Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
955c6447
Commit
955c6447
authored
Jun 11, 2017
by
rabia23
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reset self-generation of certs according to course pacing
parent
3de758f6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
38 deletions
+27
-38
lms/djangoapps/certificates/models.py
+4
-12
lms/djangoapps/certificates/signals.py
+10
-12
lms/djangoapps/certificates/tests/test_signals.py
+2
-2
openedx/core/djangoapps/content/course_overviews/models.py
+0
-8
openedx/core/djangoapps/content/course_overviews/signals.py
+2
-4
openedx/core/djangoapps/models/course_details.py
+9
-0
No files found.
lms/djangoapps/certificates/models.py
View file @
955c6447
...
@@ -54,7 +54,6 @@ from django.conf import settings
...
@@ -54,7 +54,6 @@ from django.conf import settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
,
transaction
from
django.db
import
models
,
transaction
from
django.db.utils
import
IntegrityError
from
django.db.models
import
Count
from
django.db.models
import
Count
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
...
@@ -891,17 +890,10 @@ class CertificateGenerationCourseSetting(TimeStampedModel):
...
@@ -891,17 +890,10 @@ class CertificateGenerationCourseSetting(TimeStampedModel):
is_enabled (boolean): Whether to enable or disable self-generated certificates.
is_enabled (boolean): Whether to enable or disable self-generated certificates.
"""
"""
certificate_generation_course_setting
=
CertificateGenerationCourseSetting
(
course_key
=
course_key
,
CertificateGenerationCourseSetting
.
objects
.
create
(
enabled
=
is_enabled
)
course_key
=
course_key
,
try
:
enabled
=
is_enabled
with
transaction
.
atomic
():
)
certificate_generation_course_setting
.
save
()
except
IntegrityError
:
if
is_enabled
:
LOGGER
.
exception
(
"Cannot enable self-generated certificates for course
%
s."
,
unicode
(
course_key
))
else
:
LOGGER
.
exception
(
"Cannot disable self-generated certificates for course
%
s."
,
unicode
(
course_key
))
pass
class
CertificateGenerationConfiguration
(
ConfigurationModel
):
class
CertificateGenerationConfiguration
(
ConfigurationModel
):
...
...
lms/djangoapps/certificates/signals.py
View file @
955c6447
...
@@ -2,26 +2,24 @@
...
@@ -2,26 +2,24 @@
Signal handler for enabling/disabling self-generated certificates based on the course-pacing.
Signal handler for enabling/disabling self-generated certificates based on the course-pacing.
"""
"""
from
celery.task
import
task
from
celery.task
import
task
from
django.dispatch
.dispatcher
import
receiver
from
django.dispatch
import
receiver
from
certificates.models
import
CertificateGenerationCourseSetting
from
certificates.models
import
CertificateGenerationCourseSetting
from
openedx.core.djangoapps.content.course_overviews.models
import
CourseOverview
,
COURSE_OVERVIEW_UPDATED
from
openedx.core.djangoapps.models.course_details
import
COURSE_PACING_CHANGE
from
opaque_keys.edx.keys
import
CourseKey
@receiver
(
COURSE_OVERVIEW_UPDATED
)
@receiver
(
COURSE_PACING_CHANGE
,
dispatch_uid
=
"course_pacing_changed"
)
def
_listen_for_course_publish
(
sender
,
course_key
,
**
kwargs
):
# pylint: disable=unused-argument
def
_listen_for_course_publish
(
sender
,
course_key
,
course_self_paced
,
**
kwargs
):
# pylint: disable=unused-argument
""" Catches the signal that a course overview table has been updated in database and
enable/disable the self-generated certificates according to course-pacing.
"""
"""
set_self_generated_certs
.
delay
(
unicode
(
course_key
))
Catches the signal that course pacing has changed and enable/disable
the self-generated certificates according to course-pacing.
"""
enable_self_generated_certs
.
delay
(
course_key
,
course_self_paced
)
@task
()
@task
()
def
set_self_generated_certs
(
course_key
):
def
enable_self_generated_certs
(
course_key
,
course_self_paced
):
"""
"""
Enable or disable self-generated certificates for a course according to pacing.
Enable or disable self-generated certificates for a course according to pacing.
"""
"""
course_key
=
CourseKey
.
from_string
(
course_key
)
CertificateGenerationCourseSetting
.
set_enabled_for_course
(
course_key
,
course_self_paced
)
course
=
CourseOverview
.
get_from_id
(
course_key
)
CertificateGenerationCourseSetting
.
set_enabled_for_course
(
course_key
,
course
.
self_paced
)
lms/djangoapps/certificates/tests/test_signals.py
View file @
955c6447
...
@@ -29,7 +29,7 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
...
@@ -29,7 +29,7 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
"""
"""
self
.
assertFalse
(
certs_api
.
cert_generation_enabled
(
self
.
course
.
id
))
self
.
assertFalse
(
certs_api
.
cert_generation_enabled
(
self
.
course
.
id
))
_listen_for_course_publish
(
'store'
,
self
.
course
.
id
)
_listen_for_course_publish
(
'store'
,
self
.
course
.
id
,
self
.
course
.
self_paced
)
self
.
assertTrue
(
certs_api
.
cert_generation_enabled
(
self
.
course
.
id
))
self
.
assertTrue
(
certs_api
.
cert_generation_enabled
(
self
.
course
.
id
))
def
test_cert_generation_disabled_for_instructor_paced
(
self
):
def
test_cert_generation_disabled_for_instructor_paced
(
self
):
...
@@ -40,5 +40,5 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
...
@@ -40,5 +40,5 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
self
.
course
.
self_paced
=
False
self
.
course
.
self_paced
=
False
self
.
store
.
update_item
(
self
.
course
,
self
.
user
.
id
)
self
.
store
.
update_item
(
self
.
course
,
self
.
user
.
id
)
_listen_for_course_publish
(
'store'
,
self
.
course
.
id
)
_listen_for_course_publish
(
'store'
,
self
.
course
.
id
,
self
.
course
.
self_paced
)
self
.
assertFalse
(
certs_api
.
cert_generation_enabled
(
self
.
course
.
id
))
self
.
assertFalse
(
certs_api
.
cert_generation_enabled
(
self
.
course
.
id
))
openedx/core/djangoapps/content/course_overviews/models.py
View file @
955c6447
...
@@ -10,7 +10,6 @@ from django.db import models, transaction
...
@@ -10,7 +10,6 @@ from django.db import models, transaction
from
django.db.models.fields
import
BooleanField
,
DateTimeField
,
DecimalField
,
TextField
,
FloatField
,
IntegerField
from
django.db.models.fields
import
BooleanField
,
DateTimeField
,
DecimalField
,
TextField
,
FloatField
,
IntegerField
from
django.db.utils
import
IntegrityError
from
django.db.utils
import
IntegrityError
from
django.template
import
defaultfilters
from
django.template
import
defaultfilters
from
django.dispatch
import
Signal
from
ccx_keys.locator
import
CCXLocator
from
ccx_keys.locator
import
CCXLocator
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
...
@@ -26,7 +25,6 @@ from xmodule.error_module import ErrorDescriptor
...
@@ -26,7 +25,6 @@ from xmodule.error_module import ErrorDescriptor
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
openedx.core.djangoapps.xmodule_django.models
import
CourseKeyField
,
UsageKeyField
from
openedx.core.djangoapps.xmodule_django.models
import
CourseKeyField
,
UsageKeyField
COURSE_OVERVIEW_UPDATED
=
Signal
(
providing_args
=
[
"course_key"
])
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -647,12 +645,6 @@ class CourseOverview(TimeStampedModel):
...
@@ -647,12 +645,6 @@ class CourseOverview(TimeStampedModel):
"""Represent ourselves with the course key."""
"""Represent ourselves with the course key."""
return
unicode
(
self
.
id
)
return
unicode
(
self
.
id
)
def
send_signal
(
self
):
"""
Sends out the signal that course_overview table has been updated.
"""
COURSE_OVERVIEW_UPDATED
.
send
(
sender
=
None
,
course_key
=
self
.
id
)
class
CourseOverviewTab
(
models
.
Model
):
class
CourseOverviewTab
(
models
.
Model
):
"""
"""
...
...
openedx/core/djangoapps/content/course_overviews/signals.py
View file @
955c6447
...
@@ -11,11 +11,9 @@ from xmodule.modulestore.django import SignalHandler
...
@@ -11,11 +11,9 @@ from xmodule.modulestore.django import SignalHandler
def
_listen_for_course_publish
(
sender
,
course_key
,
**
kwargs
):
# pylint: disable=unused-argument
def
_listen_for_course_publish
(
sender
,
course_key
,
**
kwargs
):
# pylint: disable=unused-argument
"""
"""
Catches the signal that a course has been published in Studio and
Catches the signal that a course has been published in Studio and
updates the corresponding CourseOverview cache entry. Also sends out
updates the corresponding CourseOverview cache entry.
the signal that course_overview table has been updated.
"""
"""
course_overview
=
CourseOverview
.
load_from_module_store
(
course_key
)
CourseOverview
.
load_from_module_store
(
course_key
)
course_overview
.
send_signal
()
@receiver
(
SignalHandler
.
course_deleted
)
@receiver
(
SignalHandler
.
course_deleted
)
...
...
openedx/core/djangoapps/models/course_details.py
View file @
955c6447
...
@@ -5,6 +5,7 @@ import re
...
@@ -5,6 +5,7 @@ import re
import
logging
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
from
django.dispatch
import
Signal
from
xmodule.fields
import
Date
from
xmodule.fields
import
Date
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
...
@@ -12,6 +13,8 @@ from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
...
@@ -12,6 +13,8 @@ from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from
openedx.core.lib.courses
import
course_image_url
from
openedx.core.lib.courses
import
course_image_url
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
COURSE_PACING_CHANGE
=
Signal
(
providing_args
=
[
"course_key"
,
"course_self_paced"
])
# This list represents the attribute keys for a course's 'about' info.
# This list represents the attribute keys for a course's 'about' info.
# Note: The 'video' attribute is intentionally excluded as it must be
# Note: The 'video' attribute is intentionally excluded as it must be
...
@@ -188,6 +191,7 @@ class CourseDetails(object):
...
@@ -188,6 +191,7 @@ class CourseDetails(object):
descriptor
=
module_store
.
get_course
(
course_key
)
descriptor
=
module_store
.
get_course
(
course_key
)
dirty
=
False
dirty
=
False
is_pacing_changed
=
False
# In the descriptor's setter, the date is converted to JSON
# In the descriptor's setter, the date is converted to JSON
# using Date's to_json method. Calling to_json on something that
# using Date's to_json method. Calling to_json on something that
...
@@ -271,6 +275,7 @@ class CourseDetails(object):
...
@@ -271,6 +275,7 @@ class CourseDetails(object):
and
jsondict
[
'self_paced'
]
!=
descriptor
.
self_paced
):
and
jsondict
[
'self_paced'
]
!=
descriptor
.
self_paced
):
descriptor
.
self_paced
=
jsondict
[
'self_paced'
]
descriptor
.
self_paced
=
jsondict
[
'self_paced'
]
dirty
=
True
dirty
=
True
is_pacing_changed
=
True
if
dirty
:
if
dirty
:
module_store
.
update_item
(
descriptor
,
user
.
id
)
module_store
.
update_item
(
descriptor
,
user
.
id
)
...
@@ -285,6 +290,10 @@ class CourseDetails(object):
...
@@ -285,6 +290,10 @@ class CourseDetails(object):
cls
.
update_about_video
(
descriptor
,
jsondict
[
'intro_video'
],
user
.
id
)
cls
.
update_about_video
(
descriptor
,
jsondict
[
'intro_video'
],
user
.
id
)
if
is_pacing_changed
:
# sends out the signal that course pacing has changed
COURSE_PACING_CHANGE
.
send
(
sender
=
None
,
course_key
=
course_key
,
course_self_paced
=
descriptor
.
self_paced
)
# Could just return jsondict w/o doing any db reads, but I put
# Could just return jsondict w/o doing any db reads, but I put
# the reads in as a means to confirm it persisted correctly
# the reads in as a means to confirm it persisted correctly
return
CourseDetails
.
fetch
(
course_key
)
return
CourseDetails
.
fetch
(
course_key
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment