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
f950ea10
Commit
f950ea10
authored
Nov 15, 2013
by
Julia Hansbrough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
response to CR
parent
e73489ec
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
8 deletions
+9
-8
common/djangoapps/student/models.py
+6
-2
common/djangoapps/student/tests/tests.py
+1
-1
lms/djangoapps/shoppingcart/models.py
+2
-5
No files found.
common/djangoapps/student/models.py
View file @
f950ea10
...
...
@@ -713,7 +713,7 @@ class CourseEnrollment(models.Model):
)
.
format
(
self
.
user
,
self
.
course_id
,
self
.
created
,
self
.
is_active
)
@classmethod
def
create_enrollment
(
cls
,
user
,
course_id
):
def
get_or_
create_enrollment
(
cls
,
user
,
course_id
):
"""
Create an enrollment for a user in a class. By default *this enrollment
is not active*. This is useful for when an enrollment needs to go
...
...
@@ -761,11 +761,15 @@ class CourseEnrollment(models.Model):
This saves immediately.
"""
activation_changed
=
False
# if is_active is None, then the call to update_enrollment didn't specify
# any value, so just leave is_active as it is
if
self
.
is_active
!=
is_active
and
is_active
is
not
None
:
self
.
is_active
=
is_active
activation_changed
=
True
mode_changed
=
False
# if mode is None, the call to update_enrollment didn't specify a new
# mode, so leave as-is
if
self
.
mode
!=
mode
and
mode
is
not
None
:
self
.
mode
=
mode
mode_changed
=
True
...
...
@@ -819,7 +823,7 @@ class CourseEnrollment(models.Model):
It is expected that this method is called from a method which has already
verified the user authentication and access.
"""
enrollment
=
cls
.
create_enrollment
(
user
,
course_id
)
enrollment
=
cls
.
get_or_
create_enrollment
(
user
,
course_id
)
enrollment
.
update_enrollment
(
is_active
=
True
)
return
enrollment
...
...
common/djangoapps/student/tests/tests.py
View file @
f950ea10
...
...
@@ -443,7 +443,7 @@ class EnrollInCourseTest(TestCase):
# Creating an enrollment doesn't actually enroll a student
# (calling CourseEnrollment.enroll() would have)
enrollment
=
CourseEnrollment
.
create_enrollment
(
user
,
course_id
)
enrollment
=
CourseEnrollment
.
get_or_
create_enrollment
(
user
,
course_id
)
self
.
assertFalse
(
CourseEnrollment
.
is_enrolled
(
user
,
course_id
))
self
.
assert_no_events_were_emitted
()
...
...
lms/djangoapps/shoppingcart/models.py
View file @
f950ea10
...
...
@@ -464,11 +464,8 @@ class CertificateItem(OrderItem):
"""
super
(
CertificateItem
,
cls
)
.
add_to_order
(
order
,
course_id
,
cost
,
currency
=
currency
)
try
:
course_enrollment
=
CourseEnrollment
.
objects
.
get
(
user
=
order
.
user
,
course_id
=
course_id
)
except
ObjectDoesNotExist
:
course_enrollment
=
CourseEnrollment
.
create_enrollment
(
order
.
user
,
course_id
)
course_enrollment
.
update_enrollment
(
mode
=
mode
)
course_enrollment
=
CourseEnrollment
.
get_or_create_enrollment
(
order
.
user
,
course_id
)
course_enrollment
.
update_enrollment
(
mode
=
mode
)
# do some validation on the enrollment mode
valid_modes
=
CourseMode
.
modes_for_course_dict
(
course_id
)
...
...
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