Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
56d3fa01
Commit
56d3fa01
authored
9 years ago
by
jsa
Browse files
Options
Downloads
Patches
Plain Diff
use COURSE_CERT_AWARDED signal for milestones + badges
parent
9d141ae7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lms/djangoapps/certificates/models.py
+12
-15
12 additions, 15 deletions
lms/djangoapps/certificates/models.py
with
12 additions
and
15 deletions
lms/djangoapps/certificates/models.py
+
12
−
15
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment