Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
32a902ca
Commit
32a902ca
authored
11 years ago
by
David Baumgold
Browse files
Options
Downloads
Patches
Plain Diff
Remove create_json_response in favor of JsonResponse class
parent
628dff53
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cms/djangoapps/contentstore/views/requests.py
+0
-10
0 additions, 10 deletions
cms/djangoapps/contentstore/views/requests.py
cms/djangoapps/contentstore/views/user.py
+24
-9
24 additions, 9 deletions
cms/djangoapps/contentstore/views/user.py
with
24 additions
and
19 deletions
cms/djangoapps/contentstore/views/requests.py
+
0
−
10
View file @
32a902ca
import
json
from
django.http
import
HttpResponse
from
mitxmako.shortcuts
import
render_to_string
,
render_to_response
...
...
@@ -24,14 +22,6 @@ def event(request):
return
HttpResponse
(
status
=
204
)
def
create_json_response
(
errmsg
=
None
):
if
errmsg
is
not
None
:
resp
=
HttpResponse
(
json
.
dumps
({
'
Status
'
:
'
Failed
'
,
'
ErrMsg
'
:
errmsg
}))
else
:
resp
=
HttpResponse
(
json
.
dumps
({
'
Status
'
:
'
OK
'
}))
return
resp
def
render_from_lms
(
template_name
,
dictionary
,
context
=
None
,
namespace
=
'
main
'
):
"""
Render a template using the LMS MAKO_TEMPLATES
...
...
This diff is collapsed.
Click to expand it.
cms/djangoapps/contentstore/views/user.py
+
24
−
9
View file @
32a902ca
...
...
@@ -8,12 +8,11 @@ from mitxmako.shortcuts import render_to_response
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
contentstore.utils
import
get_url_reverse
,
get_lms_link_for_item
from
util.json_request
import
expect_json
from
util.json_request
import
expect_json
,
JsonResponse
from
auth.authz
import
STAFF_ROLE_NAME
,
INSTRUCTOR_ROLE_NAME
,
get_users_in_course_group_by_role
from
auth.authz
import
get_user_by_email
,
add_user_to_course_group
,
remove_user_from_course_group
from
.access
import
has_access
from
.requests
import
create_json_response
def
user_author_string
(
user
):
...
...
@@ -90,8 +89,12 @@ def add_user(request, location):
'''
email
=
request
.
POST
[
"
email
"
]
if
email
==
''
:
return
create_json_response
(
'
Please specify an email address.
'
)
if
not
email
:
msg
=
{
'
Status
'
:
'
Failed
'
,
'
ErrMsg
'
:
'
Please specify an email address.
'
,
}
return
JsonResponse
(
msg
,
400
)
# check that logged in user has admin permissions to this course
if
not
has_access
(
request
.
user
,
location
,
role
=
INSTRUCTOR_ROLE_NAME
):
...
...
@@ -101,16 +104,24 @@ def add_user(request, location):
# user doesn't exist?!? Return error.
if
user
is
None
:
return
create_json_response
(
'
Could not find user by email address
\'
{0}
\'
.
'
.
format
(
email
))
msg
=
{
'
Status
'
:
'
Failed
'
,
'
ErrMsg
'
:
"
Could not find user by email address
'
{0}
'
.
"
.
format
(
email
),
}
return
JsonResponse
(
msg
,
404
)
# user exists, but hasn't activated account?!?
if
not
user
.
is_active
:
return
create_json_response
(
'
User {0} has registered but has not yet activated his/her account.
'
.
format
(
email
))
msg
=
{
'
Status
'
:
'
Failed
'
,
'
ErrMsg
'
:
'
User {0} has registered but has not yet activated his/her account.
'
.
format
(
email
),
}
return
JsonResponse
(
msg
,
400
)
# ok, we're cool to add to the course group
add_user_to_course_group
(
request
.
user
,
user
,
location
,
STAFF_ROLE_NAME
)
return
create_j
son
_r
esponse
()
return
J
son
R
esponse
(
{
"
Status
"
:
"
OK
"
}
)
@expect_json
...
...
@@ -130,7 +141,11 @@ def remove_user(request, location):
user
=
get_user_by_email
(
email
)
if
user
is
None
:
return
create_json_response
(
'
Could not find user by email address
\'
{0}
\'
.
'
.
format
(
email
))
msg
=
{
'
Status
'
:
'
Failed
'
,
'
ErrMsg
'
:
"
Could not find user by email address
'
{0}
'
.
"
.
format
(
email
),
}
return
JsonResponse
(
msg
,
404
)
# make sure we're not removing ourselves
if
user
.
id
==
request
.
user
.
id
:
...
...
@@ -138,4 +153,4 @@ def remove_user(request, location):
remove_user_from_course_group
(
request
.
user
,
user
,
location
,
STAFF_ROLE_NAME
)
return
create_j
son
_r
esponse
()
return
J
son
R
esponse
(
{
"
Status
"
:
"
OK
"
}
)
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