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
1717e0c4
Commit
1717e0c4
authored
Oct 06, 2016
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple student's dependency on badges with django signals.
parent
4bb88109
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
7 deletions
+40
-7
common/djangoapps/student/models.py
+1
-4
common/djangoapps/student/views.py
+1
-2
lms/djangoapps/badges/apps.py
+20
-0
lms/djangoapps/badges/handlers.py
+17
-0
lms/envs/common.py
+1
-1
No files found.
common/djangoapps/student/models.py
View file @
1717e0c4
...
...
@@ -47,7 +47,6 @@ from simple_history.models import HistoricalRecords
from
track
import
contexts
from
xmodule_django.models
import
CourseKeyField
,
NoneToEmptyManager
from
lms.djangoapps.badges.utils
import
badges_enabled
from
certificates.models
import
GeneratedCertificate
from
course_modes.models
import
CourseMode
from
enrollment.api
import
_default_course_mode
...
...
@@ -1297,9 +1296,7 @@ class CourseEnrollment(models.Model):
# User is allowed to enroll if they've reached this point.
enrollment
=
cls
.
get_or_create_enrollment
(
user
,
course_key
)
enrollment
.
update_enrollment
(
is_active
=
True
,
mode
=
mode
)
if
badges_enabled
():
from
lms.djangoapps.badges.events.course_meta
import
award_enrollment_badge
award_enrollment_badge
(
user
)
enrollment
.
send_signal
(
EnrollStatusChange
.
enroll
)
return
enrollment
...
...
common/djangoapps/student/views.py
View file @
1717e0c4
...
...
@@ -1077,8 +1077,7 @@ def change_enrollment(request, check_access=True):
try
:
enroll_mode
=
CourseMode
.
auto_enroll_mode
(
course_id
,
available_modes
)
if
enroll_mode
:
enrollment
=
CourseEnrollment
.
enroll
(
user
,
course_id
,
check_access
=
check_access
,
mode
=
enroll_mode
)
enrollment
.
send_signal
(
EnrollStatusChange
.
enroll
)
CourseEnrollment
.
enroll
(
user
,
course_id
,
check_access
=
check_access
,
mode
=
enroll_mode
)
except
Exception
:
# pylint: disable=broad-except
return
HttpResponseBadRequest
(
_
(
"Could not enroll"
))
...
...
lms/djangoapps/badges/apps.py
0 → 100644
View file @
1717e0c4
"""
Badges Application Configuration
Signal handlers are connected here.
"""
from
django.apps
import
AppConfig
class
BadgesConfig
(
AppConfig
):
"""
Application Configuration for Badges.
"""
name
=
u'badges'
def
ready
(
self
):
"""
Connect signal handlers.
"""
from
.
import
handlers
# pylint: disable=unused-variable
lms/djangoapps/badges/handlers.py
0 → 100644
View file @
1717e0c4
"""
Badges related signal handlers.
"""
from
django.dispatch
import
receiver
from
lms.djangoapps.badges.events.course_meta
import
award_enrollment_badge
from
lms.djangoapps.badges.utils
import
badges_enabled
from
student.models
import
ENROLL_STATUS_CHANGE
,
EnrollStatusChange
@receiver
(
ENROLL_STATUS_CHANGE
)
def
award_badge_on_enrollment
(
sender
,
event
=
None
,
user
=
None
,
**
kwargs
):
# pylint: disable=unused-argument
"""
Awards enrollment badge to the given user on new enrollments.
"""
if
badges_enabled
and
event
==
EnrollStatusChange
.
enroll
:
award_enrollment_badge
(
user
)
lms/envs/common.py
View file @
1717e0c4
...
...
@@ -2095,7 +2095,7 @@ INSTALLED_APPS = (
'learner_dashboard'
,
# Needed whether or not enabled, due to migrations
'badges'
,
'badges
.apps.BadgesConfig
'
,
# Enables default site and redirects
'django_sites_extensions'
,
...
...
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