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
628dff53
Commit
628dff53
authored
Jul 02, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pylint fixing
parent
c68895ca
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
27 deletions
+41
-27
cms/djangoapps/contentstore/views/__init__.py
+2
-0
cms/djangoapps/contentstore/views/assets.py
+8
-8
cms/djangoapps/contentstore/views/component.py
+1
-1
cms/djangoapps/contentstore/views/course.py
+24
-10
cms/djangoapps/contentstore/views/preview.py
+1
-1
cms/djangoapps/contentstore/views/user.py
+5
-7
No files found.
cms/djangoapps/contentstore/views/__init__.py
View file @
628dff53
# pylint: disable=W0401, W0511
"All view functions for contentstore, broken out into submodules"
# Disable warnings about import from wildcard
# All files below declare exports with __all__
from
.assets
import
*
...
...
cms/djangoapps/contentstore/views/assets.py
View file @
628dff53
...
...
@@ -56,15 +56,15 @@ def assets_to_json_dict(assets):
thumbnail
=
asset
.
get
(
"thumbnail_location"
)
if
thumbnail
:
obj
[
"thumbnail"
]
=
thumbnail
id
I
nfo
=
asset
.
get
(
"_id"
)
if
id
I
nfo
:
id
_i
nfo
=
asset
.
get
(
"_id"
)
if
id
_i
nfo
:
obj
[
"id"
]
=
"/{tag}/{org}/{course}/{revision}/{category}/{name}"
.
format
(
org
=
id
I
nfo
.
get
(
"org"
,
""
),
course
=
id
I
nfo
.
get
(
"course"
,
""
),
revision
=
id
I
nfo
.
get
(
"revision"
,
""
),
tag
=
id
I
nfo
.
get
(
"tag"
,
""
),
category
=
id
I
nfo
.
get
(
"category"
,
""
),
name
=
id
I
nfo
.
get
(
"name"
,
""
),
org
=
id
_i
nfo
.
get
(
"org"
,
""
),
course
=
id
_i
nfo
.
get
(
"course"
,
""
),
revision
=
id
_i
nfo
.
get
(
"revision"
,
""
),
tag
=
id
_i
nfo
.
get
(
"tag"
,
""
),
category
=
id
_i
nfo
.
get
(
"category"
,
""
),
name
=
id
_i
nfo
.
get
(
"name"
,
""
),
)
ret
.
append
(
obj
)
return
ret
...
...
cms/djangoapps/contentstore/views/component.py
View file @
628dff53
...
...
@@ -234,7 +234,7 @@ def assignment_type_update(request, org, course, category, name):
'''
location
=
Location
([
'i4x'
,
org
,
course
,
category
,
name
])
if
not
has_access
(
request
.
user
,
location
):
r
aise
HttpResponseForbidden
()
r
eturn
HttpResponseForbidden
()
if
request
.
method
==
'GET'
:
return
JsonResponse
(
CourseGradingModel
.
get_section_grader_type
(
location
))
...
...
cms/djangoapps/contentstore/views/course.py
View file @
628dff53
"""
Views related to operations on course objects
"""
#pylint: disable=W0402
import
json
import
random
import
string
...
...
@@ -91,7 +92,9 @@ def course_index(request, org, course, name):
@login_required
@expect_json
def
create_new_course
(
request
):
"""
Create a new course
"""
if
not
is_user_in_creator_group
(
request
.
user
):
raise
PermissionDenied
()
...
...
@@ -401,15 +404,19 @@ def course_advanced_updates(request, org, course, name):
return
JsonResponse
(
CourseMetadata
.
update_from_json
(
location
,
request_body
,
filter_tabs
=
filter_tabs
))
except
(
TypeError
,
ValueError
)
as
e
:
return
HttpResponseBadRequest
(
"Incorrect setting format. "
+
str
(
e
),
content_type
=
"text/plain"
)
except
(
TypeError
,
ValueError
)
as
e
rr
:
return
HttpResponseBadRequest
(
"Incorrect setting format. "
+
str
(
e
rr
),
content_type
=
"text/plain"
)
class
TextbookValidationError
(
Exception
):
"An error thrown when a textbook input is invalid"
pass
def
validate_textbooks_json
(
text
):
"""
Validate the given text as representing a single PDF textbook
"""
try
:
textbooks
=
json
.
loads
(
text
)
except
ValueError
:
...
...
@@ -426,7 +433,10 @@ def validate_textbooks_json(text):
return
textbooks
def
validate_textbook_json
(
textbook
,
used_ids
=
()):
def
validate_textbook_json
(
textbook
):
"""
Validate the given text as representing a list of PDF textbooks
"""
if
isinstance
(
textbook
,
basestring
):
try
:
textbook
=
json
.
loads
(
textbook
)
...
...
@@ -443,6 +453,10 @@ def validate_textbook_json(textbook, used_ids=()):
def
assign_textbook_id
(
textbook
,
used_ids
=
()):
"""
Return an ID that can be assigned to a textbook
and doesn't match the used_ids
"""
tid
=
Location
.
clean
(
textbook
[
"tab_title"
])
if
not
tid
[
0
]
.
isdigit
():
# stick a random digit in front
...
...
@@ -471,8 +485,8 @@ def textbook_index(request, org, course, name):
elif
request
.
method
==
'POST'
:
try
:
textbooks
=
validate_textbooks_json
(
request
.
body
)
except
TextbookValidationError
as
e
:
return
JsonResponse
({
"error"
:
e
.
message
},
status
=
400
)
except
TextbookValidationError
as
e
rr
:
return
JsonResponse
({
"error"
:
e
rr
.
message
},
status
=
400
)
tids
=
set
(
t
[
"id"
]
for
t
in
textbooks
if
"id"
in
t
)
for
textbook
in
textbooks
:
...
...
@@ -518,8 +532,8 @@ def create_textbook(request, org, course, name):
try
:
textbook
=
validate_textbook_json
(
request
.
body
)
except
TextbookValidationError
as
e
:
return
JsonResponse
({
"error"
:
e
.
message
},
status
=
400
)
except
TextbookValidationError
as
e
rr
:
return
JsonResponse
({
"error"
:
e
rr
.
message
},
status
=
400
)
if
not
textbook
.
get
(
"id"
):
tids
=
set
(
t
[
"id"
]
for
t
in
course_module
.
pdf_textbooks
if
"id"
in
t
)
textbook
[
"id"
]
=
assign_textbook_id
(
textbook
,
tids
)
...
...
@@ -566,8 +580,8 @@ def textbook_by_id(request, org, course, name, tid):
elif
request
.
method
in
(
'POST'
,
'PUT'
):
try
:
new_textbook
=
validate_textbook_json
(
request
.
body
)
except
TextbookValidationError
as
e
:
return
JsonResponse
({
"error"
:
e
.
message
},
status
=
400
)
except
TextbookValidationError
as
e
rr
:
return
JsonResponse
({
"error"
:
e
rr
.
message
},
status
=
400
)
new_textbook
[
"id"
]
=
tid
if
textbook
:
i
=
course_module
.
pdf_textbooks
.
index
(
textbook
)
...
...
cms/djangoapps/contentstore/views/preview.py
View file @
628dff53
...
...
@@ -68,7 +68,7 @@ def preview_dispatch(request, preview_id, location, dispatch=None):
def
preview_component
(
request
,
location
):
# TODO (vshnayder): change name from id to location in coffee+html as well.
if
not
has_access
(
request
.
user
,
location
):
r
aise
HttpResponseForbidden
()
r
eturn
HttpResponseForbidden
()
component
=
modulestore
()
.
get_item
(
location
)
...
...
cms/djangoapps/contentstore/views/user.py
View file @
628dff53
...
...
@@ -23,13 +23,11 @@ def user_author_string(user):
If the first and last names are blank, uses the username instead.
Assumes that the email is not blank.
'''
f
=
user
.
first_name
l
=
user
.
last_name
if
f
==
''
and
l
==
''
:
f
=
user
.
username
return
'{first} {last} <{email}>'
.
format
(
first
=
f
,
last
=
l
,
email
=
user
.
email
)
if
not
user
.
first_name
and
not
user
.
last_name
:
name
=
user
.
username
else
:
name
=
"{0} {1}"
.
format
(
user
.
first_name
,
user
.
last_name
)
return
"{name} <{email}>"
.
format
(
name
=
name
,
email
=
user
.
email
)
@login_required
...
...
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