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
248793c1
Commit
248793c1
authored
Jul 31, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some pylint issues
parent
094bf7e5
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
123 additions
and
90 deletions
+123
-90
cms/djangoapps/contentstore/management/commands/clone.py
+10
-8
cms/djangoapps/contentstore/management/commands/dump_course_structure.py
+8
-1
cms/djangoapps/contentstore/management/commands/export.py
+8
-7
cms/djangoapps/contentstore/management/commands/export_all_courses.py
+12
-15
cms/djangoapps/contentstore/management/commands/import.py
+9
-8
cms/djangoapps/contentstore/management/commands/xlint.py
+9
-10
cms/djangoapps/contentstore/tests/test_assets.py
+3
-3
cms/djangoapps/contentstore/tests/test_checklists.py
+1
-0
cms/djangoapps/contentstore/tests/test_contentstore.py
+1
-2
cms/djangoapps/contentstore/tests/test_course_settings.py
+2
-4
cms/djangoapps/contentstore/tests/test_i18n.py
+5
-3
cms/djangoapps/contentstore/tests/test_item.py
+20
-13
cms/djangoapps/contentstore/tests/tests.py
+16
-10
cms/djangoapps/contentstore/views/assets.py
+1
-1
cms/djangoapps/contentstore/views/component.py
+5
-0
cms/djangoapps/contentstore/views/preview.py
+2
-0
cms/djangoapps/contentstore/views/public.py
+4
-4
cms/djangoapps/contentstore/views/tabs.py
+6
-0
pylintrc
+1
-1
No files found.
cms/djangoapps/contentstore/management/commands/clone.py
View file @
248793c1
###
"""
###
Script for cloning a course
Script for cloning a course
###
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.modulestore.store_utilities
import
clone_course
from
xmodule.modulestore.store_utilities
import
clone_course
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
...
@@ -15,23 +15,25 @@ from auth.authz import _copy_course_group
...
@@ -15,23 +15,25 @@ from auth.authz import _copy_course_group
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""Clone a MongoDB-backed course to another location"""
help
=
'Clone a MongoDB backed course to another location'
help
=
'Clone a MongoDB backed course to another location'
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
!=
2
:
if
len
(
args
)
!=
2
:
raise
CommandError
(
"clone requires two arguments: <source-location> <dest-location>"
)
raise
CommandError
(
"clone requires two arguments: <source-location> <dest-location>"
)
source_location_str
=
args
[
0
]
source_location_str
=
args
[
0
]
dest_location_str
=
args
[
1
]
dest_location_str
=
args
[
1
]
ms
=
modulestore
(
'direct'
)
ms
tore
=
modulestore
(
'direct'
)
cs
=
contentstore
()
cs
tore
=
contentstore
()
print
"Cloning course {0} to {1}"
.
format
(
source_location_str
,
dest_location_str
)
print
(
"Cloning course {0} to {1}"
.
format
(
source_location_str
,
dest_location_str
)
)
source_location
=
CourseDescriptor
.
id_to_location
(
source_location_str
)
source_location
=
CourseDescriptor
.
id_to_location
(
source_location_str
)
dest_location
=
CourseDescriptor
.
id_to_location
(
dest_location_str
)
dest_location
=
CourseDescriptor
.
id_to_location
(
dest_location_str
)
if
clone_course
(
ms
,
cs
,
source_location
,
dest_location
):
if
clone_course
(
ms
tore
,
cstore
,
source_location
,
dest_location
):
print
"copying User permissions..."
print
(
"copying User permissions..."
)
_copy_course_group
(
source_location
,
dest_location
)
_copy_course_group
(
source_location
,
dest_location
)
cms/djangoapps/contentstore/management/commands/dump_course_structure.py
View file @
248793c1
"""
Script for dumping course dumping the course structure
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
...
@@ -9,10 +12,14 @@ filter_list = ['xml_attributes', 'checklists']
...
@@ -9,10 +12,14 @@ filter_list = ['xml_attributes', 'checklists']
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
The Django command for dumping course structure
"""
help
=
'''Write out to stdout a structural and metadata information about a course in a flat dictionary serialized
help
=
'''Write out to stdout a structural and metadata information about a course in a flat dictionary serialized
in a JSON format. This can be used for analytics.'''
in a JSON format. This can be used for analytics.'''
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
<
2
or
len
(
args
)
>
3
:
if
len
(
args
)
<
2
or
len
(
args
)
>
3
:
raise
CommandError
(
"dump_course_structure requires two or more arguments: <location> <outfile> |<db>|"
)
raise
CommandError
(
"dump_course_structure requires two or more arguments: <location> <outfile> |<db>|"
)
...
@@ -32,7 +39,7 @@ class Command(BaseCommand):
...
@@ -32,7 +39,7 @@ class Command(BaseCommand):
try
:
try
:
course
=
store
.
get_item
(
loc
,
depth
=
4
)
course
=
store
.
get_item
(
loc
,
depth
=
4
)
except
:
except
:
print
'Could not find course at {0}'
.
format
(
course_id
)
print
(
'Could not find course at {0}'
.
format
(
course_id
)
)
return
return
info
=
{}
info
=
{}
...
...
cms/djangoapps/contentstore/management/commands/export.py
View file @
248793c1
###
"""
###
Script for exporting courseware from Mongo to a tar.gz file
Script for exporting courseware from Mongo to a tar.gz file
###
"""
import
os
import
os
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
...
@@ -10,20 +10,21 @@ from xmodule.contentstore.django import contentstore
...
@@ -10,20 +10,21 @@ from xmodule.contentstore.django import contentstore
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.course_module
import
CourseDescriptor
unnamed_modules
=
0
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
Export the specified data directory into the default ModuleStore
"""
help
=
'Export the specified data directory into the default ModuleStore'
help
=
'Export the specified data directory into the default ModuleStore'
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
!=
2
:
if
len
(
args
)
!=
2
:
raise
CommandError
(
"export requires two arguments: <course location> <output path>"
)
raise
CommandError
(
"export requires two arguments: <course location> <output path>"
)
course_id
=
args
[
0
]
course_id
=
args
[
0
]
output_path
=
args
[
1
]
output_path
=
args
[
1
]
print
"Exporting course id = {0} to {1}"
.
format
(
course_id
,
output_path
)
print
(
"Exporting course id = {0} to {1}"
.
format
(
course_id
,
output_path
)
)
location
=
CourseDescriptor
.
id_to_location
(
course_id
)
location
=
CourseDescriptor
.
id_to_location
(
course_id
)
...
...
cms/djangoapps/contentstore/management/commands/export_all_courses.py
View file @
248793c1
###
"""
### Script for exporting all courseware from Mongo to a directory
Script for exporting all courseware from Mongo to a directory
###
"""
import
os
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.modulestore.xml_exporter
import
export_to_xml
from
xmodule.modulestore.xml_exporter
import
export_to_xml
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
...
@@ -10,13 +8,12 @@ from xmodule.contentstore.django import contentstore
...
@@ -10,13 +8,12 @@ from xmodule.contentstore.django import contentstore
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.course_module
import
CourseDescriptor
unnamed_modules
=
0
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""Export all courses from mongo to the specified data directory"""
help
=
'Export all courses from mongo to the specified data directory'
help
=
'Export all courses from mongo to the specified data directory'
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
!=
1
:
if
len
(
args
)
!=
1
:
raise
CommandError
(
"export requires one argument: <output path>"
)
raise
CommandError
(
"export requires one argument: <output path>"
)
...
@@ -27,14 +24,14 @@ class Command(BaseCommand):
...
@@ -27,14 +24,14 @@ class Command(BaseCommand):
root_dir
=
output_path
root_dir
=
output_path
courses
=
ms
.
get_courses
()
courses
=
ms
.
get_courses
()
print
"
%
d courses to export:"
%
len
(
courses
)
print
(
"
%
d courses to export:"
%
len
(
courses
)
)
cids
=
[
x
.
id
for
x
in
courses
]
cids
=
[
x
.
id
for
x
in
courses
]
print
cids
print
(
cids
)
for
course_id
in
cids
:
for
course_id
in
cids
:
print
"-"
*
77
print
(
"-"
*
77
)
print
"Exporting course id = {0} to {1}"
.
format
(
course_id
,
output_path
)
print
(
"Exporting course id = {0} to {1}"
.
format
(
course_id
,
output_path
)
)
if
1
:
if
1
:
try
:
try
:
...
@@ -42,6 +39,6 @@ class Command(BaseCommand):
...
@@ -42,6 +39,6 @@ class Command(BaseCommand):
course_dir
=
course_id
.
replace
(
'/'
,
'...'
)
course_dir
=
course_id
.
replace
(
'/'
,
'...'
)
export_to_xml
(
ms
,
cs
,
location
,
root_dir
,
course_dir
,
modulestore
())
export_to_xml
(
ms
,
cs
,
location
,
root_dir
,
course_dir
,
modulestore
())
except
Exception
as
err
:
except
Exception
as
err
:
print
"="
*
30
+
"> Oops, failed to export
%
s"
%
course_id
print
(
"="
*
30
+
"> Oops, failed to export
%
s"
%
course_id
)
print
"Error:"
print
(
"Error:"
)
print
err
print
(
err
)
cms/djangoapps/contentstore/management/commands/import.py
View file @
248793c1
###
"""
###
Script for importing courseware from XML format
Script for importing courseware from XML format
###
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
...
@@ -8,13 +8,14 @@ from xmodule.modulestore.django import modulestore
...
@@ -8,13 +8,14 @@ from xmodule.modulestore.django import modulestore
from
xmodule.contentstore.django
import
contentstore
from
xmodule.contentstore.django
import
contentstore
unnamed_modules
=
0
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
Import the specified data directory into the default ModuleStore
"""
help
=
'Import the specified data directory into the default ModuleStore'
help
=
'Import the specified data directory into the default ModuleStore'
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
==
0
:
if
len
(
args
)
==
0
:
raise
CommandError
(
"import requires at least one argument: <data directory> [<course dir>...]"
)
raise
CommandError
(
"import requires at least one argument: <data directory> [<course dir>...]"
)
...
@@ -23,8 +24,8 @@ class Command(BaseCommand):
...
@@ -23,8 +24,8 @@ class Command(BaseCommand):
course_dirs
=
args
[
1
:]
course_dirs
=
args
[
1
:]
else
:
else
:
course_dirs
=
None
course_dirs
=
None
print
"Importing. Data_dir={data}, course_dirs={courses}"
.
format
(
print
(
"Importing. Data_dir={data}, course_dirs={courses}"
.
format
(
data
=
data_dir
,
data
=
data_dir
,
courses
=
course_dirs
)
courses
=
course_dirs
)
)
import_from_xml
(
modulestore
(
'direct'
),
data_dir
,
course_dirs
,
load_error_modules
=
False
,
import_from_xml
(
modulestore
(
'direct'
),
data_dir
,
course_dirs
,
load_error_modules
=
False
,
static_content_store
=
contentstore
(),
verbose
=
True
)
static_content_store
=
contentstore
(),
verbose
=
True
)
cms/djangoapps/contentstore/management/commands/xlint.py
View file @
248793c1
"""
Verify the structure of courseware as to it's suitability for import
To run test: rake cms:xlint DATA_DIR=../data [COURSE_DIR=content-edx-101 (optional parameter)]
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.modulestore.xml_importer
import
perform_xlint
from
xmodule.modulestore.xml_importer
import
perform_xlint
unnamed_modules
=
0
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
\
"""Verify the structure of courseware as to it's suitability for import"""
'''
help
=
"Verify the structure of courseware as to it's suitability for import"
Verify the structure of courseware as to it's suitability for import
To run test: rake cms:xlint DATA_DIR=../data [COURSE_DIR=content-edx-101 (optional parameter)]
'''
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
==
0
:
if
len
(
args
)
==
0
:
raise
CommandError
(
"import requires at least one argument: <data directory> [<course dir>...]"
)
raise
CommandError
(
"import requires at least one argument: <data directory> [<course dir>...]"
)
...
@@ -21,7 +20,7 @@ class Command(BaseCommand):
...
@@ -21,7 +20,7 @@ class Command(BaseCommand):
course_dirs
=
args
[
1
:]
course_dirs
=
args
[
1
:]
else
:
else
:
course_dirs
=
None
course_dirs
=
None
print
"Importing. Data_dir={data}, course_dirs={courses}"
.
format
(
print
(
"Importing. Data_dir={data}, course_dirs={courses}"
.
format
(
data
=
data_dir
,
data
=
data_dir
,
courses
=
course_dirs
)
courses
=
course_dirs
)
)
perform_xlint
(
data_dir
,
course_dirs
,
load_error_modules
=
False
)
perform_xlint
(
data_dir
,
course_dirs
,
load_error_modules
=
False
)
cms/djangoapps/contentstore/tests/test_assets.py
View file @
248793c1
...
@@ -50,9 +50,9 @@ class UploadTestCase(CourseTestCase):
...
@@ -50,9 +50,9 @@ class UploadTestCase(CourseTestCase):
@skip
(
"CorruptGridFile error on continuous integration server"
)
@skip
(
"CorruptGridFile error on continuous integration server"
)
def
test_happy_path
(
self
):
def
test_happy_path
(
self
):
f
ile
=
BytesIO
(
"sample content"
)
f
=
BytesIO
(
"sample content"
)
f
ile
.
name
=
"sample.txt"
f
.
name
=
"sample.txt"
resp
=
self
.
client
.
post
(
self
.
url
,
{
"name"
:
"my-name"
,
"file"
:
f
ile
})
resp
=
self
.
client
.
post
(
self
.
url
,
{
"name"
:
"my-name"
,
"file"
:
f
})
self
.
assert2XX
(
resp
.
status_code
)
self
.
assert2XX
(
resp
.
status_code
)
def
test_no_file
(
self
):
def
test_no_file
(
self
):
...
...
cms/djangoapps/contentstore/tests/test_checklists.py
View file @
248793c1
...
@@ -27,6 +27,7 @@ class ChecklistTestCase(CourseTestCase):
...
@@ -27,6 +27,7 @@ class ChecklistTestCase(CourseTestCase):
"""
"""
self
.
assertEqual
(
persisted
[
'short_description'
],
request
[
'short_description'
])
self
.
assertEqual
(
persisted
[
'short_description'
],
request
[
'short_description'
])
compare_urls
=
(
persisted
.
get
(
'action_urls_expanded'
)
==
request
.
get
(
'action_urls_expanded'
))
compare_urls
=
(
persisted
.
get
(
'action_urls_expanded'
)
==
request
.
get
(
'action_urls_expanded'
))
pers
,
req
=
None
,
None
for
pers
,
req
in
zip
(
persisted
[
'items'
],
request
[
'items'
]):
for
pers
,
req
in
zip
(
persisted
[
'items'
],
request
[
'items'
]):
self
.
assertEqual
(
pers
[
'short_description'
],
req
[
'short_description'
])
self
.
assertEqual
(
pers
[
'short_description'
],
req
[
'short_description'
])
self
.
assertEqual
(
pers
[
'long_description'
],
req
[
'long_description'
])
self
.
assertEqual
(
pers
[
'long_description'
],
req
[
'long_description'
])
...
...
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
248793c1
...
@@ -95,8 +95,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
...
@@ -95,8 +95,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self
.
client
.
login
(
username
=
uname
,
password
=
password
)
self
.
client
.
login
(
username
=
uname
,
password
=
password
)
def
tearDown
(
self
):
def
tearDown
(
self
):
mongo
=
MongoClient
()
MongoClient
()
.
drop_database
(
TEST_DATA_CONTENTSTORE
[
'OPTIONS'
][
'db'
])
mongo
.
drop_database
(
TEST_DATA_CONTENTSTORE
[
'OPTIONS'
][
'db'
])
_CONTENTSTORE
.
clear
()
_CONTENTSTORE
.
clear
()
def
check_components_on_page
(
self
,
component_types
,
expected_types
):
def
check_components_on_page
(
self
,
component_types
,
expected_types
):
...
...
cms/djangoapps/contentstore/tests/test_course_settings.py
View file @
248793c1
...
@@ -18,8 +18,6 @@ from xmodule.modulestore.tests.factories import CourseFactory
...
@@ -18,8 +18,6 @@ from xmodule.modulestore.tests.factories import CourseFactory
from
models.settings.course_metadata
import
CourseMetadata
from
models.settings.course_metadata
import
CourseMetadata
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.django
import
modulestore
from
xmodule.fields
import
Date
from
xmodule.fields
import
Date
from
.utils
import
CourseTestCase
from
.utils
import
CourseTestCase
...
@@ -167,8 +165,8 @@ class CourseDetailsViewTest(CourseTestCase):
...
@@ -167,8 +165,8 @@ class CourseDetailsViewTest(CourseTestCase):
self
.
compare_details_with_encoding
(
json
.
loads
(
resp
.
content
),
details
.
__dict__
,
field
+
str
(
val
))
self
.
compare_details_with_encoding
(
json
.
loads
(
resp
.
content
),
details
.
__dict__
,
field
+
str
(
val
))
@staticmethod
@staticmethod
def
convert_datetime_to_iso
(
d
t
):
def
convert_datetime_to_iso
(
d
atetime_obj
):
return
Date
()
.
to_json
(
d
t
)
return
Date
()
.
to_json
(
d
atetime_obj
)
def
test_update_and_fetch
(
self
):
def
test_update_and_fetch
(
self
):
loc
=
self
.
course
.
location
loc
=
self
.
course
.
location
...
...
cms/djangoapps/contentstore/tests/test_i18n.py
View file @
248793c1
...
@@ -85,9 +85,11 @@ class InternationalizationTest(ModuleStoreTestCase):
...
@@ -85,9 +85,11 @@ class InternationalizationTest(ModuleStoreTestCase):
HTTP_ACCEPT_LANGUAGE
=
'fr'
HTTP_ACCEPT_LANGUAGE
=
'fr'
)
)
TEST_STRING
=
u'<h1 class="title-1">'
\
TEST_STRING
=
(
+
u'My
\xc7\xf6\xfc
rs
\xe9
s L#'
\
u'<h1 class="title-1">'
+
u'</h1>'
u'My
\xc7\xf6\xfc
rs
\xe9
s L#'
u'</h1>'
)
self
.
assertContains
(
resp
,
self
.
assertContains
(
resp
,
TEST_STRING
,
TEST_STRING
,
...
...
cms/djangoapps/contentstore/tests/test_item.py
View file @
248793c1
...
@@ -14,19 +14,26 @@ class DeleteItem(CourseTestCase):
...
@@ -14,19 +14,26 @@ class DeleteItem(CourseTestCase):
super
(
DeleteItem
,
self
)
.
setUp
()
super
(
DeleteItem
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
(
org
=
'mitX'
,
number
=
'333'
,
display_name
=
'Dummy Course'
)
self
.
course
=
CourseFactory
.
create
(
org
=
'mitX'
,
number
=
'333'
,
display_name
=
'Dummy Course'
)
def
test
DeleteStaticP
age
(
self
):
def
test
_delete_static_p
age
(
self
):
# Add static tab
# Add static tab
data
=
json
.
dumps
({
data
=
json
.
dumps
({
'parent_location'
:
'i4x://mitX/333/course/Dummy_Course'
,
'parent_location'
:
'i4x://mitX/333/course/Dummy_Course'
,
'category'
:
'static_tab'
'category'
:
'static_tab'
})
})
resp
=
self
.
client
.
post
(
reverse
(
'create_item'
),
data
,
resp
=
self
.
client
.
post
(
content_type
=
"application/json"
)
reverse
(
'create_item'
),
data
,
content_type
=
"application/json"
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
# Now delete it. There was a bug that the delete was failing (static tabs do not exist in draft modulestore).
# Now delete it. There was a bug that the delete was failing (static tabs do not exist in draft modulestore).
resp
=
self
.
client
.
post
(
reverse
(
'delete_item'
),
resp
.
content
,
"application/json"
)
resp
=
self
.
client
.
post
(
reverse
(
'delete_item'
),
resp
.
content
,
"application/json"
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
...
@@ -122,6 +129,7 @@ class TestCreateItem(CourseTestCase):
...
@@ -122,6 +129,7 @@ class TestCreateItem(CourseTestCase):
)
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
class
TestEditItem
(
CourseTestCase
):
class
TestEditItem
(
CourseTestCase
):
"""
"""
Test contentstore.views.item.save_item
Test contentstore.views.item.save_item
...
@@ -151,10 +159,10 @@ class TestEditItem(CourseTestCase):
...
@@ -151,10 +159,10 @@ class TestEditItem(CourseTestCase):
chap_location
=
self
.
response_id
(
resp
)
chap_location
=
self
.
response_id
(
resp
)
resp
=
self
.
client
.
post
(
resp
=
self
.
client
.
post
(
reverse
(
'create_item'
),
reverse
(
'create_item'
),
json
.
dumps
(
json
.
dumps
(
{
{
'parent_location'
:
chap_location
,
'parent_location'
:
chap_location
,
'category'
:
'sequential'
'category'
:
'sequential'
,
}),
}),
content_type
=
"application/json"
content_type
=
"application/json"
)
)
self
.
seq_location
=
self
.
response_id
(
resp
)
self
.
seq_location
=
self
.
response_id
(
resp
)
...
@@ -162,9 +170,10 @@ class TestEditItem(CourseTestCase):
...
@@ -162,9 +170,10 @@ class TestEditItem(CourseTestCase):
template_id
=
'multiplechoice.yaml'
template_id
=
'multiplechoice.yaml'
resp
=
self
.
client
.
post
(
resp
=
self
.
client
.
post
(
reverse
(
'create_item'
),
reverse
(
'create_item'
),
json
.
dumps
({
'parent_location'
:
self
.
seq_location
,
json
.
dumps
({
'category'
:
'problem'
,
'parent_location'
:
self
.
seq_location
,
'boilerplate'
:
template_id
'category'
:
'problem'
,
'boilerplate'
:
template_id
,
}),
}),
content_type
=
"application/json"
content_type
=
"application/json"
)
)
...
@@ -195,7 +204,6 @@ class TestEditItem(CourseTestCase):
...
@@ -195,7 +204,6 @@ class TestEditItem(CourseTestCase):
problem
=
modulestore
(
'draft'
)
.
get_item
(
self
.
problems
[
0
])
problem
=
modulestore
(
'draft'
)
.
get_item
(
self
.
problems
[
0
])
self
.
assertEqual
(
problem
.
rerandomize
,
'never'
)
self
.
assertEqual
(
problem
.
rerandomize
,
'never'
)
def
test_null_field
(
self
):
def
test_null_field
(
self
):
"""
"""
Sending null in for a field 'deletes' it
Sending null in for a field 'deletes' it
...
@@ -240,4 +248,3 @@ class TestEditItem(CourseTestCase):
...
@@ -240,4 +248,3 @@ class TestEditItem(CourseTestCase):
sequential
=
modulestore
()
.
get_item
(
self
.
seq_location
)
sequential
=
modulestore
()
.
get_item
(
self
.
seq_location
)
self
.
assertEqual
(
sequential
.
lms
.
due
,
datetime
.
datetime
(
2010
,
11
,
22
,
4
,
0
,
tzinfo
=
UTC
))
self
.
assertEqual
(
sequential
.
lms
.
due
,
datetime
.
datetime
(
2010
,
11
,
22
,
4
,
0
,
tzinfo
=
UTC
))
self
.
assertEqual
(
sequential
.
lms
.
start
,
datetime
.
datetime
(
2010
,
9
,
12
,
14
,
0
,
tzinfo
=
UTC
))
self
.
assertEqual
(
sequential
.
lms
.
start
,
datetime
.
datetime
(
2010
,
9
,
12
,
14
,
0
,
tzinfo
=
UTC
))
cms/djangoapps/contentstore/tests/tests.py
View file @
248793c1
...
@@ -15,14 +15,16 @@ class ContentStoreTestCase(ModuleStoreTestCase):
...
@@ -15,14 +15,16 @@ class ContentStoreTestCase(ModuleStoreTestCase):
Login. View should always return 200. The success/fail is in the
Login. View should always return 200. The success/fail is in the
returned json
returned json
"""
"""
resp
=
self
.
client
.
post
(
reverse
(
'login_post'
),
resp
=
self
.
client
.
post
(
{
'email'
:
email
,
'password'
:
password
})
reverse
(
'login_post'
),
{
'email'
:
email
,
'password'
:
password
}
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
return
resp
return
resp
def
login
(
self
,
email
,
p
w
):
def
login
(
self
,
email
,
p
assword
):
"""Login, check that it worked."""
"""Login, check that it worked."""
resp
=
self
.
_login
(
email
,
p
w
)
resp
=
self
.
_login
(
email
,
p
assword
)
data
=
parse_json
(
resp
)
data
=
parse_json
(
resp
)
self
.
assertTrue
(
data
[
'success'
])
self
.
assertTrue
(
data
[
'success'
])
return
resp
return
resp
...
@@ -178,11 +180,15 @@ class ForumTestCase(CourseTestCase):
...
@@ -178,11 +180,15 @@ class ForumTestCase(CourseTestCase):
def
test_blackouts
(
self
):
def
test_blackouts
(
self
):
now
=
datetime
.
datetime
.
now
(
UTC
)
now
=
datetime
.
datetime
.
now
(
UTC
)
self
.
course
.
discussion_blackouts
=
[(
t
.
isoformat
(),
t2
.
isoformat
())
for
t
,
t2
in
times1
=
[
[(
now
-
datetime
.
timedelta
(
days
=
14
),
now
-
datetime
.
timedelta
(
days
=
11
)),
(
now
-
datetime
.
timedelta
(
days
=
14
),
now
-
datetime
.
timedelta
(
days
=
11
)),
(
now
+
datetime
.
timedelta
(
days
=
24
),
now
+
datetime
.
timedelta
(
days
=
30
))]]
(
now
+
datetime
.
timedelta
(
days
=
24
),
now
+
datetime
.
timedelta
(
days
=
30
))
]
self
.
course
.
discussion_blackouts
=
[(
t
.
isoformat
(),
t2
.
isoformat
())
for
t
,
t2
in
times1
]
self
.
assertTrue
(
self
.
course
.
forum_posts_allowed
)
self
.
assertTrue
(
self
.
course
.
forum_posts_allowed
)
self
.
course
.
discussion_blackouts
=
[(
t
.
isoformat
(),
t2
.
isoformat
())
for
t
,
t2
in
times2
=
[
[(
now
-
datetime
.
timedelta
(
days
=
14
),
now
+
datetime
.
timedelta
(
days
=
2
)),
(
now
-
datetime
.
timedelta
(
days
=
14
),
now
+
datetime
.
timedelta
(
days
=
2
)),
(
now
+
datetime
.
timedelta
(
days
=
24
),
now
+
datetime
.
timedelta
(
days
=
30
))]]
(
now
+
datetime
.
timedelta
(
days
=
24
),
now
+
datetime
.
timedelta
(
days
=
30
))
]
self
.
course
.
discussion_blackouts
=
[(
t
.
isoformat
(),
t2
.
isoformat
())
for
t
,
t2
in
times2
]
self
.
assertFalse
(
self
.
course
.
forum_posts_allowed
)
self
.
assertFalse
(
self
.
course
.
forum_posts_allowed
)
cms/djangoapps/contentstore/views/assets.py
View file @
248793c1
...
@@ -283,7 +283,7 @@ def import_course(request, org, course, name):
...
@@ -283,7 +283,7 @@ def import_course(request, org, course, name):
tar_file
.
extractall
(
course_dir
+
'/'
)
tar_file
.
extractall
(
course_dir
+
'/'
)
# find the 'course.xml' file
# find the 'course.xml' file
dirpath
=
None
for
dirpath
,
_dirnames
,
filenames
in
os
.
walk
(
course_dir
):
for
dirpath
,
_dirnames
,
filenames
in
os
.
walk
(
course_dir
):
for
filename
in
filenames
:
for
filename
in
filenames
:
if
filename
==
'course.xml'
:
if
filename
==
'course.xml'
:
...
...
cms/djangoapps/contentstore/views/component.py
View file @
248793c1
...
@@ -58,6 +58,7 @@ ADVANCED_COMPONENT_POLICY_KEY = 'advanced_modules'
...
@@ -58,6 +58,7 @@ ADVANCED_COMPONENT_POLICY_KEY = 'advanced_modules'
@login_required
@login_required
def
edit_subsection
(
request
,
location
):
def
edit_subsection
(
request
,
location
):
"Edit the subsection of a course"
# check that we have permissions to edit this item
# check that we have permissions to edit this item
try
:
try
:
course
=
get_course_for_item
(
location
)
course
=
get_course_for_item
(
location
)
...
@@ -269,6 +270,7 @@ def assignment_type_update(request, org, course, category, name):
...
@@ -269,6 +270,7 @@ def assignment_type_update(request, org, course, category, name):
@login_required
@login_required
@expect_json
@expect_json
def
create_draft
(
request
):
def
create_draft
(
request
):
"Create a draft"
location
=
request
.
POST
[
'id'
]
location
=
request
.
POST
[
'id'
]
# check permissions for this user within this course
# check permissions for this user within this course
...
@@ -285,6 +287,7 @@ def create_draft(request):
...
@@ -285,6 +287,7 @@ def create_draft(request):
@login_required
@login_required
@expect_json
@expect_json
def
publish_draft
(
request
):
def
publish_draft
(
request
):
"Publish a draft"
location
=
request
.
POST
[
'id'
]
location
=
request
.
POST
[
'id'
]
# check permissions for this user within this course
# check permissions for this user within this course
...
@@ -300,6 +303,7 @@ def publish_draft(request):
...
@@ -300,6 +303,7 @@ def publish_draft(request):
@login_required
@login_required
@expect_json
@expect_json
def
unpublish_unit
(
request
):
def
unpublish_unit
(
request
):
"Unpublish a unit"
location
=
request
.
POST
[
'id'
]
location
=
request
.
POST
[
'id'
]
# check permissions for this user within this course
# check permissions for this user within this course
...
@@ -317,6 +321,7 @@ def unpublish_unit(request):
...
@@ -317,6 +321,7 @@ def unpublish_unit(request):
@login_required
@login_required
@ensure_csrf_cookie
@ensure_csrf_cookie
def
module_info
(
request
,
module_location
):
def
module_info
(
request
,
module_location
):
"Get or set information for a module in the modulestore"
location
=
Location
(
module_location
)
location
=
Location
(
module_location
)
# check that logged in user has permissions to this item
# check that logged in user has permissions to this item
...
...
cms/djangoapps/contentstore/views/preview.py
View file @
248793c1
...
@@ -68,6 +68,7 @@ def preview_dispatch(request, preview_id, location, dispatch=None):
...
@@ -68,6 +68,7 @@ def preview_dispatch(request, preview_id, location, dispatch=None):
@login_required
@login_required
def
preview_component
(
request
,
location
):
def
preview_component
(
request
,
location
):
"Return the HTML preview of a component"
# TODO (vshnayder): change name from id to location in coffee+html as well.
# TODO (vshnayder): change name from id to location in coffee+html as well.
if
not
has_access
(
request
.
user
,
location
):
if
not
has_access
(
request
.
user
,
location
):
return
HttpResponseForbidden
()
return
HttpResponseForbidden
()
...
@@ -91,6 +92,7 @@ def preview_module_system(request, preview_id, descriptor):
...
@@ -91,6 +92,7 @@ def preview_module_system(request, preview_id, descriptor):
"""
"""
def
preview_model_data
(
descriptor
):
def
preview_model_data
(
descriptor
):
"Helper method to create a DbModel from a descriptor"
return
DbModel
(
return
DbModel
(
SessionKeyValueStore
(
request
,
descriptor
.
_model_data
),
SessionKeyValueStore
(
request
,
descriptor
.
_model_data
),
descriptor
.
module_class
,
descriptor
.
module_class
,
...
...
cms/djangoapps/contentstore/views/public.py
View file @
248793c1
"""
Public views
"""
from
django_future.csrf
import
ensure_csrf_cookie
from
django_future.csrf
import
ensure_csrf_cookie
from
django.core.context_processors
import
csrf
from
django.core.context_processors
import
csrf
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
...
@@ -10,10 +13,6 @@ from .user import index
...
@@ -10,10 +13,6 @@ from .user import index
__all__
=
[
'signup'
,
'old_login_redirect'
,
'login_page'
,
'howitworks'
]
__all__
=
[
'signup'
,
'old_login_redirect'
,
'login_page'
,
'howitworks'
]
"""
Public views
"""
@ensure_csrf_cookie
@ensure_csrf_cookie
def
signup
(
request
):
def
signup
(
request
):
...
@@ -45,6 +44,7 @@ def login_page(request):
...
@@ -45,6 +44,7 @@ def login_page(request):
def
howitworks
(
request
):
def
howitworks
(
request
):
"Proxy view"
if
request
.
user
.
is_authenticated
():
if
request
.
user
.
is_authenticated
():
return
index
(
request
)
return
index
(
request
)
else
:
else
:
...
...
cms/djangoapps/contentstore/views/tabs.py
View file @
248793c1
"""
Views related to course tabs
"""
from
access
import
has_access
from
access
import
has_access
from
util.json_request
import
expect_json
from
util.json_request
import
expect_json
...
@@ -39,6 +42,7 @@ def initialize_course_tabs(course):
...
@@ -39,6 +42,7 @@ def initialize_course_tabs(course):
@login_required
@login_required
@expect_json
@expect_json
def
reorder_static_tabs
(
request
):
def
reorder_static_tabs
(
request
):
"Order the static tabs in the requested order"
tabs
=
request
.
POST
[
'tabs'
]
tabs
=
request
.
POST
[
'tabs'
]
course
=
get_course_for_item
(
tabs
[
0
])
course
=
get_course_for_item
(
tabs
[
0
])
...
@@ -86,6 +90,7 @@ def reorder_static_tabs(request):
...
@@ -86,6 +90,7 @@ def reorder_static_tabs(request):
@login_required
@login_required
@ensure_csrf_cookie
@ensure_csrf_cookie
def
edit_tabs
(
request
,
org
,
course
,
coursename
):
def
edit_tabs
(
request
,
org
,
course
,
coursename
):
"Edit tabs"
location
=
[
'i4x'
,
org
,
course
,
'course'
,
coursename
]
location
=
[
'i4x'
,
org
,
course
,
'course'
,
coursename
]
store
=
get_modulestore
(
location
)
store
=
get_modulestore
(
location
)
course_item
=
store
.
get_item
(
location
)
course_item
=
store
.
get_item
(
location
)
...
@@ -122,6 +127,7 @@ def edit_tabs(request, org, course, coursename):
...
@@ -122,6 +127,7 @@ def edit_tabs(request, org, course, coursename):
@login_required
@login_required
@ensure_csrf_cookie
@ensure_csrf_cookie
def
static_pages
(
request
,
org
,
course
,
coursename
):
def
static_pages
(
request
,
org
,
course
,
coursename
):
"Static pages view"
location
=
get_location_and_verify_access
(
request
,
org
,
course
,
coursename
)
location
=
get_location_and_verify_access
(
request
,
org
,
course
,
coursename
)
...
...
pylintrc
View file @
248793c1
...
@@ -160,7 +160,7 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
...
@@ -160,7 +160,7 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
# Good variable names which should always be accepted, separated by a comma
good-names=
i,j,k,ex,Run,
_
good-names=
f,i,j,k,ex,Run,_,_
_
# Bad variable names which should always be refused, separated by a comma
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
bad-names=foo,bar,baz,toto,tutu,tata
...
...
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