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
56d3fa01
Commit
56d3fa01
authored
Jan 24, 2016
by
jsa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use COURSE_CERT_AWARDED signal for milestones + badges
parent
9d141ae7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
lms/djangoapps/certificates/models.py
+12
-15
No files found.
lms/djangoapps/certificates/models.py
View file @
56d3fa01
...
...
@@ -421,16 +421,13 @@ class CertificateInvalidation(TimeStampedModel):
return
data
@receiver
(
post_save
,
sender
=
GeneratedCertificate
)
def
handle_
post_cert_generated
(
sender
,
instance
,
**
kwargs
):
# pylint: disable=unused-argument
@receiver
(
COURSE_CERT_AWARDED
,
sender
=
GeneratedCertificate
)
def
handle_
course_cert_awarded
(
sender
,
user
,
course_key
,
**
kwargs
):
# pylint: disable=unused-argument
"""
Handles post_save signal of GeneratedCertificate, and mark user collected
course milestone entry if user has passed the course.
User is assumed to have passed the course if certificate status is either 'generating' or 'downloadable'.
Mark a milestone entry if user has passed the course.
"""
allowed_cert_states
=
[
CertificateStatuses
.
generating
,
CertificateStatuses
.
downloadable
]
if
is_prerequisite_courses_enabled
()
and
instance
.
status
in
allowed_cert_states
:
fulfill_course_milestone
(
instance
.
course_id
,
instance
.
user
)
if
is_prerequisite_courses_enabled
():
fulfill_course_milestone
(
course_key
,
user
)
def
certificate_status_for_student
(
student
,
course_id
):
...
...
@@ -1085,25 +1082,25 @@ class CertificateTemplateAsset(TimeStampedModel):
app_label
=
"certificates"
@receiver
(
post_save
,
sender
=
GeneratedCertificate
)
@receiver
(
COURSE_CERT_AWARDED
,
sender
=
GeneratedCertificate
)
#pylint: disable=unused-argument
def
create_badge
(
sender
,
instance
,
**
kwargs
):
def
create_badge
(
sender
,
user
,
course_key
,
status
,
**
kwargs
):
"""
Standard signal hook to create badges when a certificate has been generated.
"""
if
not
settings
.
FEATURES
.
get
(
'ENABLE_OPENBADGES'
,
False
):
return
if
not
modulestore
()
.
get_course
(
instance
.
course_id
)
.
issue_badges
:
if
not
modulestore
()
.
get_course
(
course_key
)
.
issue_badges
:
LOGGER
.
info
(
"Course is not configured to issue badges."
)
return
if
BadgeAssertion
.
objects
.
filter
(
user
=
instance
.
user
,
course_id
=
instance
.
course_id
):
if
BadgeAssertion
.
objects
.
filter
(
user
=
user
,
course_id
=
course_key
):
LOGGER
.
info
(
"Badge already exists for this user on this course."
)
# Badge already exists. Skip.
return
# Don't bake a badge until the certificate is available. Prevents user-facing requests from being paused for this
# by making sure it only gets run on the callback during normal workflow.
if
not
instance
.
status
==
CertificateStatuses
.
downloadable
:
if
not
status
==
CertificateStatuses
.
downloadable
:
return
from
.badge_handler
import
BadgeHandler
handler
=
BadgeHandler
(
instance
.
course_id
)
handler
.
award
(
instance
.
user
)
handler
=
BadgeHandler
(
course_key
)
handler
.
award
(
user
)
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