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
32a902ca
Commit
32a902ca
authored
Jul 02, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove create_json_response in favor of JsonResponse class
parent
628dff53
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
19 deletions
+24
-19
cms/djangoapps/contentstore/views/requests.py
+0
-10
cms/djangoapps/contentstore/views/user.py
+24
-9
No files found.
cms/djangoapps/contentstore/views/requests.py
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
...
...
cms/djangoapps/contentstore/views/user.py
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_json_response
(
)
return
JsonResponse
({
"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_json_response
(
)
return
JsonResponse
({
"Status"
:
"OK"
}
)
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