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
103db8aa
Commit
103db8aa
authored
Jan 24, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add conflict detection--users should be in at most one cohort per course
parent
5fa8cf5a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
4 deletions
+37
-4
common/djangoapps/course_groups/cohorts.py
+23
-3
common/djangoapps/course_groups/views.py
+8
-0
common/static/js/course_groups/cohorts.js
+6
-1
No files found.
common/djangoapps/course_groups/cohorts.py
View file @
103db8aa
...
@@ -117,6 +117,12 @@ def add_cohort(course_id, name):
...
@@ -117,6 +117,12 @@ def add_cohort(course_id, name):
group_type
=
CourseUserGroup
.
COHORT
,
group_type
=
CourseUserGroup
.
COHORT
,
name
=
name
)
name
=
name
)
class
CohortConflict
(
Exception
):
"""
Raised when user to be added is already in another cohort in same course.
"""
pass
def
add_user_to_cohort
(
cohort
,
username_or_email
):
def
add_user_to_cohort
(
cohort
,
username_or_email
):
"""
"""
Look up the given user, and if successful, add them to the specified cohort.
Look up the given user, and if successful, add them to the specified cohort.
...
@@ -131,15 +137,29 @@ def add_user_to_cohort(cohort, username_or_email):
...
@@ -131,15 +137,29 @@ def add_user_to_cohort(cohort, username_or_email):
Raises:
Raises:
User.DoesNotExist if can't find user.
User.DoesNotExist if can't find user.
ValueError if user already present.
ValueError if user already present in this cohort.
CohortConflict if user already in another cohort.
"""
"""
if
'@'
in
username_or_email
:
if
'@'
in
username_or_email
:
user
=
User
.
objects
.
get
(
email
=
username_or_email
)
user
=
User
.
objects
.
get
(
email
=
username_or_email
)
else
:
else
:
user
=
User
.
objects
.
get
(
username
=
username_or_email
)
user
=
User
.
objects
.
get
(
username
=
username_or_email
)
if
cohort
.
users
.
filter
(
id
=
user
.
id
)
.
exists
():
# If user in any cohorts in this course already, complain
raise
ValueError
(
"User {0} already present"
.
format
(
user
.
username
))
course_cohorts
=
CourseUserGroup
.
objects
.
filter
(
course_id
=
cohort
.
course_id
,
users__id
=
user
.
id
,
group_type
=
CourseUserGroup
.
COHORT
)
if
course_cohorts
.
exists
():
if
course_cohorts
[
0
]
==
cohort
:
raise
ValueError
(
"User {0} already present in cohort {1}"
.
format
(
user
.
username
,
cohort
.
name
))
else
:
raise
CohortConflict
(
"User {0} is in another cohort {1} in course"
.
format
(
user
.
username
,
course_cohorts
[
0
]
.
name
))
cohort
.
users
.
add
(
user
)
cohort
.
users
.
add
(
user
)
return
user
return
user
...
...
common/djangoapps/course_groups/views.py
View file @
103db8aa
...
@@ -133,6 +133,8 @@ def add_users_to_cohort(request, course_id, cohort_id):
...
@@ -133,6 +133,8 @@ def add_users_to_cohort(request, course_id, cohort_id):
'added': [{'username': username,
'added': [{'username': username,
'name': name,
'name': name,
'email': email}, ...],
'email': email}, ...],
'conflict': [{'username_or_email': ...,
'msg': ...}], # in another cohort
'present': [str1, str2, ...], # already there
'present': [str1, str2, ...], # already there
'unknown': [str1, str2, ...]}
'unknown': [str1, str2, ...]}
"""
"""
...
@@ -146,6 +148,7 @@ def add_users_to_cohort(request, course_id, cohort_id):
...
@@ -146,6 +148,7 @@ def add_users_to_cohort(request, course_id, cohort_id):
users
=
request
.
POST
.
get
(
'users'
,
''
)
users
=
request
.
POST
.
get
(
'users'
,
''
)
added
=
[]
added
=
[]
present
=
[]
present
=
[]
conflict
=
[]
unknown
=
[]
unknown
=
[]
for
username_or_email
in
split_by_comma_and_whitespace
(
users
):
for
username_or_email
in
split_by_comma_and_whitespace
(
users
):
try
:
try
:
...
@@ -158,10 +161,15 @@ def add_users_to_cohort(request, course_id, cohort_id):
...
@@ -158,10 +161,15 @@ def add_users_to_cohort(request, course_id, cohort_id):
present
.
append
(
username_or_email
)
present
.
append
(
username_or_email
)
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
unknown
.
append
(
username_or_email
)
unknown
.
append
(
username_or_email
)
except
cohorts
.
CohortConflict
as
err
:
conflict
.
append
({
'username_or_email'
:
username_or_email
,
'msg'
:
str
(
err
)})
return
JsonHttpReponse
({
'success'
:
True
,
return
JsonHttpReponse
({
'success'
:
True
,
'added'
:
added
,
'added'
:
added
,
'present'
:
present
,
'present'
:
present
,
'conflict'
:
conflict
,
'unknown'
:
unknown
})
'unknown'
:
unknown
})
@ensure_csrf_cookie
@ensure_csrf_cookie
...
...
common/static/js/course_groups/cohorts.js
View file @
103db8aa
...
@@ -166,8 +166,10 @@ var CohortManager = (function ($) {
...
@@ -166,8 +166,10 @@ var CohortManager = (function ($) {
function
adder
(
note
,
color
)
{
function
adder
(
note
,
color
)
{
return
function
(
item
)
{
return
function
(
item
)
{
var
li
=
$
(
'<li></li>'
)
var
li
=
$
(
'<li></li>'
)
if
(
typeof
item
===
"object"
)
{
if
(
typeof
item
===
"object"
&&
item
.
username
)
{
li
.
text
(
note
+
' '
+
item
.
name
+
', '
+
item
.
username
+
', '
+
item
.
email
);
li
.
text
(
note
+
' '
+
item
.
name
+
', '
+
item
.
username
+
', '
+
item
.
email
);
}
else
if
(
typeof
item
===
"object"
&&
item
.
msg
)
{
li
.
text
(
note
+
' '
+
item
.
username_or_email
+
', '
+
item
.
msg
);
}
else
{
}
else
{
// string
// string
li
.
text
(
note
+
' '
+
item
);
li
.
text
(
note
+
' '
+
item
);
...
@@ -176,10 +178,13 @@ var CohortManager = (function ($) {
...
@@ -176,10 +178,13 @@ var CohortManager = (function ($) {
op_results
.
append
(
li
);
op_results
.
append
(
li
);
}
}
}
}
op_results
.
empty
();
if
(
response
&&
response
.
success
)
{
if
(
response
&&
response
.
success
)
{
response
.
added
.
forEach
(
adder
(
"Added"
,
"green"
));
response
.
added
.
forEach
(
adder
(
"Added"
,
"green"
));
response
.
present
.
forEach
(
adder
(
"Already present:"
,
"black"
));
response
.
present
.
forEach
(
adder
(
"Already present:"
,
"black"
));
response
.
conflict
.
forEach
(
adder
(
"In another cohort:"
,
"purple"
));
response
.
unknown
.
forEach
(
adder
(
"Unknown user:"
,
"red"
));
response
.
unknown
.
forEach
(
adder
(
"Unknown user:"
,
"red"
));
users_area
.
val
(
''
)
}
else
{
}
else
{
log_error
(
response
.
msg
||
"There was an error adding users"
);
log_error
(
response
.
msg
||
"There was an error adding users"
);
}
}
...
...
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