diff --git a/.gitignore b/.gitignore
index b1a36e5f2e..4fd90cfe03 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,3 +45,4 @@ node_modules
autodeploy.properties
.ws_migrations_complete
.vagrant/
+logs
diff --git a/.tx/config b/.tx/config
index 540c4732af..9288418924 100644
--- a/.tx/config
+++ b/.tx/config
@@ -1,25 +1,25 @@
[main]
host = https://www.transifex.com
-[edx-studio.django-partial]
+[edx-platform.django-partial]
file_filter = conf/locale//LC_MESSAGES/django-partial.po
source_file = conf/locale/en/LC_MESSAGES/django-partial.po
source_lang = en
type = PO
-[edx-studio.djangojs]
+[edx-platform.djangojs]
file_filter = conf/locale//LC_MESSAGES/djangojs.po
source_file = conf/locale/en/LC_MESSAGES/djangojs.po
source_lang = en
type = PO
-[edx-studio.mako]
+[edx-platform.mako]
file_filter = conf/locale//LC_MESSAGES/mako.po
source_file = conf/locale/en/LC_MESSAGES/mako.po
source_lang = en
type = PO
-[edx-studio.messages]
+[edx-platform.messages]
file_filter = conf/locale//LC_MESSAGES/messages.po
source_file = conf/locale/en/LC_MESSAGES/messages.po
source_lang = en
diff --git a/AUTHORS b/AUTHORS
index 70af9f318d..89fc2d959b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -81,3 +81,4 @@ Felix Sun
Adam Palay
Ian Hoover
Mukul Goyal
+Robert Marks
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 4d117a9c73..468db0607c 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -5,10 +5,13 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected.
+
Common: Added *experimental* support for jsinput type.
Common: Added setting to specify Celery Broker vhost
+Common: Utilize new XBlock bulk save API in LMS and CMS.
+
Studio: Add table for tracking course creator permissions (not yet used).
Update rake django-admin[syncdb] and rake django-admin[migrate] so they
run for both LMS and CMS.
@@ -21,6 +24,8 @@ Studio: Added support for uploading and managing PDF textbooks
Common: Student information is now passed to the tracking log via POST instead of GET.
+Blades: Added functionality and tests for new capa input type: choicetextresponse.
+
Common: Add tests for documentation generation to test suite
Blades: User answer now preserved (and changeable) after clicking "show answer" in choice problems
@@ -43,6 +48,13 @@ history of background tasks for a given problem and student.
Blades: Small UX fix on capa multiple-choice problems. Make labels only
as wide as the text to reduce accidental choice selections.
+Studio:
+- use xblock field defaults to initialize all new instances' fields and
+only use templates as override samples.
+- create new instances via in memory create_xmodule and related methods rather
+than cloning a db record.
+- have an explicit method for making a draft copy as distinct from making a new module.
+
Studio: Remove XML from the video component editor. All settings are
moved to be edited as metadata.
diff --git a/README.md b/README.md
index e533459c8b..2208fe1cad 100644
--- a/README.md
+++ b/README.md
@@ -239,7 +239,6 @@ CMS templates. Fortunately, `rake` will do all of this for you! Just run:
$ rake django-admin[syncdb]
$ rake django-admin[migrate]
- $ rake cms:update_templates
If you are running these commands using the [`zsh`](http://www.zsh.org/) shell,
zsh will assume that you are doing
diff --git a/cms/djangoapps/contentstore/course_info_model.py b/cms/djangoapps/contentstore/course_info_model.py
index ada3873992..7e1e6470ff 100644
--- a/cms/djangoapps/contentstore/course_info_model.py
+++ b/cms/djangoapps/contentstore/course_info_model.py
@@ -20,8 +20,8 @@ def get_course_updates(location):
try:
course_updates = modulestore('direct').get_item(location)
except ItemNotFoundError:
- template = Location(['i4x', 'edx', "templates", 'course_info', "Empty"])
- course_updates = modulestore('direct').clone_item(template, Location(location))
+ modulestore('direct').create_and_save_xmodule(location)
+ course_updates = modulestore('direct').get_item(location)
# current db rep: {"_id" : locationjson, "definition" : { "data" : "[
date
content
]"} "metadata" : ignored}
location_base = course_updates.location.url()
diff --git a/cms/djangoapps/contentstore/features/common.py b/cms/djangoapps/contentstore/features/common.py
index cb24af47e0..756adad7c4 100644
--- a/cms/djangoapps/contentstore/features/common.py
+++ b/cms/djangoapps/contentstore/features/common.py
@@ -208,7 +208,7 @@ def set_date_and_time(date_css, desired_date, time_css, desired_time):
def i_created_a_video_component(step):
world.create_component_instance(
step, '.large-video-icon',
- 'i4x://edx/templates/video/default',
+ 'video',
'.xmodule_VideoModule'
)
diff --git a/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py b/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py
index 43164f62be..2f1788c6a4 100644
--- a/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py
+++ b/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py
@@ -7,9 +7,9 @@ from terrain.steps import reload_the_page
@world.absorb
-def create_component_instance(step, component_button_css, instance_id, expected_css):
+def create_component_instance(step, component_button_css, category, expected_css, boilerplate=None):
click_new_component_button(step, component_button_css)
- click_component_from_menu(instance_id, expected_css)
+ click_component_from_menu(category, boilerplate, expected_css)
@world.absorb
@@ -19,7 +19,7 @@ def click_new_component_button(step, component_button_css):
@world.absorb
-def click_component_from_menu(instance_id, expected_css):
+def click_component_from_menu(category, boilerplate, expected_css):
"""
Creates a component from `instance_id`. For components with more
than one template, clicks on `elem_css` to create the new
@@ -27,11 +27,13 @@ def click_component_from_menu(instance_id, expected_css):
as the user clicks the appropriate button, so we assert that the
expected component is present.
"""
- elem_css = "a[data-location='%s']" % instance_id
+ if boilerplate:
+ elem_css = "a[data-category='{}'][data-boilerplate='{}']".format(category, boilerplate)
+ else:
+ elem_css = "a[data-category='{}']:not([data-boilerplate])".format(category)
elements = world.css_find(elem_css)
- assert(len(elements) == 1)
- if elements[0]['id'] == instance_id: # If this is a component with multiple templates
- world.css_click(elem_css)
+ assert_equal(len(elements), 1)
+ world.css_click(elem_css)
assert_equal(1, len(world.css_find(expected_css)))
diff --git a/cms/djangoapps/contentstore/features/discussion-editor.py b/cms/djangoapps/contentstore/features/discussion-editor.py
index ae3da3c458..8e4becb62e 100644
--- a/cms/djangoapps/contentstore/features/discussion-editor.py
+++ b/cms/djangoapps/contentstore/features/discussion-editor.py
@@ -8,7 +8,7 @@ from lettuce import world, step
def i_created_discussion_tag(step):
world.create_component_instance(
step, '.large-discussion-icon',
- 'i4x://edx/templates/discussion/Discussion_Tag',
+ 'discussion',
'.xmodule_DiscussionModule'
)
@@ -17,14 +17,14 @@ def i_created_discussion_tag(step):
def i_see_only_the_settings_and_values(step):
world.verify_all_setting_entries(
[
- ['Category', "Week 1", True],
- ['Display Name', "Discussion Tag", True],
- ['Subcategory', "Topic-Level Student-Visible Label", True]
+ ['Category', "Week 1", False],
+ ['Display Name', "Discussion Tag", False],
+ ['Subcategory', "Topic-Level Student-Visible Label", False]
])
@step('creating a discussion takes a single click')
def discussion_takes_a_single_click(step):
assert(not world.is_css_present('.xmodule_DiscussionModule'))
- world.css_click("a[data-location='i4x://edx/templates/discussion/Discussion_Tag']")
+ world.css_click("a[data-category='discussion']")
assert(world.is_css_present('.xmodule_DiscussionModule'))
diff --git a/cms/djangoapps/contentstore/features/html-editor.py b/cms/djangoapps/contentstore/features/html-editor.py
index 054c0ea642..b03388c89a 100644
--- a/cms/djangoapps/contentstore/features/html-editor.py
+++ b/cms/djangoapps/contentstore/features/html-editor.py
@@ -7,11 +7,11 @@ from lettuce import world, step
@step('I have created a Blank HTML Page$')
def i_created_blank_html_page(step):
world.create_component_instance(
- step, '.large-html-icon', 'i4x://edx/templates/html/Blank_HTML_Page',
+ step, '.large-html-icon', 'html',
'.xmodule_HtmlModule'
)
@step('I see only the HTML display name setting$')
def i_see_only_the_html_display_name(step):
- world.verify_all_setting_entries([['Display Name', "Blank HTML Page", True]])
+ world.verify_all_setting_entries([['Display Name', "Blank HTML Page", False]])
diff --git a/cms/djangoapps/contentstore/features/problem-editor.py b/cms/djangoapps/contentstore/features/problem-editor.py
index 5d12b23d90..64b2ec9b5c 100644
--- a/cms/djangoapps/contentstore/features/problem-editor.py
+++ b/cms/djangoapps/contentstore/features/problem-editor.py
@@ -18,8 +18,9 @@ def i_created_blank_common_problem(step):
world.create_component_instance(
step,
'.large-problem-icon',
- 'i4x://edx/templates/problem/Blank_Common_Problem',
- '.xmodule_CapaModule'
+ 'problem',
+ '.xmodule_CapaModule',
+ 'blank_common.yaml'
)
@@ -35,8 +36,8 @@ def i_see_five_settings_with_values(step):
[DISPLAY_NAME, "Blank Common Problem", True],
[MAXIMUM_ATTEMPTS, "", False],
[PROBLEM_WEIGHT, "", False],
- [RANDOMIZATION, "Never", True],
- [SHOW_ANSWER, "Finished", True]
+ [RANDOMIZATION, "Never", False],
+ [SHOW_ANSWER, "Finished", False]
])
@@ -94,7 +95,7 @@ def my_change_to_randomization_is_persisted(step):
def i_can_revert_to_default_for_randomization(step):
world.revert_setting_entry(RANDOMIZATION)
world.save_component_and_reopen(step)
- world.verify_setting_entry(world.get_setting_entry(RANDOMIZATION), RANDOMIZATION, "Always", False)
+ world.verify_setting_entry(world.get_setting_entry(RANDOMIZATION), RANDOMIZATION, "Never", False)
@step('I can set the weight to "(.*)"?')
@@ -156,7 +157,7 @@ def create_latex_problem(step):
world.click_new_component_button(step, '.large-problem-icon')
# Go to advanced tab.
world.css_click('#ui-id-2')
- world.click_component_from_menu("i4x://edx/templates/problem/Problem_Written_in_LaTeX", '.xmodule_CapaModule')
+ world.click_component_from_menu("problem", "latex_problem.yaml", '.xmodule_CapaModule')
@step('I edit and compile the High Level Source')
@@ -203,7 +204,7 @@ def verify_modified_display_name_with_special_chars():
def verify_unset_display_name():
- world.verify_setting_entry(world.get_setting_entry(DISPLAY_NAME), DISPLAY_NAME, '', False)
+ world.verify_setting_entry(world.get_setting_entry(DISPLAY_NAME), DISPLAY_NAME, 'Blank Advanced Problem', False)
def set_weight(weight):
diff --git a/cms/djangoapps/contentstore/features/studio-overview-togglesection.py b/cms/djangoapps/contentstore/features/studio-overview-togglesection.py
index 9ab17fbdac..41e39513ea 100644
--- a/cms/djangoapps/contentstore/features/studio-overview-togglesection.py
+++ b/cms/djangoapps/contentstore/features/studio-overview-togglesection.py
@@ -22,7 +22,7 @@ def have_a_course_with_1_section(step):
section = world.ItemFactory.create(parent_location=course.location)
subsection1 = world.ItemFactory.create(
parent_location=section.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name='Subsection One',)
@@ -33,18 +33,18 @@ def have_a_course_with_two_sections(step):
section = world.ItemFactory.create(parent_location=course.location)
subsection1 = world.ItemFactory.create(
parent_location=section.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name='Subsection One',)
section2 = world.ItemFactory.create(
parent_location=course.location,
display_name='Section Two',)
subsection2 = world.ItemFactory.create(
parent_location=section2.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name='Subsection Alpha',)
subsection3 = world.ItemFactory.create(
parent_location=section2.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name='Subsection Beta',)
diff --git a/cms/djangoapps/contentstore/features/video-editor.py b/cms/djangoapps/contentstore/features/video-editor.py
index a6865fdd6d..e0f76b30ad 100644
--- a/cms/djangoapps/contentstore/features/video-editor.py
+++ b/cms/djangoapps/contentstore/features/video-editor.py
@@ -7,7 +7,7 @@ from lettuce import world, step
@step('I see the correct settings and default values$')
def i_see_the_correct_settings_and_values(step):
world.verify_all_setting_entries([['Default Speed', 'OEoXaMPEzfM', False],
- ['Display Name', 'default', True],
+ ['Display Name', 'Video Title', False],
['Download Track', '', False],
['Download Video', '', False],
['Show Captions', 'True', False],
diff --git a/cms/djangoapps/contentstore/features/video.py b/cms/djangoapps/contentstore/features/video.py
index cb59193f17..a6a362befc 100644
--- a/cms/djangoapps/contentstore/features/video.py
+++ b/cms/djangoapps/contentstore/features/video.py
@@ -14,7 +14,7 @@ def does_not_autoplay(_step):
@step('creating a video takes a single click')
def video_takes_a_single_click(_step):
assert(not world.is_css_present('.xmodule_VideoModule'))
- world.css_click("a[data-location='i4x://edx/templates/video/default']")
+ world.css_click("a[data-category='video']")
assert(world.is_css_present('.xmodule_VideoModule'))
diff --git a/cms/djangoapps/contentstore/management/commands/dump_course_structure.py b/cms/djangoapps/contentstore/management/commands/dump_course_structure.py
new file mode 100644
index 0000000000..d9b7c55cbd
--- /dev/null
+++ b/cms/djangoapps/contentstore/management/commands/dump_course_structure.py
@@ -0,0 +1,55 @@
+from django.core.management.base import BaseCommand, CommandError
+from xmodule.course_module import CourseDescriptor
+from xmodule.modulestore.django import modulestore
+from json import dumps
+from xmodule.modulestore.inheritance import own_metadata
+from django.conf import settings
+
+filter_list = ['xml_attributes', 'checklists']
+
+
+class Command(BaseCommand):
+ 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.'''
+
+ def handle(self, *args, **options):
+ if len(args) < 2 or len(args) > 3:
+ raise CommandError("dump_course_structure requires two or more arguments: ||")
+
+ course_id = args[0]
+ outfile = args[1]
+
+ # use a user-specified database name, if present
+ # this is useful for doing dumps from databases restored from prod backups
+ if len(args) == 3:
+ settings.MODULESTORE['direct']['OPTIONS']['db'] = args[2]
+
+ loc = CourseDescriptor.id_to_location(course_id)
+
+ store = modulestore()
+
+ course = None
+ try:
+ course = store.get_item(loc, depth=4)
+ except:
+ print 'Could not find course at {0}'.format(course_id)
+ return
+
+ info = {}
+
+ def dump_into_dict(module, info):
+ filtered_metadata = dict((key, value) for key, value in own_metadata(module).iteritems()
+ if key not in filter_list)
+ info[module.location.url()] = {
+ 'category': module.location.category,
+ 'children': module.children if hasattr(module, 'children') else [],
+ 'metadata': filtered_metadata
+ }
+
+ for child in module.get_children():
+ dump_into_dict(child, info)
+
+ dump_into_dict(course, info)
+
+ with open(outfile, 'w') as f:
+ f.write(dumps(info))
diff --git a/cms/djangoapps/contentstore/management/commands/update_templates.py b/cms/djangoapps/contentstore/management/commands/update_templates.py
deleted file mode 100644
index 36348314b9..0000000000
--- a/cms/djangoapps/contentstore/management/commands/update_templates.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from xmodule.templates import update_templates
-from xmodule.modulestore.django import modulestore
-from django.core.management.base import BaseCommand
-
-
-class Command(BaseCommand):
- help = 'Imports and updates the Studio component templates from the code pack and put in the DB'
-
- def handle(self, *args, **options):
- update_templates(modulestore('direct'))
diff --git a/cms/djangoapps/contentstore/module_info_model.py b/cms/djangoapps/contentstore/module_info_model.py
index 726d4bb0ce..bce4b0326c 100644
--- a/cms/djangoapps/contentstore/module_info_model.py
+++ b/cms/djangoapps/contentstore/module_info_model.py
@@ -3,13 +3,13 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore import Location
-def get_module_info(store, location, parent_location=None, rewrite_static_links=False):
+def get_module_info(store, location, rewrite_static_links=False):
try:
module = store.get_item(location)
except ItemNotFoundError:
# create a new one
- template_location = Location(['i4x', 'edx', 'templates', location.category, 'Empty'])
- module = store.clone_item(template_location, location)
+ store.create_and_save_xmodule(location)
+ module = store.get_item(location)
data = module.data
if rewrite_static_links:
@@ -29,7 +29,8 @@ def get_module_info(store, location, parent_location=None, rewrite_static_links=
'id': module.location.url(),
'data': data,
# TODO (cpennington): This really shouldn't have to do this much reaching in to get the metadata
- 'metadata': module._model_data._kvs._metadata
+ # what's the intent here? all metadata incl inherited & namespaced?
+ 'metadata': module.xblock_kvs._metadata
}
@@ -37,14 +38,11 @@ def set_module_info(store, location, post_data):
module = None
try:
module = store.get_item(location)
- except:
- pass
-
- if module is None:
- # new module at this location
- # presume that we have an 'Empty' template
- template_location = Location(['i4x', 'edx', 'templates', location.category, 'Empty'])
- module = store.clone_item(template_location, location)
+ except ItemNotFoundError:
+ # new module at this location: almost always used for the course about pages; thus, no parent. (there
+ # are quite a handful of about page types available for a course and only the overview is pre-created)
+ store.create_and_save_xmodule(location)
+ module = store.get_item(location)
if post_data.get('data') is not None:
data = post_data['data']
@@ -79,4 +77,4 @@ def set_module_info(store, location, post_data):
# commit to datastore
# TODO (cpennington): This really shouldn't have to do this much reaching in to get the metadata
- store.update_metadata(location, module._model_data._kvs._metadata)
+ store.update_metadata(location, module.xblock_kvs._metadata)
diff --git a/cms/djangoapps/contentstore/tests/test_checklists.py b/cms/djangoapps/contentstore/tests/test_checklists.py
index 99ffb8678d..02999f6567 100644
--- a/cms/djangoapps/contentstore/tests/test_checklists.py
+++ b/cms/djangoapps/contentstore/tests/test_checklists.py
@@ -46,6 +46,8 @@ class ChecklistTestCase(CourseTestCase):
# Now delete the checklists from the course and verify they get repopulated (for courses
# created before checklists were introduced).
self.course.checklists = None
+ # Save the changed `checklists` to the underlying KeyValueStore before updating the modulestore
+ self.course.save()
modulestore = get_modulestore(self.course.location)
modulestore.update_metadata(self.course.location, own_metadata(self.course))
self.assertEqual(self.get_persisted_checklists(), None)
diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py
index be122fa1a4..ce7e886220 100644
--- a/cms/djangoapps/contentstore/tests/test_contentstore.py
+++ b/cms/djangoapps/contentstore/tests/test_contentstore.py
@@ -24,12 +24,11 @@ from auth.authz import add_user_to_creator_group
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.modulestore import Location
+from xmodule.modulestore import Location, mongo
from xmodule.modulestore.store_utilities import clone_course
from xmodule.modulestore.store_utilities import delete_course
from xmodule.modulestore.django import modulestore
from xmodule.contentstore.django import contentstore, _CONTENTSTORE
-from xmodule.templates import update_templates
from xmodule.modulestore.xml_exporter import export_to_xml
from xmodule.modulestore.xml_importer import import_from_xml, perform_xlint
from xmodule.modulestore.inheritance import own_metadata
@@ -88,6 +87,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.user.is_active = True
# Staff has access to view all courses
self.user.is_staff = True
+
+ # Save the data that we've just changed to the db.
self.user.save()
self.client = Client()
@@ -118,6 +119,10 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
course.advanced_modules = component_types
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ course.save()
+
store.update_metadata(course.location, own_metadata(course))
# just pick one vertical
@@ -135,7 +140,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.check_components_on_page(ADVANCED_COMPONENT_TYPES, ['Video Alpha',
'Word cloud',
'Annotation',
- 'Open Ended Response',
+ 'Open Response Assessment',
'Peer Grading Interface'])
def test_advanced_components_require_two_clicks(self):
@@ -183,7 +188,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
html_module = draft_store.get_item(['i4x', 'edX', 'simple', 'html', 'test_html', None])
- draft_store.clone_item(html_module.location, html_module.location)
+ draft_store.convert_to_draft(html_module.location)
# now query get_items() to get this location with revision=None, this should just
# return back a single item (not 2)
@@ -215,7 +220,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(html_module.lms.graceperiod, course.lms.graceperiod)
self.assertNotIn('graceperiod', own_metadata(html_module))
- draft_store.clone_item(html_module.location, html_module.location)
+ draft_store.convert_to_draft(html_module.location)
# refetch to check metadata
html_module = draft_store.get_item(['i4x', 'edX', 'simple', 'html', 'test_html', None])
@@ -233,13 +238,16 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertNotIn('graceperiod', own_metadata(html_module))
# put back in draft and change metadata and see if it's now marked as 'own_metadata'
- draft_store.clone_item(html_module.location, html_module.location)
+ draft_store.convert_to_draft(html_module.location)
html_module = draft_store.get_item(['i4x', 'edX', 'simple', 'html', 'test_html', None])
new_graceperiod = timedelta(hours=1)
self.assertNotIn('graceperiod', own_metadata(html_module))
html_module.lms.graceperiod = new_graceperiod
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ html_module.save()
self.assertIn('graceperiod', own_metadata(html_module))
self.assertEqual(html_module.lms.graceperiod, new_graceperiod)
@@ -255,7 +263,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
draft_store.publish(html_module.location, 0)
# and re-read and verify 'own-metadata'
- draft_store.clone_item(html_module.location, html_module.location)
+ draft_store.convert_to_draft(html_module.location)
html_module = draft_store.get_item(['i4x', 'edX', 'simple', 'html', 'test_html', None])
self.assertIn('graceperiod', own_metadata(html_module))
@@ -278,7 +286,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
)
# put into draft
- modulestore('draft').clone_item(problem.location, problem.location)
+ modulestore('draft').convert_to_draft(problem.location)
# make sure we can query that item and verify that it is a draft
draft_problem = modulestore('draft').get_item(
@@ -309,12 +317,14 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
CourseFactory.create(org='edX', course='999', display_name='Robot Super Course')
course_location = Location(['i4x', 'edX', '999', 'course', 'Robot_Super_Course', None])
- ItemFactory.create(parent_location=course_location,
- template="i4x://edx/templates/static_tab/Empty",
- display_name="Static_1")
- ItemFactory.create(parent_location=course_location,
- template="i4x://edx/templates/static_tab/Empty",
- display_name="Static_2")
+ ItemFactory.create(
+ parent_location=course_location,
+ category="static_tab",
+ display_name="Static_1")
+ ItemFactory.create(
+ parent_location=course_location,
+ category="static_tab",
+ display_name="Static_2")
course = module_store.get_item(Location(['i4x', 'edX', '999', 'course', 'Robot_Super_Course', None]))
@@ -371,7 +381,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
course_location = Location(['i4x', 'edX', '999', 'course', 'Robot_Super_Course', None])
chapterloc = ItemFactory.create(parent_location=course_location, display_name="Chapter").location
- ItemFactory.create(parent_location=chapterloc, template='i4x://edx/templates/sequential/Empty', display_name="Sequential")
+ ItemFactory.create(parent_location=chapterloc, category='sequential', display_name="Sequential")
sequential = direct_store.get_item(Location(['i4x', 'edX', '999', 'sequential', 'Sequential', None]))
chapter = direct_store.get_item(Location(['i4x', 'edX', '999', 'chapter', 'Chapter', None]))
@@ -574,7 +584,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
def test_clone_course(self):
course_data = {
- 'template': 'i4x://edx/templates/course/Empty',
'org': 'MITx',
'number': '999',
'display_name': 'Robot Super Course',
@@ -614,10 +623,10 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course')
location = Location('i4x://MITx/999/chapter/neuvo')
- self.assertRaises(InvalidVersionError, draft_store.clone_item, 'i4x://edx/templates/chapter/Empty',
- location)
- direct_store.clone_item('i4x://edx/templates/chapter/Empty', location)
- self.assertRaises(InvalidVersionError, draft_store.clone_item, location, location)
+ # Ensure draft mongo store does not allow us to create chapters either directly or via convert to draft
+ self.assertRaises(InvalidVersionError, draft_store.create_and_save_xmodule, location)
+ direct_store.create_and_save_xmodule(location)
+ self.assertRaises(InvalidVersionError, draft_store.convert_to_draft, location)
self.assertRaises(InvalidVersionError, draft_store.update_item, location, 'chapter data')
@@ -652,9 +661,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
vertical = module_store.get_item(Location(['i4x', 'edX', 'toy',
'vertical', 'vertical_test', None]), depth=1)
- draft_store.clone_item(vertical.location, vertical.location)
+ draft_store.convert_to_draft(vertical.location)
for child in vertical.get_children():
- draft_store.clone_item(child.location, child.location)
+ draft_store.convert_to_draft(child.location)
# delete the course
delete_course(module_store, content_store, location, commit=True)
@@ -687,26 +696,35 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
import_from_xml(module_store, 'common/test/data/', ['toy'])
location = CourseDescriptor.id_to_location('edX/toy/2012_Fall')
- # get a vertical (and components in it) to put into 'draft'
- vertical = module_store.get_item(Location(['i4x', 'edX', 'toy',
- 'vertical', 'vertical_test', None]), depth=1)
-
- draft_store.clone_item(vertical.location, vertical.location)
-
+ # get a vertical (and components in it) to copy into an orphan sub dag
+ vertical = module_store.get_item(
+ Location(['i4x', 'edX', 'toy', 'vertical', 'vertical_test', None]),
+ depth=1
+ )
# We had a bug where orphaned draft nodes caused export to fail. This is here to cover that case.
- draft_store.clone_item(vertical.location, Location(['i4x', 'edX', 'toy',
- 'vertical', 'no_references', 'draft']))
+ vertical.location = mongo.draft.as_draft(vertical.location.replace(name='no_references'))
+ draft_store.save_xmodule(vertical)
+ orphan_vertical = draft_store.get_item(vertical.location)
+ self.assertEqual(orphan_vertical.location.name, 'no_references')
+ # get the original vertical (and components in it) to put into 'draft'
+ vertical = module_store.get_item(
+ Location(['i4x', 'edX', 'toy', 'vertical', 'vertical_test', None]),
+ depth=1)
+ self.assertEqual(len(orphan_vertical.children), len(vertical.children))
+ draft_store.convert_to_draft(vertical.location)
for child in vertical.get_children():
- draft_store.clone_item(child.location, child.location)
+ draft_store.convert_to_draft(child.location)
root_dir = path(mkdtemp_clean())
- # now create a private vertical
- private_vertical = draft_store.clone_item(vertical.location,
- Location(['i4x', 'edX', 'toy', 'vertical', 'a_private_vertical', None]))
+ # now create a new/different private (draft only) vertical
+ vertical.location = mongo.draft.as_draft(Location(['i4x', 'edX', 'toy', 'vertical', 'a_private_vertical', None]))
+ draft_store.save_xmodule(vertical)
+ private_vertical = draft_store.get_item(vertical.location)
+ vertical = None # blank out b/c i destructively manipulated its location 2 lines above
- # add private to list of children
+ # add the new private to list of children
sequential = module_store.get_item(Location(['i4x', 'edX', 'toy',
'sequential', 'vertical_sequential', None]))
private_location_no_draft = private_vertical.location.replace(revision=None)
@@ -792,6 +810,34 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
shutil.rmtree(root_dir)
+ def test_export_course_with_metadata_only_video(self):
+ module_store = modulestore('direct')
+ draft_store = modulestore('draft')
+ content_store = contentstore()
+
+ import_from_xml(module_store, 'common/test/data/', ['toy'])
+ location = CourseDescriptor.id_to_location('edX/toy/2012_Fall')
+
+ # create a new video module and add it as a child to a vertical
+ # this re-creates a bug whereby since the video template doesn't have
+ # anything in 'data' field, the export was blowing up
+ verticals = module_store.get_items(['i4x', 'edX', 'toy', 'vertical', None, None])
+
+ self.assertGreater(len(verticals), 0)
+
+ parent = verticals[0]
+
+ ItemFactory.create(parent_location=parent.location, category="video", display_name="untitled")
+
+ root_dir = path(mkdtemp_clean())
+
+ print 'Exporting to tempdir = {0}'.format(root_dir)
+
+ # export out to a tempdir
+ export_to_xml(module_store, content_store, location, root_dir, 'test_export', draft_modulestore=draft_store)
+
+ shutil.rmtree(root_dir)
+
def test_course_handouts_rewrites(self):
module_store = modulestore('direct')
@@ -846,6 +892,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
# add a bool piece of unknown metadata so we can verify we don't throw an exception
metadata['new_metadata'] = True
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ course.save()
module_store.update_metadata(location, metadata)
print 'Exporting to tempdir = {0}'.format(root_dir)
@@ -885,7 +934,6 @@ class ContentStoreTest(ModuleStoreTestCase):
self.client.login(username=uname, password=password)
self.course_data = {
- 'template': 'i4x://edx/templates/course/Empty',
'org': 'MITx',
'number': '999',
'display_name': 'Robot Super Course',
@@ -1029,17 +1077,17 @@ class ContentStoreTest(ModuleStoreTestCase):
html=True
)
- def test_clone_item(self):
+ def test_create_item(self):
"""Test cloning an item. E.g. creating a new section"""
CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course')
section_data = {
'parent_location': 'i4x://MITx/999/course/Robot_Super_Course',
- 'template': 'i4x://edx/templates/chapter/Empty',
+ 'category': 'chapter',
'display_name': 'Section One',
}
- resp = self.client.post(reverse('clone_item'), section_data)
+ resp = self.client.post(reverse('create_item'), section_data)
self.assertEqual(resp.status_code, 200)
data = parse_json(resp)
@@ -1054,14 +1102,14 @@ class ContentStoreTest(ModuleStoreTestCase):
problem_data = {
'parent_location': 'i4x://MITx/999/course/Robot_Super_Course',
- 'template': 'i4x://edx/templates/problem/Blank_Common_Problem'
+ 'category': 'problem'
}
- resp = self.client.post(reverse('clone_item'), problem_data)
+ resp = self.client.post(reverse('create_item'), problem_data)
self.assertEqual(resp.status_code, 200)
payload = parse_json(resp)
- problem_loc = payload['id']
+ problem_loc = Location(payload['id'])
problem = get_modulestore(problem_loc).get_item(problem_loc)
# should be a CapaDescriptor
self.assertIsInstance(problem, CapaDescriptor, "New problem is not a CapaDescriptor")
@@ -1194,10 +1242,9 @@ class ContentStoreTest(ModuleStoreTestCase):
CourseFactory.create(org='edX', course='999', display_name='Robot Super Course')
new_component_location = Location('i4x', 'edX', '999', 'discussion', 'new_component')
- source_template_location = Location('i4x', 'edx', 'templates', 'discussion', 'Discussion_Tag')
# crate a new module and add it as a child to a vertical
- module_store.clone_item(source_template_location, new_component_location)
+ module_store.create_and_save_xmodule(new_component_location)
new_discussion_item = module_store.get_item(new_component_location)
@@ -1218,10 +1265,9 @@ class ContentStoreTest(ModuleStoreTestCase):
module_store.modulestore_update_signal.connect(_signal_hander)
new_component_location = Location('i4x', 'edX', '999', 'html', 'new_component')
- source_template_location = Location('i4x', 'edx', 'templates', 'html', 'Blank_HTML_Page')
# crate a new module
- module_store.clone_item(source_template_location, new_component_location)
+ module_store.create_and_save_xmodule(new_component_location)
finally:
module_store.modulestore_update_signal = None
@@ -1239,14 +1285,14 @@ class ContentStoreTest(ModuleStoreTestCase):
# let's assert on the metadata_inheritance on an existing vertical
for vertical in verticals:
self.assertEqual(course.lms.xqa_key, vertical.lms.xqa_key)
+ self.assertEqual(course.start, vertical.lms.start)
self.assertGreater(len(verticals), 0)
new_component_location = Location('i4x', 'edX', 'toy', 'html', 'new_component')
- source_template_location = Location('i4x', 'edx', 'templates', 'html', 'Blank_HTML_Page')
# crate a new module and add it as a child to a vertical
- module_store.clone_item(source_template_location, new_component_location)
+ module_store.create_and_save_xmodule(new_component_location)
parent = verticals[0]
module_store.update_children(parent.location, parent.children + [new_component_location.url()])
@@ -1256,6 +1302,8 @@ class ContentStoreTest(ModuleStoreTestCase):
# check for grace period definition which should be defined at the course level
self.assertEqual(parent.lms.graceperiod, new_module.lms.graceperiod)
+ self.assertEqual(parent.lms.start, new_module.lms.start)
+ self.assertEqual(course.start, new_module.lms.start)
self.assertEqual(course.lms.xqa_key, new_module.lms.xqa_key)
@@ -1263,6 +1311,7 @@ class ContentStoreTest(ModuleStoreTestCase):
# now let's define an override at the leaf node level
#
new_module.lms.graceperiod = timedelta(1)
+ new_module.save()
module_store.update_metadata(new_module.location, own_metadata(new_module))
# flush the cache and refetch
@@ -1271,29 +1320,25 @@ class ContentStoreTest(ModuleStoreTestCase):
self.assertEqual(timedelta(1), new_module.lms.graceperiod)
+ def test_default_metadata_inheritance(self):
+ course = CourseFactory.create()
+ vertical = ItemFactory.create(parent_location=course.location)
+ course.children.append(vertical)
+ # in memory
+ self.assertIsNotNone(course.start)
+ self.assertEqual(course.start, vertical.lms.start)
+ self.assertEqual(course.textbooks, [])
+ self.assertIn('GRADER', course.grading_policy)
+ self.assertIn('GRADE_CUTOFFS', course.grading_policy)
+ self.assertGreaterEqual(len(course.checklists), 4)
-class TemplateTestCase(ModuleStoreTestCase):
-
- def test_template_cleanup(self):
+ # by fetching
module_store = modulestore('direct')
-
- # insert a bogus template in the store
- bogus_template_location = Location('i4x', 'edx', 'templates', 'html', 'bogus')
- source_template_location = Location('i4x', 'edx', 'templates', 'html', 'Blank_HTML_Page')
-
- module_store.clone_item(source_template_location, bogus_template_location)
-
- verify_create = module_store.get_item(bogus_template_location)
- self.assertIsNotNone(verify_create)
-
- # now run cleanup
- update_templates(modulestore('direct'))
-
- # now try to find dangling template, it should not be in DB any longer
- asserted = False
- try:
- verify_create = module_store.get_item(bogus_template_location)
- except ItemNotFoundError:
- asserted = True
-
- self.assertTrue(asserted)
+ fetched_course = module_store.get_item(course.location)
+ fetched_item = module_store.get_item(vertical.location)
+ self.assertIsNotNone(fetched_course.start)
+ self.assertEqual(course.start, fetched_course.start)
+ self.assertEqual(fetched_course.start, fetched_item.lms.start)
+ self.assertEqual(course.textbooks, fetched_course.textbooks)
+ # is this test too strict? i.e., it requires the dicts to be ==
+ self.assertEqual(course.checklists, fetched_course.checklists)
diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py
index 21d7d69d41..0862eb462d 100644
--- a/cms/djangoapps/contentstore/tests/test_course_settings.py
+++ b/cms/djangoapps/contentstore/tests/test_course_settings.py
@@ -19,6 +19,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
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 .utils import CourseTestCase
@@ -36,7 +37,6 @@ class CourseDetailsTestCase(CourseTestCase):
self.assertIsNone(details.enrollment_start, "enrollment_start date somehow initialized " + str(details.enrollment_start))
self.assertIsNone(details.enrollment_end, "enrollment_end date somehow initialized " + str(details.enrollment_end))
self.assertIsNone(details.syllabus, "syllabus somehow initialized" + str(details.syllabus))
- self.assertEqual(details.overview, "", "overview somehow initialized" + details.overview)
self.assertIsNone(details.intro_video, "intro_video somehow initialized" + str(details.intro_video))
self.assertIsNone(details.effort, "effort somehow initialized" + str(details.effort))
@@ -49,7 +49,6 @@ class CourseDetailsTestCase(CourseTestCase):
self.assertIsNone(jsondetails['enrollment_start'], "enrollment_start date somehow initialized ")
self.assertIsNone(jsondetails['enrollment_end'], "enrollment_end date somehow initialized ")
self.assertIsNone(jsondetails['syllabus'], "syllabus somehow initialized")
- self.assertEqual(jsondetails['overview'], "", "overview somehow initialized")
self.assertIsNone(jsondetails['intro_video'], "intro_video somehow initialized")
self.assertIsNone(jsondetails['effort'], "effort somehow initialized")
@@ -291,6 +290,71 @@ class CourseGradingTest(CourseTestCase):
altered_grader = CourseGradingModel.update_grader_from_json(test_grader.course_location, test_grader.graders[1])
self.assertDictEqual(test_grader.graders[1], altered_grader, "drop_count[1] + 2")
+ def test_update_cutoffs_from_json(self):
+ test_grader = CourseGradingModel.fetch(self.course.location)
+ CourseGradingModel.update_cutoffs_from_json(test_grader.course_location, test_grader.grade_cutoffs)
+ # Unlike other tests, need to actually perform a db fetch for this test since update_cutoffs_from_json
+ # simply returns the cutoffs you send into it, rather than returning the db contents.
+ altered_grader = CourseGradingModel.fetch(self.course.location)
+ self.assertDictEqual(test_grader.grade_cutoffs, altered_grader.grade_cutoffs, "Noop update")
+
+ test_grader.grade_cutoffs['D'] = 0.3
+ CourseGradingModel.update_cutoffs_from_json(test_grader.course_location, test_grader.grade_cutoffs)
+ altered_grader = CourseGradingModel.fetch(self.course.location)
+ self.assertDictEqual(test_grader.grade_cutoffs, altered_grader.grade_cutoffs, "cutoff add D")
+
+ test_grader.grade_cutoffs['Pass'] = 0.75
+ CourseGradingModel.update_cutoffs_from_json(test_grader.course_location, test_grader.grade_cutoffs)
+ altered_grader = CourseGradingModel.fetch(self.course.location)
+ self.assertDictEqual(test_grader.grade_cutoffs, altered_grader.grade_cutoffs, "cutoff change 'Pass'")
+
+ def test_delete_grace_period(self):
+ test_grader = CourseGradingModel.fetch(self.course.location)
+ CourseGradingModel.update_grace_period_from_json(test_grader.course_location, test_grader.grace_period)
+ # update_grace_period_from_json doesn't return anything, so query the db for its contents.
+ altered_grader = CourseGradingModel.fetch(self.course.location)
+ self.assertEqual(test_grader.grace_period, altered_grader.grace_period, "Noop update")
+
+ test_grader.grace_period = {'hours': 15, 'minutes': 5, 'seconds': 30}
+ CourseGradingModel.update_grace_period_from_json(test_grader.course_location, test_grader.grace_period)
+ altered_grader = CourseGradingModel.fetch(self.course.location)
+ self.assertDictEqual(test_grader.grace_period, altered_grader.grace_period, "Adding in a grace period")
+
+ test_grader.grace_period = {'hours': 1, 'minutes': 10, 'seconds': 0}
+ # Now delete the grace period
+ CourseGradingModel.delete_grace_period(test_grader.course_location)
+ # update_grace_period_from_json doesn't return anything, so query the db for its contents.
+ altered_grader = CourseGradingModel.fetch(self.course.location)
+ # Once deleted, the grace period should simply be None
+ self.assertEqual(None, altered_grader.grace_period, "Delete grace period")
+
+ def test_update_section_grader_type(self):
+ # Get the descriptor and the section_grader_type and assert they are the default values
+ descriptor = get_modulestore(self.course.location).get_item(self.course.location)
+ section_grader_type = CourseGradingModel.get_section_grader_type(self.course.location)
+
+ self.assertEqual('Not Graded', section_grader_type['graderType'])
+ self.assertEqual(None, descriptor.lms.format)
+ self.assertEqual(False, descriptor.lms.graded)
+
+ # Change the default grader type to Homework, which should also mark the section as graded
+ CourseGradingModel.update_section_grader_type(self.course.location, {'graderType': 'Homework'})
+ descriptor = get_modulestore(self.course.location).get_item(self.course.location)
+ section_grader_type = CourseGradingModel.get_section_grader_type(self.course.location)
+
+ self.assertEqual('Homework', section_grader_type['graderType'])
+ self.assertEqual('Homework', descriptor.lms.format)
+ self.assertEqual(True, descriptor.lms.graded)
+
+ # Change the grader type back to Not Graded, which should also unmark the section as graded
+ CourseGradingModel.update_section_grader_type(self.course.location, {'graderType': 'Not Graded'})
+ descriptor = get_modulestore(self.course.location).get_item(self.course.location)
+ section_grader_type = CourseGradingModel.get_section_grader_type(self.course.location)
+
+ self.assertEqual('Not Graded', section_grader_type['graderType'])
+ self.assertEqual(None, descriptor.lms.format)
+ self.assertEqual(False, descriptor.lms.graded)
+
class CourseMetadataEditingTest(CourseTestCase):
"""
@@ -352,7 +416,7 @@ class CourseMetadataEditingTest(CourseTestCase):
self.assertEqual(test_model['display_name'], 'Robot Super Course', "not expected value")
self.assertIn('rerandomize', test_model, 'Missing rerandomize metadata field')
# check for deletion effectiveness
- self.assertEqual('closed', test_model['showanswer'], 'showanswer field still in')
+ self.assertEqual('finished', test_model['showanswer'], 'showanswer field still in')
self.assertEqual(None, test_model['xqa_key'], 'xqa_key field still in')
diff --git a/cms/djangoapps/contentstore/tests/test_course_updates.py b/cms/djangoapps/contentstore/tests/test_course_updates.py
index 4f92806871..30114496c8 100644
--- a/cms/djangoapps/contentstore/tests/test_course_updates.py
+++ b/cms/djangoapps/contentstore/tests/test_course_updates.py
@@ -36,8 +36,11 @@ class CourseUpdateTest(CourseTestCase):
'provided_id': payload['id']})
content += '
div
p
'
payload['content'] = content
+ # POST requests were coming in w/ these header values causing an error; so, repro error here
resp = self.client.post(first_update_url, json.dumps(payload),
- "application/json")
+ "application/json",
+ HTTP_X_HTTP_METHOD_OVERRIDE="PUT",
+ REQUEST_METHOD="POST")
self.assertHTMLEqual(content, json.loads(resp.content)['content'],
"iframe w/ div")
diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py
index a292b7316e..88df19ec2d 100644
--- a/cms/djangoapps/contentstore/tests/test_i18n.py
+++ b/cms/djangoapps/contentstore/tests/test_i18n.py
@@ -35,7 +35,6 @@ class InternationalizationTest(ModuleStoreTestCase):
self.user.save()
self.course_data = {
- 'template': 'i4x://edx/templates/course/Empty',
'org': 'MITx',
'number': '999',
'display_name': 'Robot Super Course',
diff --git a/cms/djangoapps/contentstore/tests/test_item.py b/cms/djangoapps/contentstore/tests/test_item.py
index 4e6c951d9b..578b82b3cf 100644
--- a/cms/djangoapps/contentstore/tests/test_item.py
+++ b/cms/djangoapps/contentstore/tests/test_item.py
@@ -1,6 +1,11 @@
from contentstore.tests.test_course_settings import CourseTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from django.core.urlresolvers import reverse
+from xmodule.capa_module import CapaDescriptor
+import json
+from xmodule.modulestore.django import modulestore
+import datetime
+from pytz import UTC
class DeleteItem(CourseTestCase):
@@ -11,14 +16,228 @@ class DeleteItem(CourseTestCase):
def testDeleteStaticPage(self):
# Add static tab
- data = {
+ data = json.dumps({
'parent_location': 'i4x://mitX/333/course/Dummy_Course',
- 'template': 'i4x://edx/templates/static_tab/Empty'
- }
+ 'category': 'static_tab'
+ })
- resp = self.client.post(reverse('clone_item'), data)
+ resp = self.client.post(reverse('create_item'), data,
+ content_type="application/json")
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).
resp = self.client.post(reverse('delete_item'), resp.content, "application/json")
self.assertEqual(resp.status_code, 200)
+
+
+class TestCreateItem(CourseTestCase):
+ """
+ Test the create_item handler thoroughly
+ """
+ def response_id(self, response):
+ """
+ Get the id from the response payload
+ :param response:
+ """
+ parsed = json.loads(response.content)
+ return parsed['id']
+
+ def test_create_nicely(self):
+ """
+ Try the straightforward use cases
+ """
+ # create a chapter
+ display_name = 'Nicely created'
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps({
+ 'parent_location': self.course.location.url(),
+ 'display_name': display_name,
+ 'category': 'chapter'
+ }),
+ content_type="application/json"
+ )
+ self.assertEqual(resp.status_code, 200)
+
+ # get the new item and check its category and display_name
+ chap_location = self.response_id(resp)
+ new_obj = modulestore().get_item(chap_location)
+ self.assertEqual(new_obj.category, 'chapter')
+ self.assertEqual(new_obj.display_name, display_name)
+ self.assertEqual(new_obj.location.org, self.course.location.org)
+ self.assertEqual(new_obj.location.course, self.course.location.course)
+
+ # get the course and ensure it now points to this one
+ course = modulestore().get_item(self.course.location)
+ self.assertIn(chap_location, course.children)
+
+ # use default display name
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps({
+ 'parent_location': chap_location,
+ 'category': 'vertical'
+ }),
+ content_type="application/json"
+ )
+ self.assertEqual(resp.status_code, 200)
+
+ vert_location = self.response_id(resp)
+
+ # create problem w/ boilerplate
+ template_id = 'multiplechoice.yaml'
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps({
+ 'parent_location': vert_location,
+ 'category': 'problem',
+ 'boilerplate': template_id
+ }),
+ content_type="application/json"
+ )
+ self.assertEqual(resp.status_code, 200)
+ prob_location = self.response_id(resp)
+ problem = modulestore('draft').get_item(prob_location)
+ # ensure it's draft
+ self.assertTrue(problem.is_draft)
+ # check against the template
+ template = CapaDescriptor.get_template(template_id)
+ self.assertEqual(problem.data, template['data'])
+ self.assertEqual(problem.display_name, template['metadata']['display_name'])
+ self.assertEqual(problem.markdown, template['metadata']['markdown'])
+
+ def test_create_item_negative(self):
+ """
+ Negative tests for create_item
+ """
+ # non-existent boilerplate: creates a default
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps(
+ {'parent_location': self.course.location.url(),
+ 'category': 'problem',
+ 'boilerplate': 'nosuchboilerplate.yaml'
+ }),
+ content_type="application/json"
+ )
+ self.assertEqual(resp.status_code, 200)
+
+class TestEditItem(CourseTestCase):
+ """
+ Test contentstore.views.item.save_item
+ """
+ def response_id(self, response):
+ """
+ Get the id from the response payload
+ :param response:
+ """
+ parsed = json.loads(response.content)
+ return parsed['id']
+
+ def setUp(self):
+ """ Creates the test course structure and a couple problems to 'edit'. """
+ super(TestEditItem, self).setUp()
+ # create a chapter
+ display_name = 'chapter created'
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps(
+ {'parent_location': self.course.location.url(),
+ 'display_name': display_name,
+ 'category': 'chapter'
+ }),
+ content_type="application/json"
+ )
+ chap_location = self.response_id(resp)
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps(
+ {'parent_location': chap_location,
+ 'category': 'sequential'
+ }),
+ content_type="application/json"
+ )
+ self.seq_location = self.response_id(resp)
+ # create problem w/ boilerplate
+ template_id = 'multiplechoice.yaml'
+ resp = self.client.post(
+ reverse('create_item'),
+ json.dumps({'parent_location': self.seq_location,
+ 'category': 'problem',
+ 'boilerplate': template_id
+ }),
+ content_type="application/json"
+ )
+ self.problems = [self.response_id(resp)]
+
+ def test_delete_field(self):
+ """
+ Sending null in for a field 'deletes' it
+ """
+ self.client.post(
+ reverse('save_item'),
+ json.dumps({
+ 'id': self.problems[0],
+ 'metadata': {'rerandomize': 'onreset'}
+ }),
+ content_type="application/json"
+ )
+ problem = modulestore('draft').get_item(self.problems[0])
+ self.assertEqual(problem.rerandomize, 'onreset')
+ self.client.post(
+ reverse('save_item'),
+ json.dumps({
+ 'id': self.problems[0],
+ 'metadata': {'rerandomize': None}
+ }),
+ content_type="application/json"
+ )
+ problem = modulestore('draft').get_item(self.problems[0])
+ self.assertEqual(problem.rerandomize, 'never')
+
+
+ def test_null_field(self):
+ """
+ Sending null in for a field 'deletes' it
+ """
+ problem = modulestore('draft').get_item(self.problems[0])
+ self.assertIsNotNone(problem.markdown)
+ self.client.post(
+ reverse('save_item'),
+ json.dumps({
+ 'id': self.problems[0],
+ 'nullout': ['markdown']
+ }),
+ content_type="application/json"
+ )
+ problem = modulestore('draft').get_item(self.problems[0])
+ self.assertIsNone(problem.markdown)
+
+ def test_date_fields(self):
+ """
+ Test setting due & start dates on sequential
+ """
+ sequential = modulestore().get_item(self.seq_location)
+ self.assertIsNone(sequential.lms.due)
+ self.client.post(
+ reverse('save_item'),
+ json.dumps({
+ 'id': self.seq_location,
+ 'metadata': {'due': '2010-11-22T04:00Z'}
+ }),
+ content_type="application/json"
+ )
+ sequential = modulestore().get_item(self.seq_location)
+ self.assertEqual(sequential.lms.due, datetime.datetime(2010, 11, 22, 4, 0, tzinfo=UTC))
+ self.client.post(
+ reverse('save_item'),
+ json.dumps({
+ 'id': self.seq_location,
+ 'metadata': {'start': '2010-09-12T14:00Z'}
+ }),
+ content_type="application/json"
+ )
+ 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.start, datetime.datetime(2010, 9, 12, 14, 0, tzinfo=UTC))
+
diff --git a/cms/djangoapps/contentstore/tests/test_textbooks.py b/cms/djangoapps/contentstore/tests/test_textbooks.py
index 02c64e9413..a21a1b1023 100644
--- a/cms/djangoapps/contentstore/tests/test_textbooks.py
+++ b/cms/djangoapps/contentstore/tests/test_textbooks.py
@@ -62,6 +62,9 @@ class TextbookIndexTestCase(CourseTestCase):
}
]
self.course.pdf_textbooks = content
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ self.course.save()
store = get_modulestore(self.course.location)
store.update_metadata(self.course.location, own_metadata(self.course))
@@ -220,6 +223,9 @@ class TextbookByIdTestCase(CourseTestCase):
'tid': 2,
})
self.course.pdf_textbooks = [self.textbook1, self.textbook2]
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ self.course.save()
self.store = get_modulestore(self.course.location)
self.store.update_metadata(self.course.location, own_metadata(self.course))
self.url_nonexist = reverse('textbook_by_id', kwargs={
diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py
index bc9e9e8bae..a3f211a703 100644
--- a/cms/djangoapps/contentstore/tests/utils.py
+++ b/cms/djangoapps/contentstore/tests/utils.py
@@ -54,7 +54,6 @@ class CourseTestCase(ModuleStoreTestCase):
self.client.login(username=uname, password=password)
self.course = CourseFactory.create(
- template='i4x://edx/templates/course/Empty',
org='MITx',
number='999',
display_name='Robot Super Course',
diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py
index 5fa0d949b0..4973bddaca 100644
--- a/cms/djangoapps/contentstore/utils.py
+++ b/cms/djangoapps/contentstore/utils.py
@@ -19,14 +19,14 @@ NOTES_PANEL = {"name": _("My Notes"), "type": "notes"}
EXTRA_TAB_PANELS = dict([(p['type'], p) for p in [OPEN_ENDED_PANEL, NOTES_PANEL]])
-def get_modulestore(location):
+def get_modulestore(category_or_location):
"""
Returns the correct modulestore to use for modifying the specified location
"""
- if not isinstance(location, Location):
- location = Location(location)
+ if isinstance(category_or_location, Location):
+ category_or_location = category_or_location.category
- if location.category in DIRECT_ONLY_CATEGORIES:
+ if category_or_location in DIRECT_ONLY_CATEGORIES:
return modulestore('direct')
else:
return modulestore()
diff --git a/cms/djangoapps/contentstore/views/assets.py b/cms/djangoapps/contentstore/views/assets.py
index d0b202da19..0bb9551ac9 100644
--- a/cms/djangoapps/contentstore/views/assets.py
+++ b/cms/djangoapps/contentstore/views/assets.py
@@ -13,7 +13,7 @@ from django_future.csrf import ensure_csrf_cookie
from django.core.urlresolvers import reverse
from django.core.servers.basehttp import FileWrapper
from django.core.files.temp import NamedTemporaryFile
-from django.views.decorators.http import require_POST
+from django.views.decorators.http import require_POST, require_http_methods
from mitxmako.shortcuts import render_to_response
from cache_toolbox.core import del_cached_content
@@ -249,6 +249,7 @@ def remove_asset(request, org, course, name):
@ensure_csrf_cookie
+@require_http_methods(("GET", "POST", "PUT"))
@login_required
def import_course(request, org, course, name):
"""
@@ -256,7 +257,7 @@ def import_course(request, org, course, name):
"""
location = get_location_and_verify_access(request, org, course, name)
- if request.method == 'POST':
+ if request.method in ('POST', 'PUT'):
filename = request.FILES['course-data'].name
if not filename.endswith('.tar.gz'):
diff --git a/cms/djangoapps/contentstore/views/checklist.py b/cms/djangoapps/contentstore/views/checklist.py
index fa0a7b7b62..fdb5857ba7 100644
--- a/cms/djangoapps/contentstore/views/checklist.py
+++ b/cms/djangoapps/contentstore/views/checklist.py
@@ -7,11 +7,11 @@ from django.views.decorators.http import require_http_methods
from django_future.csrf import ensure_csrf_cookie
from mitxmako.shortcuts import render_to_response
-from xmodule.modulestore import Location
from xmodule.modulestore.inheritance import own_metadata
from ..utils import get_modulestore, get_url_reverse
from .access import get_location_and_verify_access
+from xmodule.course_module import CourseDescriptor
__all__ = ['get_checklists', 'update_checklist']
@@ -28,13 +28,11 @@ def get_checklists(request, org, course, name):
modulestore = get_modulestore(location)
course_module = modulestore.get_item(location)
- new_course_template = Location('i4x', 'edx', 'templates', 'course', 'Empty')
- template_module = modulestore.get_item(new_course_template)
# If course was created before checklists were introduced, copy them over from the template.
copied = False
if not course_module.checklists:
- course_module.checklists = template_module.checklists
+ course_module.checklists = CourseDescriptor.checklists.default
copied = True
checklists, modified = expand_checklist_action_urls(course_module)
diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py
index 30958d5866..1be6ac2822 100644
--- a/cms/djangoapps/contentstore/views/component.py
+++ b/cms/djangoapps/contentstore/views/component.py
@@ -26,6 +26,8 @@ from models.settings.course_grading import CourseGradingModel
from .requests import _xmodule_recurse
from .access import has_access
+from xmodule.x_module import XModuleDescriptor
+from xblock.plugin import PluginMissingError
__all__ = ['OPEN_ENDED_COMPONENT_TYPES',
'ADVANCED_COMPONENT_POLICY_KEY',
@@ -101,7 +103,7 @@ def edit_subsection(request, location):
return render_to_response('edit_subsection.html',
{'subsection': item,
'context_course': course,
- 'create_new_unit_template': Location('i4x', 'edx', 'templates', 'vertical', 'Empty'),
+ 'new_unit_category': 'vertical',
'lms_link': lms_link,
'preview_link': preview_link,
'course_graders': json.dumps(CourseGradingModel.fetch(course.location).graders),
@@ -134,10 +136,26 @@ def edit_unit(request, location):
item = modulestore().get_item(location, depth=1)
except ItemNotFoundError:
return HttpResponseBadRequest()
-
lms_link = get_lms_link_for_item(item.location, course_id=course.location.course_id)
component_templates = defaultdict(list)
+ for category in COMPONENT_TYPES:
+ component_class = XModuleDescriptor.load_class(category)
+ # add the default template
+ component_templates[category].append((
+ component_class.display_name.default or 'Blank',
+ category,
+ False, # No defaults have markdown (hardcoded current default)
+ None # no boilerplate for overrides
+ ))
+ # add boilerplates
+ for template in component_class.templates():
+ component_templates[category].append((
+ template['metadata'].get('display_name'),
+ category,
+ template['metadata'].get('markdown') is not None,
+ template.get('template_id')
+ ))
# Check if there are any advanced modules specified in the course policy. These modules
# should be specified as a list of strings, where the strings are the names of the modules
@@ -145,29 +163,29 @@ def edit_unit(request, location):
course_advanced_keys = course.advanced_modules
# Set component types according to course policy file
- component_types = list(COMPONENT_TYPES)
if isinstance(course_advanced_keys, list):
- course_advanced_keys = [c for c in course_advanced_keys if c in ADVANCED_COMPONENT_TYPES]
- if len(course_advanced_keys) > 0:
- component_types.append(ADVANCED_COMPONENT_CATEGORY)
+ for category in course_advanced_keys:
+ if category in ADVANCED_COMPONENT_TYPES:
+ # Do I need to allow for boilerplates or just defaults on the class? i.e., can an advanced
+ # have more than one entry in the menu? one for default and others for prefilled boilerplates?
+ try:
+ component_class = XModuleDescriptor.load_class(category)
+
+ component_templates['advanced'].append((
+ component_class.display_name.default or category,
+ category,
+ False,
+ None # don't override default data
+ ))
+ except PluginMissingError:
+ # dhm: I got this once but it can happen any time the course author configures
+ # an advanced component which does not exist on the server. This code here merely
+ # prevents any authors from trying to instantiate the non-existent component type
+ # by not showing it in the menu
+ pass
else:
log.error("Improper format for course advanced keys! {0}".format(course_advanced_keys))
- templates = modulestore().get_items(Location('i4x', 'edx', 'templates'))
- for template in templates:
- category = template.location.category
-
- if category in course_advanced_keys:
- category = ADVANCED_COMPONENT_CATEGORY
-
- if category in component_types:
- # This is a hack to create categories for different xmodules
- component_templates[category].append((
- template.display_name_with_default,
- template.location.url(),
- hasattr(template, 'markdown') and template.markdown is not None
- ))
-
components = [
component.location.url()
for component
@@ -219,7 +237,7 @@ def edit_unit(request, location):
'subsection': containing_subsection,
'release_date': get_default_time_display(containing_subsection.lms.start) if containing_subsection.lms.start is not None else None,
'section': containing_section,
- 'create_new_unit_template': Location('i4x', 'edx', 'templates', 'vertical', 'Empty'),
+ 'new_unit_category': 'vertical',
'unit_state': unit_state,
'published_date': get_default_time_display(item.cms.published_date) if item.cms.published_date is not None else None
})
@@ -227,6 +245,7 @@ def edit_unit(request, location):
@expect_json
@login_required
+@require_http_methods(("GET", "POST", "PUT"))
@ensure_csrf_cookie
def assignment_type_update(request, org, course, category, name):
'''
@@ -238,7 +257,7 @@ def assignment_type_update(request, org, course, category, name):
if request.method == 'GET':
return JsonResponse(CourseGradingModel.get_section_grader_type(location))
- elif request.method == 'POST': # post or put, doesn't matter.
+ elif request.method in ('POST', 'PUT'): # post or put, doesn't matter.
return JsonResponse(CourseGradingModel.update_section_grader_type(location, request.POST))
@@ -253,7 +272,7 @@ def create_draft(request):
# This clones the existing item location to a draft location (the draft is implicit,
# because modulestore is a Draft modulestore)
- modulestore().clone_item(location, location)
+ modulestore().convert_to_draft(location)
return HttpResponse()
diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py
index f8de053d95..02eb4c65b8 100644
--- a/cms/djangoapps/contentstore/views/course.py
+++ b/cms/djangoapps/contentstore/views/course.py
@@ -1,10 +1,9 @@
"""
Views related to operations on course objects
"""
-#pylint: disable=W0402
import json
import random
-import string
+import string # pylint: disable=W0402
from django.contrib.auth.decorators import login_required
from django_future.csrf import ensure_csrf_cookie
@@ -43,8 +42,8 @@ from .component import (
ADVANCED_COMPONENT_POLICY_KEY)
from django_comment_common.utils import seed_permissions_roles
-import datetime
-from django.utils.timezone import UTC
+
+from xmodule.html_module import AboutDescriptor
__all__ = ['course_index', 'create_new_course', 'course_info',
'course_info_updates', 'get_course_settings',
'course_config_graders_page',
@@ -82,10 +81,11 @@ def course_index(request, org, course, name):
'sections': sections,
'course_graders': json.dumps(CourseGradingModel.fetch(course.location).graders),
'parent_location': course.location,
- 'new_section_template': Location('i4x', 'edx', 'templates', 'chapter', 'Empty'),
- 'new_subsection_template': Location('i4x', 'edx', 'templates', 'sequential', 'Empty'), # for now they are the same, but the could be different at some point...
+ 'new_section_category': 'chapter',
+ 'new_subsection_category': 'sequential',
'upload_asset_callback_url': upload_asset_callback_url,
- 'create_new_unit_template': Location('i4x', 'edx', 'templates', 'vertical', 'Empty')
+ 'new_unit_category': 'vertical',
+ 'category': 'vertical'
})
@@ -98,12 +98,6 @@ def create_new_course(request):
if not is_user_in_creator_group(request.user):
raise PermissionDenied()
- # This logic is repeated in xmodule/modulestore/tests/factories.py
- # so if you change anything here, you need to also change it there.
- # TODO: write a test that creates two courses, one with the factory and
- # the other with this method, then compare them to make sure they are
- # equivalent.
- template = Location(request.POST['template'])
org = request.POST.get('org')
number = request.POST.get('number')
display_name = request.POST.get('display_name')
@@ -121,29 +115,31 @@ def create_new_course(request):
existing_course = modulestore('direct').get_item(dest_location)
except ItemNotFoundError:
pass
-
if existing_course is not None:
return JsonResponse({'ErrMsg': 'There is already a course defined with this name.'})
course_search_location = ['i4x', dest_location.org, dest_location.course, 'course', None]
courses = modulestore().get_items(course_search_location)
-
if len(courses) > 0:
return JsonResponse({'ErrMsg': 'There is already a course defined with the same organization and course number.'})
- new_course = modulestore('direct').clone_item(template, dest_location)
+ # instantiate the CourseDescriptor and then persist it
+ # note: no system to pass
+ if display_name is None:
+ metadata = {}
+ else:
+ metadata = {'display_name': display_name}
+ modulestore('direct').create_and_save_xmodule(dest_location, metadata=metadata)
+ new_course = modulestore('direct').get_item(dest_location)
- # clone a default 'about' module as well
-
- about_template_location = Location(['i4x', 'edx', 'templates', 'about', 'overview'])
- dest_about_location = dest_location._replace(category='about', name='overview')
- modulestore('direct').clone_item(about_template_location, dest_about_location)
-
- if display_name is not None:
- new_course.display_name = display_name
-
- # set a default start date to now
- new_course.start = datetime.datetime.now(UTC())
+ # clone a default 'about' overview module as well
+ dest_about_location = dest_location.replace(category='about', name='overview')
+ overview_template = AboutDescriptor.get_template('overview.yaml')
+ modulestore('direct').create_and_save_xmodule(
+ dest_about_location,
+ system=new_course.system,
+ definition_data=overview_template.get('data')
+ )
initialize_course_tabs(new_course)
@@ -179,6 +175,7 @@ def course_info(request, org, course, name, provided_id=None):
@expect_json
+@require_http_methods(("GET", "POST", "PUT", "DELETE"))
@login_required
@ensure_csrf_cookie
def course_info_updates(request, org, course, provided_id=None):
@@ -209,7 +206,7 @@ def course_info_updates(request, org, course, provided_id=None):
except:
return HttpResponseBadRequest("Failed to delete",
content_type="text/plain")
- elif request.method == 'POST':
+ elif request.method in ('POST', 'PUT'): # can be either and sometimes django is rewriting one to the other
try:
return JsonResponse(update_course_updates(location, request.POST, provided_id))
except:
@@ -303,7 +300,7 @@ def course_settings_updates(request, org, course, name, section):
if request.method == 'GET':
# Cannot just do a get w/o knowing the course name :-(
return JsonResponse(manager.fetch(Location(['i4x', org, course, 'course', name])), encoder=CourseSettingsEncoder)
- elif request.method == 'POST': # post or put, doesn't matter.
+ elif request.method in ('POST', 'PUT'): # post or put, doesn't matter.
return JsonResponse(manager.update_from_json(request.POST), encoder=CourseSettingsEncoder)
@@ -482,7 +479,7 @@ def textbook_index(request, org, course, name):
if request.is_ajax():
if request.method == 'GET':
return JsonResponse(course_module.pdf_textbooks)
- elif request.method == 'POST':
+ elif request.method in ('POST', 'PUT'): # can be either and sometimes django is rewriting one to the other
try:
textbooks = validate_textbooks_json(request.body)
except TextbookValidationError as err:
@@ -498,6 +495,9 @@ def textbook_index(request, org, course, name):
if not any(tab['type'] == 'pdf_textbooks' for tab in course_module.tabs):
course_module.tabs.append({"type": "pdf_textbooks"})
course_module.pdf_textbooks = textbooks
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ course_module.save()
store.update_metadata(course_module.location, own_metadata(course_module))
return JsonResponse(course_module.pdf_textbooks)
else:
@@ -544,6 +544,9 @@ def create_textbook(request, org, course, name):
tabs = course_module.tabs
tabs.append({"type": "pdf_textbooks"})
course_module.tabs = tabs
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ course_module.save()
store.update_metadata(course_module.location, own_metadata(course_module))
resp = JsonResponse(textbook, status=201)
resp["Location"] = reverse("textbook_by_id", kwargs={
@@ -577,7 +580,7 @@ def textbook_by_id(request, org, course, name, tid):
if not textbook:
return JsonResponse(status=404)
return JsonResponse(textbook)
- elif request.method in ('POST', 'PUT'):
+ elif request.method in ('POST', 'PUT'): # can be either and sometimes django is rewriting one to the other
try:
new_textbook = validate_textbook_json(request.body)
except TextbookValidationError as err:
@@ -587,10 +590,13 @@ def textbook_by_id(request, org, course, name, tid):
i = course_module.pdf_textbooks.index(textbook)
new_textbooks = course_module.pdf_textbooks[0:i]
new_textbooks.append(new_textbook)
- new_textbooks.extend(course_module.pdf_textbooks[i+1:])
+ new_textbooks.extend(course_module.pdf_textbooks[i + 1:])
course_module.pdf_textbooks = new_textbooks
else:
course_module.pdf_textbooks.append(new_textbook)
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ course_module.save()
store.update_metadata(course_module.location, own_metadata(course_module))
return JsonResponse(new_textbook, status=201)
elif request.method == 'DELETE':
@@ -598,7 +604,8 @@ def textbook_by_id(request, org, course, name, tid):
return JsonResponse(status=404)
i = course_module.pdf_textbooks.index(textbook)
new_textbooks = course_module.pdf_textbooks[0:i]
- new_textbooks.extend(course_module.pdf_textbooks[i+1:])
+ new_textbooks.extend(course_module.pdf_textbooks[i + 1:])
course_module.pdf_textbooks = new_textbooks
+ course_module.save()
store.update_metadata(course_module.location, own_metadata(course_module))
return JsonResponse()
diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py
index abc5f48564..efebded9b9 100644
--- a/cms/djangoapps/contentstore/views/item.py
+++ b/cms/djangoapps/contentstore/views/item.py
@@ -13,16 +13,26 @@ from util.json_request import expect_json
from ..utils import get_modulestore
from .access import has_access
from .requests import _xmodule_recurse
+from xmodule.x_module import XModuleDescriptor
-__all__ = ['save_item', 'clone_item', 'delete_item']
+__all__ = ['save_item', 'create_item', 'delete_item']
# cdodge: these are categories which should not be parented, they are detached from the hierarchy
DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info']
-
@login_required
@expect_json
def save_item(request):
+ """
+ Will carry a json payload with these possible fields
+ :id (required): the id
+ :data (optional): the new value for the data
+ :metadata (optional): new values for the metadata fields.
+ Any whose values are None will be deleted not set to None! Absent ones will be left alone
+ :nullout (optional): which metadata fields to set to None
+ """
+ # The nullout is a bit of a temporary copout until we can make module_edit.coffee and the metadata editors a
+ # little smarter and able to pass something more akin to {unset: [field, field]}
item_location = request.POST['id']
# check permissions for this user within this course
@@ -42,59 +52,98 @@ def save_item(request):
children = request.POST['children']
store.update_children(item_location, children)
- # cdodge: also commit any metadata which might have been passed along in the
- # POST from the client, if it is there
- # NOTE, that the postback is not the complete metadata, as there's system metadata which is
- # not presented to the end-user for editing. So let's fetch the original and
- # 'apply' the submitted metadata, so we don't end up deleting system metadata
- if request.POST.get('metadata') is not None:
- posted_metadata = request.POST['metadata']
- # fetch original
+ # cdodge: also commit any metadata which might have been passed along
+ if request.POST.get('nullout') is not None or request.POST.get('metadata') is not None:
+ # the postback is not the complete metadata, as there's system metadata which is
+ # not presented to the end-user for editing. So let's fetch the original and
+ # 'apply' the submitted metadata, so we don't end up deleting system metadata
existing_item = modulestore().get_item(item_location)
+ for metadata_key in request.POST.get('nullout', []):
+ # [dhm] see comment on _get_xblock_field
+ _get_xblock_field(existing_item, metadata_key).write_to(existing_item, None)
# update existing metadata with submitted metadata (which can be partial)
- # IMPORTANT NOTE: if the client passed pack 'null' (None) for a piece of metadata that means 'remove it'
- for metadata_key, value in posted_metadata.items():
+ # IMPORTANT NOTE: if the client passed 'null' (None) for a piece of metadata that means 'remove it'. If
+ # the intent is to make it None, use the nullout field
+ for metadata_key, value in request.POST.get('metadata', {}).items():
+ # [dhm] see comment on _get_xblock_field
+ field = _get_xblock_field(existing_item, metadata_key)
- if posted_metadata[metadata_key] is None:
- # remove both from passed in collection as well as the collection read in from the modulestore
- if metadata_key in existing_item._model_data:
- del existing_item._model_data[metadata_key]
- del posted_metadata[metadata_key]
+ if value is None:
+ field.delete_from(existing_item)
else:
- existing_item._model_data[metadata_key] = value
-
+ value = field.from_json(value)
+ field.write_to(existing_item, value)
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ existing_item.save()
# commit to datastore
- # TODO (cpennington): This really shouldn't have to do this much reaching in to get the metadata
store.update_metadata(item_location, own_metadata(existing_item))
return HttpResponse()
+# [DHM] A hack until we implement a permanent soln. Proposed perm solution is to make namespace fields also top level
+# fields in xblocks rather than requiring dereference through namespace but we'll need to consider whether there are
+# plausible use cases for distinct fields w/ same name in different namespaces on the same blocks.
+# The idea is that consumers of the xblock, and particularly the web client, shouldn't know about our internal
+# representation (namespaces as means of decorating all modules).
+# Given top-level access, the calls can simply be setattr(existing_item, field, value) ...
+# Really, this method should be elsewhere (e.g., xblock). We also need methods for has_value (v is_default)...
+def _get_xblock_field(xblock, field_name):
+ """
+ A temporary function to get the xblock field either from the xblock or one of its namespaces by name.
+ :param xblock:
+ :param field_name:
+ """
+ def find_field(fields):
+ for field in fields:
+ if field.name == field_name:
+ return field
+
+ found = find_field(xblock.fields)
+ if found:
+ return found
+ for namespace in xblock.namespaces:
+ found = find_field(getattr(xblock, namespace).fields)
+ if found:
+ return found
+
+
@login_required
@expect_json
-def clone_item(request):
+def create_item(request):
parent_location = Location(request.POST['parent_location'])
- template = Location(request.POST['template'])
+ category = request.POST['category']
display_name = request.POST.get('display_name')
if not has_access(request.user, parent_location):
raise PermissionDenied()
- parent = get_modulestore(template).get_item(parent_location)
- dest_location = parent_location._replace(category=template.category, name=uuid4().hex)
+ parent = get_modulestore(category).get_item(parent_location)
+ dest_location = parent_location.replace(category=category, name=uuid4().hex)
- new_item = get_modulestore(template).clone_item(template, dest_location)
+ # get the metadata, display_name, and definition from the request
+ metadata = {}
+ data = None
+ template_id = request.POST.get('boilerplate')
+ if template_id is not None:
+ clz = XModuleDescriptor.load_class(category)
+ if clz is not None:
+ template = clz.get_template(template_id)
+ if template is not None:
+ metadata = template.get('metadata', {})
+ data = template.get('data')
- # replace the display name with an optional parameter passed in from the caller
if display_name is not None:
- new_item.display_name = display_name
+ metadata['display_name'] = display_name
- get_modulestore(template).update_metadata(new_item.location.url(), own_metadata(new_item))
+ get_modulestore(category).create_and_save_xmodule(dest_location, definition_data=data,
+ metadata=metadata, system=parent.system)
- if new_item.location.category not in DETACHED_CATEGORIES:
- get_modulestore(parent.location).update_children(parent_location, parent.children + [new_item.location.url()])
+ if category not in DETACHED_CATEGORIES:
+ get_modulestore(parent.location).update_children(parent_location, parent.children + [dest_location.url()])
return HttpResponse(json.dumps({'id': dest_location.url()}))
diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py
index ba393e72f4..35af3e9ac3 100644
--- a/cms/djangoapps/contentstore/views/preview.py
+++ b/cms/djangoapps/contentstore/views/preview.py
@@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from mitxmako.shortcuts import render_to_response
-from xmodule_modifiers import replace_static_urls, wrap_xmodule
+from xmodule_modifiers import replace_static_urls, wrap_xmodule, save_module # pylint: disable=F0401
from xmodule.error_module import ErrorDescriptor
from xmodule.errortracker import exc_info_to_str
from xmodule.exceptions import NotFoundError, ProcessingError
@@ -47,6 +47,8 @@ def preview_dispatch(request, preview_id, location, dispatch=None):
# Let the module handle the AJAX
try:
ajax_return = instance.handle_ajax(dispatch, request.POST)
+ # Save any module data that has changed to the underlying KeyValueStore
+ instance.save()
except NotFoundError:
log.exception("Module indicating to user that request doesn't exist")
@@ -166,6 +168,11 @@ def load_preview_module(request, preview_id, descriptor):
course_namespace=Location([module.location.tag, module.location.org, module.location.course, None, None])
)
+ module.get_html = save_module(
+ module.get_html,
+ module
+ )
+
return module
diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py
index 154f9fb55d..d55932e33d 100644
--- a/cms/djangoapps/contentstore/views/tabs.py
+++ b/cms/djangoapps/contentstore/views/tabs.py
@@ -76,6 +76,9 @@ def reorder_static_tabs(request):
# OK, re-assemble the static tabs in the new order
course.tabs = reordered_tabs
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ course.save()
modulestore('direct').update_metadata(course.location, own_metadata(course))
return HttpResponse()
diff --git a/cms/djangoapps/contentstore/views/user.py b/cms/djangoapps/contentstore/views/user.py
index 948ed614d2..ee6b0bf84d 100644
--- a/cms/djangoapps/contentstore/views/user.py
+++ b/cms/djangoapps/contentstore/views/user.py
@@ -27,6 +27,7 @@ def index(request):
# filter out courses that we don't have access too
def course_filter(course):
return (has_access(request.user, course.location)
+ # TODO remove this condition when templates purged from db
and course.location.course != 'templates'
and course.location.org != ''
and course.location.course != ''
@@ -34,7 +35,6 @@ def index(request):
courses = filter(course_filter, courses)
return render_to_response('index.html', {
- 'new_course_template': Location('i4x', 'edx', 'templates', 'course', 'Empty'),
'courses': [(course.display_name,
get_url_reverse('CourseOutline', course),
get_lms_link_for_item(course.location, course_id=course.location.course_id))
diff --git a/cms/djangoapps/models/settings/course_details.py b/cms/djangoapps/models/settings/course_details.py
index 8ce8c2db34..7c3b883283 100644
--- a/cms/djangoapps/models/settings/course_details.py
+++ b/cms/djangoapps/models/settings/course_details.py
@@ -122,6 +122,10 @@ class CourseDetails(object):
descriptor.enrollment_end = converted
if dirty:
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
+
get_modulestore(course_location).update_metadata(course_location, own_metadata(descriptor))
# NOTE: below auto writes to the db w/o verifying that any of the fields actually changed
diff --git a/cms/djangoapps/models/settings/course_grading.py b/cms/djangoapps/models/settings/course_grading.py
index 4ea9f2f5db..0746fc7a90 100644
--- a/cms/djangoapps/models/settings/course_grading.py
+++ b/cms/djangoapps/models/settings/course_grading.py
@@ -7,9 +7,12 @@ class CourseGradingModel(object):
"""
Basically a DAO and Model combo for CRUD operations pertaining to grading policy.
"""
+ # Within this class, allow access to protected members of client classes.
+ # This comes up when accessing kvs data and caches during kvs saves and modulestore writes.
+ # pylint: disable=W0212
def __init__(self, course_descriptor):
self.course_location = course_descriptor.location
- self.graders = [CourseGradingModel.jsonize_grader(i, grader) for i, grader in enumerate(course_descriptor.raw_grader)] # weights transformed to ints [0..100]
+ self.graders = [CourseGradingModel.jsonize_grader(i, grader) for i, grader in enumerate(course_descriptor.raw_grader)] # weights transformed to ints [0..100]
self.grade_cutoffs = course_descriptor.grade_cutoffs
self.grace_period = CourseGradingModel.convert_set_grace_period(course_descriptor)
@@ -81,15 +84,18 @@ class CourseGradingModel(object):
Decode the json into CourseGradingModel and save any changes. Returns the modified model.
Probably not the usual path for updates as it's too coarse grained.
"""
- course_location = jsondict['course_location']
+ course_location = Location(jsondict['course_location'])
descriptor = get_modulestore(course_location).get_item(course_location)
-
graders_parsed = [CourseGradingModel.parse_grader(jsonele) for jsonele in jsondict['graders']]
descriptor.raw_grader = graders_parsed
descriptor.grade_cutoffs = jsondict['grade_cutoffs']
- get_modulestore(course_location).update_item(course_location, descriptor._model_data._kvs._data)
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
+ get_modulestore(course_location).update_item(course_location, descriptor.xblock_kvs._data)
+
CourseGradingModel.update_grace_period_from_json(course_location, jsondict['grace_period'])
return CourseGradingModel.fetch(course_location)
@@ -116,6 +122,9 @@ class CourseGradingModel(object):
else:
descriptor.raw_grader.append(grader)
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(course_location).update_item(course_location, descriptor._model_data._kvs._data)
return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index])
@@ -131,6 +140,10 @@ class CourseGradingModel(object):
descriptor = get_modulestore(course_location).get_item(course_location)
descriptor.grade_cutoffs = cutoffs
+
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(course_location).update_item(course_location, descriptor._model_data._kvs._data)
return cutoffs
@@ -156,6 +169,10 @@ class CourseGradingModel(object):
descriptor = get_modulestore(course_location).get_item(course_location)
descriptor.lms.graceperiod = grace_timedelta
+
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(course_location).update_metadata(course_location, descriptor._model_data._kvs._metadata)
@staticmethod
@@ -172,23 +189,12 @@ class CourseGradingModel(object):
del descriptor.raw_grader[index]
# force propagation to definition
descriptor.raw_grader = descriptor.raw_grader
+
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(course_location).update_item(course_location, descriptor._model_data._kvs._data)
- # NOTE cannot delete cutoffs. May be useful to reset
- @staticmethod
- def delete_cutoffs(course_location, cutoffs):
- """
- Resets the cutoffs to the defaults
- """
- if not isinstance(course_location, Location):
- course_location = Location(course_location)
-
- descriptor = get_modulestore(course_location).get_item(course_location)
- descriptor.grade_cutoffs = descriptor.defaut_grading_policy['GRADE_CUTOFFS']
- get_modulestore(course_location).update_item(course_location, descriptor._model_data._kvs._data)
-
- return descriptor.grade_cutoffs
-
@staticmethod
def delete_grace_period(course_location):
"""
@@ -199,6 +205,10 @@ class CourseGradingModel(object):
descriptor = get_modulestore(course_location).get_item(course_location)
del descriptor.lms.graceperiod
+
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(course_location).update_metadata(course_location, descriptor._model_data._kvs._metadata)
@staticmethod
@@ -209,7 +219,7 @@ class CourseGradingModel(object):
descriptor = get_modulestore(location).get_item(location)
return {"graderType": descriptor.lms.format if descriptor.lms.format is not None else 'Not Graded',
"location": location,
- "id": 99 # just an arbitrary value to
+ "id": 99 # just an arbitrary value to
}
@staticmethod
@@ -225,6 +235,9 @@ class CourseGradingModel(object):
del descriptor.lms.format
del descriptor.lms.graded
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(location).update_metadata(location, descriptor._model_data._kvs._metadata)
@staticmethod
@@ -232,7 +245,7 @@ class CourseGradingModel(object):
# 5 hours 59 minutes 59 seconds => converted to iso format
rawgrace = descriptor.lms.graceperiod
if rawgrace:
- hours_from_days = rawgrace.days*24
+ hours_from_days = rawgrace.days * 24
seconds = rawgrace.seconds
hours_from_seconds = int(seconds / 3600)
hours = hours_from_days + hours_from_seconds
diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py
index 5fb07fe806..8d9a292867 100644
--- a/cms/djangoapps/models/settings/course_metadata.py
+++ b/cms/djangoapps/models/settings/course_metadata.py
@@ -76,6 +76,9 @@ class CourseMetadata(object):
setattr(descriptor.lms, key, value)
if dirty:
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
get_modulestore(course_location).update_metadata(course_location,
own_metadata(descriptor))
@@ -97,6 +100,10 @@ class CourseMetadata(object):
elif hasattr(descriptor.lms, key):
delattr(descriptor.lms, key)
+ # Save the data that we've just changed to the underlying
+ # MongoKeyValueStore before we update the mongo datastore.
+ descriptor.save()
+
get_modulestore(course_location).update_metadata(course_location,
own_metadata(descriptor))
diff --git a/cms/static/coffee/src/views/module_edit.coffee b/cms/static/coffee/src/views/module_edit.coffee
index 5154591d6f..62083fa26d 100644
--- a/cms/static/coffee/src/views/module_edit.coffee
+++ b/cms/static/coffee/src/views/module_edit.coffee
@@ -56,14 +56,15 @@ class CMS.Views.ModuleEdit extends Backbone.View
changedMetadata: ->
return _.extend(@metadataEditor.getModifiedMetadataValues(), @customMetadata())
- cloneTemplate: (parent, template) ->
- $.post("/clone_item", {
- parent_location: parent
- template: template
- }, (data) =>
- @model.set(id: data.id)
- @$el.data('id', data.id)
- @render()
+ createItem: (parent, payload) ->
+ payload.parent_location = parent
+ $.post(
+ "/create_item"
+ payload
+ (data) =>
+ @model.set(id: data.id)
+ @$el.data('id', data.id)
+ @render()
)
render: ->
diff --git a/cms/static/coffee/src/views/tabs.coffee b/cms/static/coffee/src/views/tabs.coffee
index 1034fc988e..58f52f27a3 100644
--- a/cms/static/coffee/src/views/tabs.coffee
+++ b/cms/static/coffee/src/views/tabs.coffee
@@ -55,9 +55,9 @@ class CMS.Views.TabsEdit extends Backbone.View
editor.$el.removeClass('new')
, 500)
- editor.cloneTemplate(
+ editor.createItem(
@model.get('id'),
- 'i4x://edx/templates/static_tab/Empty'
+ {category: 'static_tab'}
)
analytics.track "Added Static Page",
diff --git a/cms/static/coffee/src/views/unit.coffee b/cms/static/coffee/src/views/unit.coffee
index 058bcf0ce1..774ef04f6d 100644
--- a/cms/static/coffee/src/views/unit.coffee
+++ b/cms/static/coffee/src/views/unit.coffee
@@ -89,9 +89,9 @@ class CMS.Views.UnitEdit extends Backbone.View
@$newComponentItem.before(editor.$el)
- editor.cloneTemplate(
+ editor.createItem(
@$el.data('id'),
- $(event.currentTarget).data('location')
+ $(event.currentTarget).data()
)
analytics.track "Added a Component",
diff --git a/cms/static/js/base.js b/cms/static/js/base.js
index b53d116808..329624ef46 100644
--- a/cms/static/js/base.js
+++ b/cms/static/js/base.js
@@ -253,17 +253,13 @@ function syncReleaseDate(e) {
}
function getEdxTimeFromDateTimeVals(date_val, time_val) {
- var edxTimeStr = null;
-
if (date_val != '') {
if (time_val == '') time_val = '00:00';
- // Note, we are using date.js utility which has better parsing abilities than the built in JS date parsing
- var date = Date.parse(date_val + " " + time_val);
- edxTimeStr = date.toString('yyyy-MM-ddTHH:mm');
+ return new Date(date_val + " " + time_val + "Z");
}
- return edxTimeStr;
+ else return null;
}
function getEdxTimeFromDateTimeInputs(date_id, time_id) {
@@ -338,7 +334,7 @@ function createNewUnit(e) {
e.preventDefault();
var parent = $(this).data('parent');
- var template = $(this).data('template');
+ var category = $(this).data('category');
analytics.track('Created a Unit', {
'course': course_location_analytics,
@@ -346,9 +342,9 @@ function createNewUnit(e) {
});
- $.post('/clone_item', {
+ $.post('/create_item', {
'parent_location': parent,
- 'template': template,
+ 'category': category,
'display_name': 'New Unit'
},
@@ -551,7 +547,7 @@ function saveNewSection(e) {
var $saveButton = $(this).find('.new-section-name-save');
var parent = $saveButton.data('parent');
- var template = $saveButton.data('template');
+ var category = $saveButton.data('category');
var display_name = $(this).find('.new-section-name').val();
analytics.track('Created a Section', {
@@ -559,9 +555,9 @@ function saveNewSection(e) {
'display_name': display_name
});
- $.post('/clone_item', {
+ $.post('/create_item', {
'parent_location': parent,
- 'template': template,
+ 'category': category,
'display_name': display_name,
},
@@ -595,7 +591,6 @@ function saveNewCourse(e) {
e.preventDefault();
var $newCourse = $(this).closest('.new-course');
- var template = $(this).find('.new-course-save').data('template');
var org = $newCourse.find('.new-course-org').val();
var number = $newCourse.find('.new-course-number').val();
var display_name = $newCourse.find('.new-course-name').val();
@@ -612,7 +607,6 @@ function saveNewCourse(e) {
});
$.post('/create_new_course', {
- 'template': template,
'org': org,
'number': number,
'display_name': display_name
@@ -646,7 +640,7 @@ function addNewSubsection(e) {
var parent = $(this).parents("section.branch").data("id");
$saveButton.data('parent', parent);
- $saveButton.data('template', $(this).data('template'));
+ $saveButton.data('category', $(this).data('category'));
$newSubsection.find('.new-subsection-form').bind('submit', saveNewSubsection);
$cancelButton.bind('click', cancelNewSubsection);
@@ -659,7 +653,7 @@ function saveNewSubsection(e) {
e.preventDefault();
var parent = $(this).find('.new-subsection-name-save').data('parent');
- var template = $(this).find('.new-subsection-name-save').data('template');
+ var category = $(this).find('.new-subsection-name-save').data('category');
var display_name = $(this).find('.new-subsection-name-input').val();
analytics.track('Created a Subsection', {
@@ -668,9 +662,9 @@ function saveNewSubsection(e) {
});
- $.post('/clone_item', {
+ $.post('/create_item', {
'parent_location': parent,
- 'template': template,
+ 'category': category,
'display_name': display_name
},
diff --git a/cms/templates/howitworks.html b/cms/templates/howitworks.html
index a791f5d1fa..8de260a69b 100644
--- a/cms/templates/howitworks.html
+++ b/cms/templates/howitworks.html
@@ -11,7 +11,7 @@
## "edX Studio" should not be translated
-
${_('Welcome to')}edX Studio
+
${_('Welcome to')} edX Studio
${_("Studio helps manage your courses online, so you can focus on teaching them")}
+ % for name, category, has_markdown, boilerplate_name in sorted(templates):
+ % if has_markdown or type != "problem":
+ % if boilerplate_name is None:
+
+ % endif
% endfor
diff --git a/cms/templates/widgets/units.html b/cms/templates/widgets/units.html
index 5ac05e79eb..62c1fb62d7 100644
--- a/cms/templates/widgets/units.html
+++ b/cms/templates/widgets/units.html
@@ -34,7 +34,7 @@ This def will enumerate through a passed in subsection and list all of the units
% endfor
diff --git a/cms/urls.py b/cms/urls.py
index 6db07dc2ed..711742d89f 100644
--- a/cms/urls.py
+++ b/cms/urls.py
@@ -17,7 +17,7 @@ urlpatterns = ('', # nopep8
url(r'^preview_component/(?P.*?)$', 'contentstore.views.preview_component', name='preview_component'),
url(r'^save_item$', 'contentstore.views.save_item', name='save_item'),
url(r'^delete_item$', 'contentstore.views.delete_item', name='delete_item'),
- url(r'^clone_item$', 'contentstore.views.clone_item', name='clone_item'),
+ url(r'^create_item$', 'contentstore.views.create_item', name='create_item'),
url(r'^create_draft$', 'contentstore.views.create_draft', name='create_draft'),
url(r'^publish_draft$', 'contentstore.views.publish_draft', name='publish_draft'),
url(r'^unpublish_unit$', 'contentstore.views.unpublish_unit', name='unpublish_unit'),
diff --git a/common/djangoapps/terrain/course_helpers.py b/common/djangoapps/terrain/course_helpers.py
index 27bf95099d..c62b1a1e79 100644
--- a/common/djangoapps/terrain/course_helpers.py
+++ b/common/djangoapps/terrain/course_helpers.py
@@ -12,7 +12,6 @@ from django.contrib.sessions.middleware import SessionMiddleware
from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore
from xmodule.contentstore.django import contentstore
-from xmodule.templates import update_templates
from urllib import quote_plus
@@ -84,5 +83,4 @@ def clear_courses():
# from the bash shell to drop it:
# $ mongo test_xmodule --eval "db.dropDatabase()"
modulestore().collection.drop()
- update_templates(modulestore('direct'))
contentstore().fs_files.drop()
diff --git a/common/djangoapps/tests.py b/common/djangoapps/tests.py
index 8e78ee7f37..4a61a106d4 100644
--- a/common/djangoapps/tests.py
+++ b/common/djangoapps/tests.py
@@ -23,15 +23,15 @@ class TestXmoduleModfiers(ModuleStoreTestCase):
number='313', display_name='histogram test')
section = ItemFactory.create(
parent_location=course.location, display_name='chapter hist',
- template='i4x://edx/templates/chapter/Empty')
+ category='chapter')
problem = ItemFactory.create(
parent_location=section.location, display_name='problem hist 1',
- template='i4x://edx/templates/problem/Blank_Common_Problem')
+ category='problem')
problem.has_score = False # don't trip trying to retrieve db data
late_problem = ItemFactory.create(
parent_location=section.location, display_name='problem hist 2',
- template='i4x://edx/templates/problem/Blank_Common_Problem')
+ category='problem')
late_problem.lms.start = datetime.datetime.now(UTC) + datetime.timedelta(days=32)
late_problem.has_score = False
diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py
index 7a74e75591..3efc04789e 100644
--- a/common/djangoapps/xmodule_modifiers.py
+++ b/common/djangoapps/xmodule_modifiers.py
@@ -89,6 +89,21 @@ def grade_histogram(module_id):
return grades
+def save_module(get_html, module):
+ """
+ Updates the given get_html function for the given module to save the fields
+ after rendering.
+ """
+ @wraps(get_html)
+ def _get_html():
+ """Cache the rendered output, save, then return the output."""
+ rendered_html = get_html()
+ module.save()
+ return rendered_html
+
+ return _get_html
+
+
def add_histogram(get_html, module, user):
"""
Updates the supplied module with a new get_html function that wraps
@@ -120,7 +135,7 @@ def add_histogram(get_html, module, user):
# doesn't like symlinks)
filepath = filename
data_dir = osfs.root_path.rsplit('/')[-1]
- giturl = getattr(module.lms, 'giturl', '') or 'https://github.com/MITx'
+ giturl = module.lms.giturl or 'https://github.com/MITx'
edit_link = "%s/%s/tree/master/%s" % (giturl, data_dir, filepath)
else:
edit_link = False
diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py
index 9bb72ad4e1..29800a211b 100644
--- a/common/lib/capa/capa/inputtypes.py
+++ b/common/lib/capa/capa/inputtypes.py
@@ -460,10 +460,10 @@ class JSInput(InputTypeBase):
DO NOT USE! HAS NOT BEEN TESTED BEYOND 700X PROBLEMS, AND MAY CHANGE IN
BACKWARDS-INCOMPATIBLE WAYS.
Inputtype for general javascript inputs. Intended to be used with
- customresponse.
+ customresponse.
Loads in a sandboxed iframe to help prevent css and js conflicts between
- frame and top-level window.
-
+ frame and top-level window.
+
iframe sandbox whitelist:
- allow-scripts
- allow-popups
@@ -474,9 +474,9 @@ class JSInput(InputTypeBase):
window elements.
Example:
-
See the documentation in the /doc/public folder for more information.
@@ -500,7 +500,7 @@ class JSInput(InputTypeBase):
Attribute('width', "400"), # iframe width
Attribute('height', "300")] # iframe height
-
+
def _extra_context(self):
context = {
@@ -510,11 +510,12 @@ class JSInput(InputTypeBase):
return context
-
+
registry.register(JSInput)
#-----------------------------------------------------------------------------
+
class TextLine(InputTypeBase):
"""
A text line input. Can do math preview if "math"="1" is specified.
@@ -1368,3 +1369,209 @@ class AnnotationInput(InputTypeBase):
return extra_context
registry.register(AnnotationInput)
+
+
+class ChoiceTextGroup(InputTypeBase):
+ """
+ Groups of radiobutton/checkboxes with text inputs.
+
+ Examples:
+ RadioButton problem
+
+
+ A person rolls a standard die 100 times and records the results.
+ On the first roll they received a "1". Given this information
+ select the correct choice and fill in numbers to make it accurate.
+
+
+
+ The lowest number rolled was:
+ and the highest number rolled was:
+ .
+ The lowest number rolled was
+ and there is not enough information to determine the highest number rolled.
+
+ There is not enough information to determine the lowest
+ number rolled, and the highest number rolled was:
+ .
+
+
+
+
+
+ CheckboxProblem:
+
+
+ A person randomly selects 100 times, with replacement, from the list of numbers \(\sqrt{2}\) , 2, 3, 4 ,5 ,6
+ and records the results. The first number they pick is \(\sqrt{2}\) Given this information
+ select the correct choices and fill in numbers to make them accurate.
+
+
+
+
+ The lowest number selected was
+
+
+ The highest number selected was .
+
+ There is not enough information given to determine the highest number
+ which was selected.
+
+ There is not enough information given to determine the lowest number
+ selected.
+
+
+
+
+
+ In the preceding examples the is used to generate a textinput html element
+ in the problem's display. Since it is inside of an incorrect choice, no answer given
+ for it will be correct, and thus specifying an answer for it is not needed.
+ """
+ template = "choicetext.html"
+ tags = ['radiotextgroup', 'checkboxtextgroup']
+
+ def setup(self):
+ """
+ Performs setup for the initial rendering of the problem.
+ `self.html_input_type` determines whether this problem is displayed
+ with radiobuttons or checkboxes
+
+ If the initial value of `self.value` is '' change it to {} so that
+ the template has an empty dictionary to work with.
+
+ sets the value of self.choices to be equal to the return value of
+ `self.extract_choices`
+ """
+ self.text_input_values = {}
+ if self.tag == 'radiotextgroup':
+ self.html_input_type = "radio"
+ elif self.tag == 'checkboxtextgroup':
+ self.html_input_type = "checkbox"
+ else:
+ raise Exception("ChoiceGroup: unexpected tag {0}".format(self.tag))
+
+ if self.value == '':
+ # Make `value` an empty dictionary, if it currently has an empty
+ # value. This is necessary because the template expects a
+ # dictionary.
+ self.value = {}
+ self.choices = self.extract_choices(self.xml)
+
+ @classmethod
+ def get_attributes(cls):
+ """
+ Returns a list of `Attribute` for this problem type
+ """
+ return [
+ Attribute("show_correctness", "always"),
+ Attribute("submitted_message", "Answer received.")
+ ]
+
+ def _extra_context(self):
+ """
+ Returns a dictionary of extra content necessary for rendering this InputType.
+
+ `input_type` is either 'radio' or 'checkbox' indicating whether the choices for
+ this problem will have radiobuttons or checkboxes.
+ """
+ return {
+ 'input_type': self.html_input_type,
+ 'choices': self.choices
+ }
+
+ @staticmethod
+ def extract_choices(element):
+ """
+ Extracts choices from the xml for this problem type.
+ If we have xml that is as follows(choice names will have been assigned
+ by now)
+
+
+ The number
+
+ Is the mean of the list.
+
+ " +
+ "tag; got {0} instead".format(choice.tag)
+ )
+
+ components = []
+ choice_text = ''
+ if choice.text is not None:
+ choice_text += choice.text
+ # Initialize our dict for the next content
+ adder = {
+ 'type': 'text',
+ 'contents': choice_text,
+ 'tail_text': '',
+ 'value': ''
+ }
+ components.append(adder)
+
+ for elt in choice:
+ # for elements in the choice e.g.
+ adder = {
+ 'type': 'text',
+ 'contents': '',
+ 'tail_text': '',
+ 'value': ''
+ }
+ tag_type = elt.tag
+ # If the current `elt` is a set the
+ # `adder`type to 'numtolerance_input', and 'contents' to
+ # the `elt`'s name.
+ # Treat decoy_inputs and numtolerance_inputs the same in order
+ # to prevent students from reading the Html and figuring out
+ # which inputs are valid
+ if tag_type in ('numtolerance_input', 'decoy_input'):
+ # We set this to textinput, so that we get a textinput html
+ # element.
+ adder['type'] = 'textinput'
+ adder['contents'] = elt.get('name')
+ else:
+ adder['contents'] = elt.text
+
+ # Add any tail text("is the mean" in the example)
+ adder['tail_text'] = elt.tail if elt.tail else ''
+ components.append(adder)
+
+ # Add the tuple for the current choice to the list of choices
+ choices.append((choice.get("name"), components))
+ return choices
+
+registry.register(ChoiceTextGroup)
diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py
index 3762c21976..f99518c8ce 100644
--- a/common/lib/capa/capa/responsetypes.py
+++ b/common/lib/capa/capa/responsetypes.py
@@ -2097,6 +2097,333 @@ class AnnotationResponse(LoncapaResponse):
return option_ids[0]
return None
+
+class ChoiceTextResponse(LoncapaResponse):
+ """
+ Allows for multiple choice responses with text inputs
+ Desired semantics match those of NumericalResponse and
+ ChoiceResponse.
+ """
+
+ response_tag = 'choicetextresponse'
+ max_inputfields = 1
+ allowed_inputfields = ['choicetextgroup',
+ 'checkboxtextgroup',
+ 'radiotextgroup'
+ ]
+
+ def setup_response(self):
+ """
+ Sets up three dictionaries for use later:
+ `correct_choices`: These are the correct binary choices(radio/checkbox)
+ `correct_inputs`: These are the numerical/string answers for required
+ inputs.
+ `answer_values`: This is a dict, keyed by the name of the binary choice
+ which contains the correct answers for the text inputs separated by
+ commas e.g. "1, 0.5"
+
+ `correct_choices` and `correct_inputs` are used for grading the problem
+ and `answer_values` is used for displaying correct answers.
+
+ """
+ context = self.context
+ self.correct_choices = {}
+ self.assign_choice_names()
+ self.correct_inputs = {}
+ self.answer_values = {self.answer_id: []}
+ correct_xml = self.xml.xpath('//*[@id=$id]//choice[@correct="true"]',
+ id=self.xml.get('id'))
+ for node in correct_xml:
+ # For each correct choice, set the `parent_name` to the
+ # current choice's name
+ parent_name = node.get('name')
+ # Add the name of the correct binary choice to the
+ # correct choices list as a key. The value is not important.
+ self.correct_choices[parent_name] = {'answer': ''}
+ # Add the name of the parent to the list of correct answers
+ self.answer_values[self.answer_id].append(parent_name)
+ answer_list = []
+ # Loop over elements inside of the correct choices
+ for child in node:
+ answer = child.get('answer', None)
+ if not answer:
+ # If the question creator does not specify an answer for a
+ # inside of a correct choice, raise an error
+ raise LoncapaProblemError(
+ "Answer not provided for numtolerance_input"
+ )
+ # Contextualize the answer to allow script generated answers.
+ answer = contextualize_text(answer, context)
+ input_name = child.get('name')
+ # Contextualize the tolerance to value.
+ tolerance = contextualize_text(
+ child.get('tolerance', '0'),
+ context
+ )
+ # Add the answer and tolerance information for the current
+ # numtolerance_input to `correct_inputs`
+ self.correct_inputs[input_name] = {
+ 'answer': answer,
+ 'tolerance': tolerance
+ }
+ # Add the correct answer for this input to the list for show
+ answer_list.append(answer)
+ # Turn the list of numtolerance_input answers into a comma separated string.
+ self.answer_values[parent_name] = ', '.join(answer_list)
+ # Turn correct choices into a set. Allows faster grading.
+ self.correct_choices = set(self.correct_choices.keys())
+
+ def assign_choice_names(self):
+ """
+ Initialize name attributes in and tags
+ for this response.
+
+ Example:
+ Assuming for simplicity that `self.answer_id` = '1_2_1'
+
+ Before the function is called `self.xml` =
+
+
+ The number
+
+ Is the mean of the list.
+
+
+ False demonstration choice
+
+
+
+ After this is called the choices and numtolerance_inputs will have a name
+ attribute initialized and self.xml will be:
+
+
+
+ The number
+
+ Is the mean of the list.
+
+
+ # "bc" is appended at the end to indicate that this is a
+ # binary choice as opposed to a numtolerance_input, this convention
+ # is used when grading the problem
+ choice.set(
+ "name",
+ self.answer_id + "_choiceinput_" + str(index) + "bc"
+ )
+ # Set Name attributes for elements
+ # Look for all inside this choice.
+ numtolerance_inputs = choice.findall('numtolerance_input')
+ # Look for all inside this choice
+ decoys = choice.findall('decoy_input')
+ # would only be used in choices which do not contain
+ #
+ inputs = numtolerance_inputs if numtolerance_inputs else decoys
+ # Give each input inside of the choice a name combining
+ # The ordinality of the choice, and the ordinality of the input
+ # within that choice e.g. 1_2_1_choiceinput_0_numtolerance_input_1
+ for ind, child in enumerate(inputs):
+ child.set(
+ "name",
+ self.answer_id + "_choiceinput_" + str(index) +
+ "_numtolerance_input_" + str(ind)
+ )
+
+ def get_score(self, student_answers):
+ """
+ Returns a `CorrectMap` showing whether `student_answers` are correct.
+
+ `student_answers` contains keys for binary inputs(radiobutton,
+ checkbox) and numerical inputs. Keys ending with 'bc' are binary
+ choice inputs otherwise they are text fields.
+
+ This method first separates the two
+ types of answers and then grades them in separate methods.
+
+ The student is only correct if they have both the binary inputs and
+ numerical inputs correct.
+ """
+ answer_dict = student_answers.get(self.answer_id, "")
+ binary_choices, numtolerance_inputs = self._split_answers_dict(answer_dict)
+ # Check the binary choices first.
+ choices_correct = self._check_student_choices(binary_choices)
+ inputs_correct = self._check_student_inputs(numtolerance_inputs)
+ # Only return correct if the student got both the binary
+ # and numtolerance_inputs are correct
+ correct = choices_correct and inputs_correct
+
+ return CorrectMap(
+ self.answer_id,
+ 'correct' if correct else 'incorrect'
+ )
+
+ def get_answers(self):
+ """
+ Returns a dictionary containing the names of binary choices as keys
+ and a string of answers to any numtolerance_inputs which they may have
+ e.g {choice_1bc : "answer1, answer2", choice_2bc : ""}
+ """
+ return self.answer_values
+
+ def _split_answers_dict(self, a_dict):
+ """
+ Returns two dicts:
+ `binary_choices` : dictionary {input_name: input_value} for
+ the binary choices which the student selected.
+ and
+ `numtolerance_choices` : a dictionary {input_name: input_value}
+ for the numtolerance_inputs inside of choices which were selected
+
+ Determines if an input is inside of a binary input by looking at
+ the beginning of it's name.
+
+ For example. If a binary_choice was named '1_2_1_choiceinput_0bc'
+ All of the numtolerance_inputs in it would have an idea that begins
+ with '1_2_1_choice_input_0_numtolerance_input'
+
+ Splits the name of the numtolerance_input at the occurence of
+ '_numtolerance_input_' and appends 'bc' to the end to get the name
+ of the choice it is contained in.
+
+ Example:
+ `a_dict` = {
+ '1_2_1_choiceinput_0bc': '1_2_1_choiceinput_0bc',
+ '1_2_1_choiceinput_0_numtolerance_input_0': '1',
+ '1_2_1_choiceinput_0_numtolerance_input_1': '2'
+ '1_2_1_choiceinput_1_numtolerance_input_0': '3'
+ }
+
+ In this case, the binary choice is '1_2_1_choiceinput_0bc', and
+ the numtolerance_inputs associated with it are
+ '1_2_1_choiceinput_0_numtolerance_input_0', and
+ '1_2_1_choiceinput_0_numtolerance_input_1'.
+
+ so the two return dictionaries would be
+ `binary_choices` = {'1_2_1_choiceinput_0bc': '1_2_1_choiceinput_0bc'}
+ and
+ `numtolerance_choices` ={
+ '1_2_1_choiceinput_0_numtolerance_input_0': '1',
+ '1_2_1_choiceinput_0_numtolerance_input_1': '2'
+ }
+
+ The entry '1_2_1_choiceinput_1_numtolerance_input_0': '3' is discarded
+ because it was not inside of a selected binary choice, and no validation
+ should be performed on numtolerance_inputs inside of non-selected choices.
+ """
+
+ # Initialize the two dictionaries that are returned
+ numtolerance_choices = {}
+ binary_choices = {}
+
+ # `selected_choices` is a list of binary choices which were "checked/selected"
+ # when the student submitted the problem.
+ # Keys in a_dict ending with 'bc' refer to binary choices.
+ selected_choices = [key for key in a_dict if key.endswith("bc")]
+ for key in selected_choices:
+ binary_choices[key] = a_dict[key]
+
+ # Convert the name of a numtolerance_input into the name of the binary
+ # choice that it is contained within, and append it to the list if
+ # the numtolerance_input's parent binary_choice is contained in
+ # `selected_choices`.
+ selected_numtolerance_inputs = [
+ key for key in a_dict if key.partition("_numtolerance_input_")[0] + "bc"
+ in selected_choices
+ ]
+
+ for key in selected_numtolerance_inputs:
+ numtolerance_choices[key] = a_dict[key]
+
+ return (binary_choices, numtolerance_choices)
+
+ def _check_student_choices(self, choices):
+ """
+ Compares student submitted checkbox/radiobutton answers against
+ the correct answers. Returns True or False.
+
+ True if all of the correct choices are selected and no incorrect
+ choices are selected.
+ """
+ student_choices = set(choices)
+ required_selected = len(self.correct_choices - student_choices) == 0
+ no_extra_selected = len(student_choices - self.correct_choices) == 0
+ correct = required_selected and no_extra_selected
+ return correct
+
+ def _check_student_inputs(self, numtolerance_inputs):
+ """
+ Compares student submitted numerical answers against the correct
+ answers and tolerances.
+
+ `numtolerance_inputs` is a dictionary {answer_name : answer_value}
+
+ Performs numerical validation by means of calling
+ `compare_with_tolerance()` on all of `numtolerance_inputs`
+
+ Performs a call to `compare_with_tolerance` even on values for
+ decoy_inputs. This is used to validate their numericality and
+ raise an error if the student entered a non numerical expression.
+
+ Returns True if and only if all student inputs are correct.
+ """
+ inputs_correct = True
+ for answer_name, answer_value in numtolerance_inputs.iteritems():
+ # If `self.corrrect_inputs` does not contain an entry for
+ # `answer_name`, this means that answer_name is a decoy
+ # input's value, and validation of its numericality is the
+ # only thing of interest from the later call to
+ # `compare_with_tolerance`.
+ params = self.correct_inputs.get(answer_name, {'answer': 0})
+
+ correct_ans = params['answer']
+ # Set the tolerance to '0' if it was not specified in the xml
+ tolerance = params.get('tolerance', '0')
+ # Make sure that the staff answer is a valid number
+ try:
+ correct_ans = complex(correct_ans)
+ except ValueError:
+ log.debug(
+ "Content error--answer" +
+ "'{0}' is not a valid complex number".format(correct_ans)
+ )
+ raise StudentInputError(
+ "The Staff answer could not be interpreted as a number."
+ )
+ # Compare the student answer to the staff answer/ or to 0
+ # if all that is important is verifying numericality
+ try:
+ partial_correct = compare_with_tolerance(
+ evaluator(dict(), dict(), answer_value),
+ correct_ans,
+ tolerance
+ )
+ except:
+ # Use the traceback-preserving version of re-raising with a
+ # different type
+ _, _, trace = sys.exc_info()
+
+ raise StudentInputError(
+ "Could not interpret '{0}' as a number{1}".format(
+ cgi.escape(answer_value),
+ trace
+ )
+ )
+ # Ignore the results of the comparisons which were just for
+ # Numerical Validation.
+ if answer_name in self.correct_inputs and not partial_correct:
+ # If any input is not correct, set the return value to False
+ inputs_correct = False
+ return inputs_correct
+
#-----------------------------------------------------------------------------
# TEMPORARY: List of all response subclasses
@@ -2116,4 +2443,5 @@ __all__ = [CodeResponse,
MultipleChoiceResponse,
TrueFalseResponse,
JavascriptResponse,
- AnnotationResponse]
+ AnnotationResponse,
+ ChoiceTextResponse]
diff --git a/common/lib/capa/capa/templates/choicetext.html b/common/lib/capa/capa/templates/choicetext.html
new file mode 100644
index 0000000000..5f587e214a
--- /dev/null
+++ b/common/lib/capa/capa/templates/choicetext.html
@@ -0,0 +1,76 @@
+<% element_checked = False %>
+% for choice_id, _ in choices:
+ <%choice_id = choice_id %>
+ %if choice_id in value:
+ <% element_checked = True %>
+ %endif
+%endfor
+
+
+
diff --git a/common/lib/capa/capa/tests/response_xml_factory.py b/common/lib/capa/capa/tests/response_xml_factory.py
index 35c12800ae..4c015d6699 100644
--- a/common/lib/capa/capa/tests/response_xml_factory.py
+++ b/common/lib/capa/capa/tests/response_xml_factory.py
@@ -779,3 +779,109 @@ class SymbolicResponseXMLFactory(ResponseXMLFactory):
def create_input_element(self, **kwargs):
return ResponseXMLFactory.textline_input_xml(**kwargs)
+
+
+class ChoiceTextResponseXMLFactory(ResponseXMLFactory):
+ """ Factory for producing xml """
+
+ def create_response_element(self, **kwargs):
+ """ Create a element """
+ return etree.Element("choicetextresponse")
+
+ def create_input_element(self, **kwargs):
+ """ Create a element.
+ choices can be specified in the following format:
+ [("true", [{"answer": "5", "tolerance": 0}]),
+ ("false", [{"answer": "5", "tolerance": 0}])
+ ]
+
+ This indicates that the first checkbox/radio is correct and it
+ contains a numtolerance_input with an answer of 5 and a tolerance of 0
+
+ It also indicates that the second has a second incorrect radiobutton
+ or checkbox with a numtolerance_input.
+ """
+ choices = kwargs.get('choices', [("true", {})])
+ choice_inputs = []
+ # Ensure that the first element of choices is an ordered
+ # collection. It will start as a list, a tuple, or not a Container.
+ if type(choices[0]) not in [list, tuple]:
+ choices = [choices]
+
+ for choice in choices:
+ correctness, answers = choice
+ numtolerance_inputs = []
+ # If the current `choice` contains any("answer": number)
+ # elements, turn those into numtolerance_inputs
+ if answers:
+ # `answers` will be a list or tuple of answers or a single
+ # answer, representing the answers for numtolerance_inputs
+ # inside of this specific choice.
+
+ # Make sure that `answers` is an ordered collection for
+ # convenience.
+ if type(answers) not in [list, tuple]:
+ answers = [answers]
+
+ numtolerance_inputs = [
+ self._create_numtolerance_input_element(answer)
+ for answer in answers
+ ]
+
+ choice_inputs.append(
+ self._create_choice_element(
+ correctness=correctness,
+ inputs=numtolerance_inputs
+ )
+ )
+ # Default type is 'radiotextgroup'
+ input_type = kwargs.get('type', 'radiotextgroup')
+ input_element = etree.Element(input_type)
+
+ for ind, choice in enumerate(choice_inputs):
+ # Give each choice text equal to it's position(0,1,2...)
+ choice.text = "choice_{0}".format(ind)
+ input_element.append(choice)
+
+ return input_element
+
+ def _create_choice_element(self, **kwargs):
+ """
+ Creates a choice element for a choictextproblem.
+ Defaults to a correct choice with no numtolerance_input
+ """
+ text = kwargs.get('text', '')
+ correct = kwargs.get('correctness', "true")
+ inputs = kwargs.get('inputs', [])
+ choice_element = etree.Element("choice")
+ choice_element.set("correct", correct)
+ choice_element.text = text
+ for inp in inputs:
+ # Add all of the inputs as children of this choice
+ choice_element.append(inp)
+
+ return choice_element
+
+ def _create_numtolerance_input_element(self, params):
+ """
+ Creates a or element with
+ optionally specified tolerance and answer.
+ """
+ answer = params['answer'] if 'answer' in params else None
+ # If there is not an answer specified, Then create a
+ # otherwise create a and set its tolerance
+ # and answer attributes.
+ if answer:
+ text_input = etree.Element("numtolerance_input")
+ text_input.set('answer', answer)
+ # If tolerance was specified, was specified use it, otherwise
+ # Set the tolerance to "0"
+ text_input.set(
+ 'tolerance',
+ params['tolerance'] if 'tolerance' in params else "0"
+ )
+
+ else:
+ text_input = etree.Element("decoy_input")
+
+ return text_input
diff --git a/common/lib/capa/capa/tests/test_input_templates.py b/common/lib/capa/capa/tests/test_input_templates.py
index 00a9b3f6c2..dcab279614 100644
--- a/common/lib/capa/capa/tests/test_input_templates.py
+++ b/common/lib/capa/capa/tests/test_input_templates.py
@@ -714,3 +714,170 @@ class DragAndDropTemplateTest(TemplateTestCase):
# escaping the HTML. We should be able to traverse the XML tree.
xpath = "//div[@class='drag_and_drop_problem_json']/p/b"
self.assert_has_text(xml, xpath, 'HTML')
+
+
+class ChoiceTextGroupTemplateTest(TemplateTestCase):
+ """Test mako template for `` input"""
+
+ TEMPLATE_NAME = 'choicetext.html'
+ VALUE_DICT = {'1_choiceinput_0bc': '1_choiceinput_0bc', '1_choiceinput_0_textinput_0': '0',
+ '1_choiceinput_1_textinput_0': '0'}
+ EMPTY_DICT = {'1_choiceinput_0_textinput_0': '',
+ '1_choiceinput_1_textinput_0': ''}
+ BOTH_CHOICE_CHECKBOX = {'1_choiceinput_0bc': 'choiceinput_0',
+ '1_choiceinput_1bc': 'choiceinput_1',
+ '1_choiceinput_0_textinput_0': '0',
+ '1_choiceinput_1_textinput_0': '0'}
+ WRONG_CHOICE_CHECKBOX = {'1_choiceinput_1bc': 'choiceinput_1',
+ '1_choiceinput_0_textinput_0': '0',
+ '1_choiceinput_1_textinput_0': '0'}
+
+ def setUp(self):
+ choices = [('1_choiceinput_0bc',
+ [{'tail_text': '', 'type': 'text', 'value': '', 'contents': ''},
+ {'tail_text': '', 'type': 'textinput', 'value': '', 'contents': 'choiceinput_0_textinput_0'}]),
+ ('1_choiceinput_1bc', [{'tail_text': '', 'type': 'text', 'value': '', 'contents': ''},
+ {'tail_text': '', 'type': 'textinput', 'value': '', 'contents': 'choiceinput_1_textinput_0'}])]
+ self.context = {'id': '1',
+ 'choices': choices,
+ 'status': 'correct',
+ 'input_type': 'radio',
+ 'value': self.VALUE_DICT}
+
+ super(ChoiceTextGroupTemplateTest, self).setUp()
+
+ def test_grouping_tag(self):
+ """
+ Tests whether we are using a section or a label to wrap choice elements.
+ Section is used for checkbox, so inputting text does not deselect
+ """
+ input_tags = ('radio', 'checkbox')
+ self.context['status'] = 'correct'
+ xpath = "//section[@id='forinput1_choiceinput_0bc']"
+
+ self.context['value'] = {}
+ for input_type in input_tags:
+ self.context['input_type'] = input_type
+ xml = self.render_to_xml(self.context)
+ self.assert_has_xpath(xml, xpath, self.context)
+
+ def test_problem_marked_correct(self):
+ """Test conditions under which the entire problem
+ (not a particular option) is marked correct"""
+
+ self.context['status'] = 'correct'
+ self.context['input_type'] = 'checkbox'
+ self.context['value'] = self.VALUE_DICT
+
+ # Should mark the entire problem correct
+ xml = self.render_to_xml(self.context)
+ xpath = "//div[@class='indicator_container']/span[@class='correct']"
+ self.assert_has_xpath(xml, xpath, self.context)
+
+ # Should NOT mark individual options
+ self.assert_no_xpath(xml, "//label[@class='choicetextgroup_incorrect']",
+ self.context)
+
+ self.assert_no_xpath(xml, "//label[@class='choicetextgroup_correct']",
+ self.context)
+
+ def test_problem_marked_incorrect(self):
+ """Test all conditions under which the entire problem
+ (not a particular option) is marked incorrect"""
+ grouping_tags = {'radio': 'label', 'checkbox': 'section'}
+ conditions = [
+ {'status': 'incorrect', 'input_type': 'radio', 'value': {}},
+ {'status': 'incorrect', 'input_type': 'checkbox', 'value': self.WRONG_CHOICE_CHECKBOX},
+ {'status': 'incorrect', 'input_type': 'checkbox', 'value': self.BOTH_CHOICE_CHECKBOX},
+ {'status': 'incorrect', 'input_type': 'checkbox', 'value': self.VALUE_DICT},
+ {'status': 'incomplete', 'input_type': 'radio', 'value': {}},
+ {'status': 'incomplete', 'input_type': 'checkbox', 'value': self.WRONG_CHOICE_CHECKBOX},
+ {'status': 'incomplete', 'input_type': 'checkbox', 'value': self.BOTH_CHOICE_CHECKBOX},
+ {'status': 'incomplete', 'input_type': 'checkbox', 'value': self.VALUE_DICT}]
+
+ for test_conditions in conditions:
+ self.context.update(test_conditions)
+ xml = self.render_to_xml(self.context)
+ xpath = "//div[@class='indicator_container']/span[@class='incorrect']"
+ self.assert_has_xpath(xml, xpath, self.context)
+
+ # Should NOT mark individual options
+ grouping_tag = grouping_tags[test_conditions['input_type']]
+ self.assert_no_xpath(xml,
+ "//{0}[@class='choicetextgroup_incorrect']".format(grouping_tag),
+ self.context)
+
+ self.assert_no_xpath(xml,
+ "//{0}[@class='choicetextgroup_correct']".format(grouping_tag),
+ self.context)
+
+ def test_problem_marked_unsubmitted(self):
+ """Test all conditions under which the entire problem
+ (not a particular option) is marked unanswered"""
+ grouping_tags = {'radio': 'label', 'checkbox': 'section'}
+
+ conditions = [
+ {'status': 'unsubmitted', 'input_type': 'radio', 'value': {}},
+ {'status': 'unsubmitted', 'input_type': 'radio', 'value': self.EMPTY_DICT},
+ {'status': 'unsubmitted', 'input_type': 'checkbox', 'value': {}},
+ {'status': 'unsubmitted', 'input_type': 'checkbox', 'value': self.EMPTY_DICT},
+ {'status': 'unsubmitted', 'input_type': 'checkbox', 'value': self.VALUE_DICT},
+ {'status': 'unsubmitted', 'input_type': 'checkbox', 'value': self.BOTH_CHOICE_CHECKBOX}]
+
+ self.context['status'] = 'unanswered'
+
+ for test_conditions in conditions:
+ self.context.update(test_conditions)
+ xml = self.render_to_xml(self.context)
+ xpath = "//div[@class='indicator_container']/span[@class='unanswered']"
+ self.assert_has_xpath(xml, xpath, self.context)
+
+ # Should NOT mark individual options
+ grouping_tag = grouping_tags[test_conditions['input_type']]
+ self.assert_no_xpath(xml,
+ "//{0}[@class='choicetextgroup_incorrect']".format(grouping_tag),
+ self.context)
+
+ self.assert_no_xpath(xml,
+ "//{0}[@class='choicetextgroup_correct']".format(grouping_tag),
+ self.context)
+
+ def test_option_marked_correct(self):
+ """Test conditions under which a particular option
+ (not the entire problem) is marked correct."""
+
+ conditions = [
+ {'input_type': 'radio', 'value': self.VALUE_DICT}]
+
+ self.context['status'] = 'correct'
+
+ for test_conditions in conditions:
+ self.context.update(test_conditions)
+ xml = self.render_to_xml(self.context)
+ xpath = "//section[@id='forinput1_choiceinput_0bc' and\
+ @class='choicetextgroup_correct']"
+ self.assert_has_xpath(xml, xpath, self.context)
+
+ # Should NOT mark the whole problem
+ xpath = "//div[@class='indicator_container']/span"
+ self.assert_no_xpath(xml, xpath, self.context)
+
+ def test_option_marked_incorrect(self):
+ """Test conditions under which a particular option
+ (not the entire problem) is marked incorrect."""
+
+ conditions = [
+ {'input_type': 'radio', 'value': self.VALUE_DICT}]
+
+ self.context['status'] = 'incorrect'
+
+ for test_conditions in conditions:
+ self.context.update(test_conditions)
+ xml = self.render_to_xml(self.context)
+ xpath = "//section[@id='forinput1_choiceinput_0bc' and\
+ @class='choicetextgroup_incorrect']"
+ self.assert_has_xpath(xml, xpath, self.context)
+
+ # Should NOT mark the whole problem
+ xpath = "//div[@class='indicator_container']/span"
+ self.assert_no_xpath(xml, xpath, self.context)
diff --git a/common/lib/capa/capa/tests/test_inputtypes.py b/common/lib/capa/capa/tests/test_inputtypes.py
index 1b52d41890..48e34dea09 100644
--- a/common/lib/capa/capa/tests/test_inputtypes.py
+++ b/common/lib/capa/capa/tests/test_inputtypes.py
@@ -860,3 +860,94 @@ class AnnotationInputTest(unittest.TestCase):
self.maxDiff = None
self.assertDictEqual(context, expected)
+
+
+class TestChoiceText(unittest.TestCase):
+ """
+ Tests for checkboxtextgroup inputs
+ """
+ @staticmethod
+ def build_choice_element(node_type, contents, tail_text, value):
+ """
+ Builds a content node for a choice.
+ """
+ # When xml is being parsed numtolerance_input and decoy_input tags map to textinput type
+ # in order to provide the template with correct rendering information.
+ if node_type in ('numtolerance_input', 'decoy_input'):
+ node_type = 'textinput'
+ choice = {'type': node_type, 'contents': contents, 'tail_text': tail_text, 'value': value}
+ return choice
+
+ def check_group(self, tag, choice_tag, expected_input_type):
+ """
+ Build a radio or checkbox group, parse it and check the resuls against the
+ expected output.
+
+ `tag` should be 'checkboxtextgroup' or 'radiotextgroup'
+ `choice_tag` is either 'choice' for proper xml, or any other value to trigger an error.
+ `expected_input_type` is either 'radio' or 'checkbox'.
+ """
+ xml_str = """
+ <{tag}>
+ <{choice_tag} correct="false" name="choiceinput_0">this isfalse{choice_tag}>
+ Is a number!
+ {tag}>
+ """.format(tag=tag, choice_tag=choice_tag)
+ element = etree.fromstring(xml_str)
+ state = {
+ 'value': '{}',
+ 'id': 'choicetext_input',
+ 'status': 'answered'
+ }
+
+ first_input = self.build_choice_element('numtolerance_input', 'choiceinput_0_textinput_0', 'false', '')
+ second_input = self.build_choice_element('decoy_input', 'choiceinput_1_textinput_0', '', '')
+ first_choice_content = self.build_choice_element('text', 'this is', '', '')
+ second_choice_content = self.build_choice_element('text', 'Is a number', '', '')
+ second_choice_text = self.build_choice_element('text', "!", '', '')
+
+ choices = [
+ ('choiceinput_0', [first_choice_content, first_input]),
+ ('choiceinput_1', [second_choice_content, second_input, second_choice_text])
+ ]
+
+ expected = {
+ 'msg': '',
+ 'input_type': expected_input_type,
+ 'choices': choices,
+ 'show_correctness': 'always',
+ 'submitted_message': 'Answer received.'
+ }
+ expected.update(state)
+ the_input = lookup_tag(tag)(test_system(), element, state)
+ context = the_input._get_render_context()
+ self.assertEqual(context, expected)
+
+ def test_radiotextgroup(self):
+ """
+ Test that a properly formatted radiotextgroup problem generates
+ expected ouputs
+ """
+ self.check_group('radiotextgroup', 'choice', 'radio')
+
+ def test_checkboxtextgroup(self):
+ """
+ Test that a properly formatted checkboxtextgroup problem generates
+ expected ouput
+ """
+ self.check_group('checkboxtextgroup', 'choice', 'checkbox')
+
+ def test_invalid_tag(self):
+ """
+ Test to ensure that an unrecognized inputtype tag causes an error
+ """
+ with self.assertRaises(Exception):
+ self.check_group('invalid', 'choice', 'checkbox')
+
+ def test_invalid_input_tag(self):
+ """
+ Test to ensure having a tag other than inside of
+ a checkbox or radiotextgroup problem raises an error.
+ """
+ with self.assertRaisesRegexp(Exception, "Error in xml"):
+ self.check_group('checkboxtextgroup', 'invalid', 'checkbox')
diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py
index 594e2ca629..2a15145579 100644
--- a/common/lib/capa/capa/tests/test_responsetypes.py
+++ b/common/lib/capa/capa/tests/test_responsetypes.py
@@ -1429,3 +1429,357 @@ class AnnotationResponseTest(ResponseTest):
msg="%s should be marked %s" % (answer_id, expected_correctness))
self.assertEqual(expected_points, actual_points,
msg="%s should have %d points" % (answer_id, expected_points))
+
+
+class ChoiceTextResponseTest(ResponseTest):
+ """
+ Class containing setup and tests for ChoiceText responsetype.
+ """
+
+ from response_xml_factory import ChoiceTextResponseXMLFactory
+ xml_factory_class = ChoiceTextResponseXMLFactory
+
+ # `TEST_INPUTS` is a dictionary mapping from
+ # test_name to a representation of inputs for a test problem.
+ TEST_INPUTS = {
+ "1_choice_0_input_correct": [(True, [])],
+ "1_choice_0_input_incorrect": [(False, [])],
+ "1_choice_0_input_invalid_choice": [(False, []), (True, [])],
+ "1_choice_1_input_correct": [(True, ["123"])],
+ "1_input_script_correct": [(True, ["2"])],
+ "1_input_script_incorrect": [(True, ["3.25"])],
+ "1_choice_2_inputs_correct": [(True, ["123", "456"])],
+ "1_choice_2_inputs_tolerance": [(True, ["123 + .5", "456 + 9"])],
+ "1_choice_2_inputs_1_wrong": [(True, ["0", "456"])],
+ "1_choice_2_inputs_both_wrong": [(True, ["0", "0"])],
+ "1_choice_2_inputs_inputs_blank": [(True, ["", ""])],
+ "1_choice_2_inputs_empty": [(False, [])],
+ "1_choice_2_inputs_fail_tolerance": [(True, ["123 + 1.5", "456 + 9"])],
+ "1_choice_1_input_within_tolerance": [(True, ["122.5"])],
+ "1_choice_1_input_answer_incorrect": [(True, ["345"])],
+ "1_choice_1_input_choice_incorrect": [(False, ["123"])],
+ "2_choices_0_inputs_correct": [(False, []), (True, [])],
+ "2_choices_0_inputs_incorrect": [(True, []), (False, [])],
+ "2_choices_0_inputs_blank": [(False, []), (False, [])],
+ "2_choices_1_input_1_correct": [(False, []), (True, ["123"])],
+ "2_choices_1_input_1_incorrect": [(True, []), (False, ["123"])],
+ "2_choices_1_input_input_wrong": [(False, []), (True, ["321"])],
+ "2_choices_1_input_1_blank": [(False, []), (False, [])],
+ "2_choices_1_input_2_correct": [(True, []), (False, ["123"])],
+ "2_choices_1_input_2_incorrect": [(False, []), (True, ["123"])],
+ "2_choices_2_inputs_correct": [(True, ["123"]), (False, [])],
+ "2_choices_2_inputs_wrong_choice": [(False, ["123"]), (True, [])],
+ "2_choices_2_inputs_wrong_input": [(True, ["321"]), (False, [])]
+ }
+
+ # `TEST_SCENARIOS` is a dictionary of the form
+ # {Test_Name" : (Test_Problem_name, correctness)}
+ # correctness represents whether the problem should be graded as
+ # correct or incorrect when the test is run.
+ TEST_SCENARIOS = {
+ "1_choice_0_input_correct": ("1_choice_0_input", "correct"),
+ "1_choice_0_input_incorrect": ("1_choice_0_input", "incorrect"),
+ "1_choice_0_input_invalid_choice": ("1_choice_0_input", "incorrect"),
+ "1_input_script_correct": ("1_input_script", "correct"),
+ "1_input_script_incorrect": ("1_input_script", "incorrect"),
+ "1_choice_2_inputs_correct": ("1_choice_2_inputs", "correct"),
+ "1_choice_2_inputs_tolerance": ("1_choice_2_inputs", "correct"),
+ "1_choice_2_inputs_1_wrong": ("1_choice_2_inputs", "incorrect"),
+ "1_choice_2_inputs_both_wrong": ("1_choice_2_inputs", "incorrect"),
+ "1_choice_2_inputs_inputs_blank": ("1_choice_2_inputs", "incorrect"),
+ "1_choice_2_inputs_empty": ("1_choice_2_inputs", "incorrect"),
+ "1_choice_2_inputs_fail_tolerance": ("1_choice_2_inputs", "incorrect"),
+ "1_choice_1_input_correct": ("1_choice_1_input", "correct"),
+ "1_choice_1_input_within_tolerance": ("1_choice_1_input", "correct"),
+ "1_choice_1_input_answer_incorrect": ("1_choice_1_input", "incorrect"),
+ "1_choice_1_input_choice_incorrect": ("1_choice_1_input", "incorrect"),
+ "2_choices_0_inputs_correct": ("2_choices_0_inputs", "correct"),
+ "2_choices_0_inputs_incorrect": ("2_choices_0_inputs", "incorrect"),
+ "2_choices_0_inputs_blank": ("2_choices_0_inputs", "incorrect"),
+ "2_choices_1_input_1_correct": ("2_choices_1_input_1", "correct"),
+ "2_choices_1_input_1_incorrect": ("2_choices_1_input_1", "incorrect"),
+ "2_choices_1_input_input_wrong": ("2_choices_1_input_1", "incorrect"),
+ "2_choices_1_input_1_blank": ("2_choices_1_input_1", "incorrect"),
+ "2_choices_1_input_2_correct": ("2_choices_1_input_2", "correct"),
+ "2_choices_1_input_2_incorrect": ("2_choices_1_input_2", "incorrect"),
+ "2_choices_2_inputs_correct": ("2_choices_2_inputs", "correct"),
+ "2_choices_2_inputs_wrong_choice": ("2_choices_2_inputs", "incorrect"),
+ "2_choices_2_inputs_wrong_input": ("2_choices_2_inputs", "incorrect")
+ }
+
+ # Dictionary that maps from problem_name to arguments for
+ # _make_problem, that will create the problem.
+ TEST_PROBLEM_ARGS = {
+ "1_choice_0_input": {"choices": ("true", {}), "script": ''},
+ "1_choice_1_input": {
+ "choices": ("true", {"answer": "123", "tolerance": "1"}),
+ "script": ''
+ },
+
+ "1_input_script": {
+ "choices": ("true", {"answer": "$computed_response", "tolerance": "1"}),
+ "script": "computed_response = math.sqrt(4)"
+ },
+
+ "1_choice_2_inputs": {
+ "choices": [
+ (
+ "true", (
+ {"answer": "123", "tolerance": "1"},
+ {"answer": "456", "tolerance": "10"}
+ )
+ )
+ ],
+ "script": ''
+ },
+ "2_choices_0_inputs": {
+ "choices": [("false", {}), ("true", {})],
+ "script": ''
+
+ },
+ "2_choices_1_input_1": {
+ "choices": [
+ ("false", {}), ("true", {"answer": "123", "tolerance": "0"})
+ ],
+ "script": ''
+ },
+ "2_choices_1_input_2": {
+ "choices": [("true", {}), ("false", {"answer": "123", "tolerance": "0"})],
+ "script": ''
+ },
+ "2_choices_2_inputs": {
+ "choices": [
+ ("true", {"answer": "123", "tolerance": "0"}),
+ ("false", {"answer": "999", "tolerance": "0"})
+ ],
+ "script": ''
+ }
+ }
+
+ def _make_problem(self, choices, in_type='radiotextgroup', script=''):
+ """
+ Convenience method to fill in default values for script and
+ type if needed, then call self.build_problem
+ """
+ return self.build_problem(
+ choices=choices,
+ type=in_type,
+ script=script
+ )
+
+ def _make_answer_dict(self, choice_list):
+ """
+ Convenience method to make generation of answers less tedious,
+ pass in an iterable argument with elements of the form: [bool, [ans,]]
+ Will generate an answer dict for those options
+ """
+
+ answer_dict = {}
+ for index, choice_answers_pair in enumerate(choice_list):
+ # Choice is whether this choice is correct
+ # Answers contains a list of answers to textinpts for the choice
+ choice, answers = choice_answers_pair
+
+ if choice:
+ # Radio/Checkbox inputs in choicetext problems follow
+ # a naming convention that gives them names ending with "bc"
+ choice_id = "1_2_1_choiceinput_{index}bc".format(index=index)
+ choice_value = "choiceinput_{index}".format(index=index)
+ answer_dict[choice_id] = choice_value
+ # Build the names for the numtolerance_inputs and add their answers
+ # to `answer_dict`.
+ for ind, answer in enumerate(answers):
+ # In `answer_id` `index` represents the ordinality of the
+ # choice and `ind` represents the ordinality of the
+ # numtolerance_input inside the parent choice.
+ answer_id = "1_2_1_choiceinput_{index}_numtolerance_input_{ind}".format(
+ index=index,
+ ind=ind
+ )
+ answer_dict[answer_id] = answer
+
+ return answer_dict
+
+ def test_invalid_xml(self):
+ """
+ Test that build problem raises errors for invalid options
+ """
+ with self.assertRaises(Exception):
+ self.build_problem(type="invalidtextgroup")
+
+ def test_valid_xml(self):
+ """
+ Test that `build_problem` builds valid xml
+ """
+ self.build_problem()
+ self.assertTrue(True)
+
+ def test_unchecked_input_not_validated(self):
+ """
+ Test that a student can have a non numeric answer in an unselected
+ choice without causing an error to be raised when the problem is
+ checked.
+ """
+
+ two_choice_two_input = self._make_problem(
+ [
+ ("true", {"answer": "123", "tolerance": "1"}),
+ ("false", {})
+ ],
+ "checkboxtextgroup"
+ )
+
+ self.assert_grade(
+ two_choice_two_input,
+ self._make_answer_dict([(True, ["1"]), (False, ["Platypus"])]),
+ "incorrect"
+ )
+
+ def test_interpret_error(self):
+ """
+ Test that student answers that cannot be interpeted as numbers
+ cause the response type to raise an error.
+ """
+ two_choice_two_input = self._make_problem(
+ [
+ ("true", {"answer": "123", "tolerance": "1"}),
+ ("false", {})
+ ],
+ "checkboxtextgroup"
+ )
+
+ with self.assertRaisesRegexp(StudentInputError, "Could not interpret"):
+ # Test that error is raised for input in selected correct choice.
+ self.assert_grade(
+ two_choice_two_input,
+ self._make_answer_dict([(True, ["Platypus"])]),
+ "correct"
+ )
+
+ with self.assertRaisesRegexp(StudentInputError, "Could not interpret"):
+ # Test that error is raised for input in selected incorrect choice.
+ self.assert_grade(
+ two_choice_two_input,
+ self._make_answer_dict([(True, ["1"]), (True, ["Platypus"])]),
+ "correct"
+ )
+
+ def test_staff_answer_error(self):
+ broken_problem = self._make_problem(
+ [("true", {"answer": "Platypus", "tolerance": "0"}),
+ ("true", {"answer": "edX", "tolerance": "0"})
+ ],
+ "checkboxtextgroup"
+ )
+ with self.assertRaisesRegexp(
+ StudentInputError,
+ "The Staff answer could not be interpreted as a number."
+ ):
+ self.assert_grade(
+ broken_problem,
+ self._make_answer_dict(
+ [(True, ["1"]), (True, ["1"])]
+ ),
+ "correct"
+ )
+
+ def test_radio_grades(self):
+ """
+ Test that confirms correct operation of grading when the inputtag is
+ radiotextgroup.
+ """
+
+ for name, inputs in self.TEST_INPUTS.iteritems():
+ # Turn submission into the form expected when grading this problem.
+ submission = self._make_answer_dict(inputs)
+ # Lookup the problem_name, and the whether this test problem
+ # and inputs should be graded as correct or incorrect.
+ problem_name, correctness = self.TEST_SCENARIOS[name]
+ # Load the args needed to build the problem for this test.
+ problem_args = self.TEST_PROBLEM_ARGS[problem_name]
+ test_choices = problem_args["choices"]
+ test_script = problem_args["script"]
+ # Build the actual problem for the test.
+ test_problem = self._make_problem(test_choices, 'radiotextgroup', test_script)
+ # Make sure the actual grade matches the expected grade.
+ self.assert_grade(
+ test_problem,
+ submission,
+ correctness,
+ msg="{0} should be {1}".format(
+ name,
+ correctness
+ )
+ )
+
+ def test_checkbox_grades(self):
+ """
+ Test that confirms correct operation of grading when the inputtag is
+ checkboxtextgroup.
+ """
+ # Dictionary from name of test_scenario to (problem_name, correctness)
+ # Correctness is used to test whether the problem was graded properly
+ scenarios = {
+ "2_choices_correct": ("checkbox_two_choices", "correct"),
+ "2_choices_incorrect": ("checkbox_two_choices", "incorrect"),
+
+ "2_choices_2_inputs_correct": (
+ "checkbox_2_choices_2_inputs",
+ "correct"
+ ),
+
+ "2_choices_2_inputs_missing_choice": (
+ "checkbox_2_choices_2_inputs",
+ "incorrect"
+ ),
+
+ "2_choices_2_inputs_wrong_input": (
+ "checkbox_2_choices_2_inputs",
+ "incorrect"
+ )
+ }
+ # Dictionary scenario_name: test_inputs
+ inputs = {
+ "2_choices_correct": [(True, []), (True, [])],
+ "2_choices_incorrect": [(True, []), (False, [])],
+ "2_choices_2_inputs_correct": [(True, ["123"]), (True, ["456"])],
+ "2_choices_2_inputs_missing_choice": [
+ (True, ["123"]), (False, ["456"])
+ ],
+ "2_choices_2_inputs_wrong_input": [
+ (True, ["123"]), (True, ["654"])
+ ]
+ }
+
+ # Two choice zero input problem with both choices being correct.
+ checkbox_two_choices = self._make_problem(
+ [("true", {}), ("true", {})], "checkboxtextgroup"
+ )
+ # Two choice two input problem with both choices correct.
+ checkbox_two_choices_two_inputs = self._make_problem(
+ [("true", {"answer": "123", "tolerance": "0"}),
+ ("true", {"answer": "456", "tolerance": "0"})
+ ],
+ "checkboxtextgroup"
+ )
+
+ # Dictionary problem_name: problem
+ problems = {
+ "checkbox_two_choices": checkbox_two_choices,
+ "checkbox_2_choices_2_inputs": checkbox_two_choices_two_inputs
+ }
+
+ for name, inputs in inputs.iteritems():
+ submission = self._make_answer_dict(inputs)
+ # Load the test problem's name and desired correctness
+ problem_name, correctness = scenarios[name]
+ # Load the problem
+ problem = problems[problem_name]
+
+ # Make sure the actual grade matches the expected grade
+ self.assert_grade(
+ problem,
+ submission,
+ correctness,
+ msg="{0} should be {1}".format(name, correctness)
+ )
diff --git a/common/lib/xmodule/xmodule/abtest_module.py b/common/lib/xmodule/xmodule/abtest_module.py
index 2e61076e94..53f080eb3a 100644
--- a/common/lib/xmodule/xmodule/abtest_module.py
+++ b/common/lib/xmodule/xmodule/abtest_module.py
@@ -80,8 +80,6 @@ class ABTestModule(ABTestFields, XModule):
class ABTestDescriptor(ABTestFields, RawDescriptor, XmlDescriptor):
module_class = ABTestModule
- template_dir_name = "abtest"
-
@classmethod
def definition_from_xml(cls, xml_object, system):
"""
diff --git a/common/lib/xmodule/xmodule/annotatable_module.py b/common/lib/xmodule/xmodule/annotatable_module.py
index e8674360c3..f80e3e488e 100644
--- a/common/lib/xmodule/xmodule/annotatable_module.py
+++ b/common/lib/xmodule/xmodule/annotatable_module.py
@@ -6,12 +6,37 @@ from pkg_resources import resource_string
from xmodule.x_module import XModule
from xmodule.raw_module import RawDescriptor
from xblock.core import Scope, String
+import textwrap
log = logging.getLogger(__name__)
class AnnotatableFields(object):
- data = String(help="XML data for the annotation", scope=Scope.content)
+ data = String(help="XML data for the annotation", scope=Scope.content,
+ default=textwrap.dedent(
+ """\
+
+
+
Enter your (optional) instructions for the exercise in HTML format.
+
Annotations are specified by an <annotation> tag which may may have the following attributes:
+
+
title (optional). Title of the annotation. Defaults to Commentary if omitted.
+
body (required). Text of the annotation.
+
problem (optional). Numeric index of the problem associated with this annotation. This is a zero-based index, so the first problem on the page would have problem="0".
+
highlight (optional). Possible values: yellow, red, orange, green, blue, or purple. Defaults to yellow if this attribute is omitted.
+
+
+
Add your HTML with annotation spans here.
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sodales laoreet est, egestas gravida felis egestas nec. Aenean at volutpat erat. Cras commodo viverra nibh in aliquam.
+
Nulla facilisi. Pellentesque id vestibulum libero. Suspendisse potenti. Morbi scelerisque nisi vitae felis dictum mattis. Nam sit amet magna elit. Nullam volutpat cursus est, sit amet sagittis odio vulputate et. Curabitur euismod, orci in vulputate imperdiet, augue lorem tempor purus, id aliquet augue turpis a est. Aenean a sagittis libero. Praesent fringilla pretium magna, non condimentum risus elementum nec. Pellentesque faucibus elementum pharetra. Pellentesque vitae metus eros.
+
+ """))
+ display_name = String(
+ display_name="Display Name",
+ help="Display name for this module",
+ scope=Scope.settings,
+ default='Annotation',
+ )
class AnnotatableModule(AnnotatableFields, XModule):
@@ -125,5 +150,4 @@ class AnnotatableModule(AnnotatableFields, XModule):
class AnnotatableDescriptor(AnnotatableFields, RawDescriptor):
module_class = AnnotatableModule
- template_dir_name = "annotatable"
mako_template = "widgets/raw-edit.html"
diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py
index eeb8f19439..d76b62dc06 100644
--- a/common/lib/xmodule/xmodule/capa_module.py
+++ b/common/lib/xmodule/xmodule/capa_module.py
@@ -77,6 +77,14 @@ class CapaFields(object):
"""
Define the possible fields for a Capa problem
"""
+ display_name = String(
+ display_name="Display Name",
+ help="This name appears in the horizontal navigation at the top of the page.",
+ scope=Scope.settings,
+ # it'd be nice to have a useful default but it screws up other things; so,
+ # use display_name_with_default for those
+ default="Blank Advanced Problem"
+ )
attempts = Integer(help="Number of attempts taken by the student on this problem",
default=0, scope=Scope.user_state)
max_attempts = Integer(
@@ -94,7 +102,8 @@ class CapaFields(object):
display_name="Show Answer",
help=("Defines when to show the answer to the problem. "
"A default value can be set in Advanced Settings."),
- scope=Scope.settings, default="closed",
+ scope=Scope.settings,
+ default="finished",
values=[
{"display_name": "Always", "value": "always"},
{"display_name": "Answered", "value": "answered"},
@@ -106,21 +115,24 @@ class CapaFields(object):
)
force_save_button = Boolean(
help="Whether to force the save button to appear on the page",
- scope=Scope.settings, default=False
+ scope=Scope.settings,
+ default=False
)
rerandomize = Randomization(
display_name="Randomization",
help="Defines how often inputs are randomized when a student loads the problem. "
- "This setting only applies to problems that can have randomly generated numeric values. "
- "A default value can be set in Advanced Settings.",
- default="always", scope=Scope.settings, values=[
+ "This setting only applies to problems that can have randomly generated numeric values. "
+ "A default value can be set in Advanced Settings.",
+ default="never",
+ scope=Scope.settings,
+ values=[
{"display_name": "Always", "value": "always"},
{"display_name": "On Reset", "value": "onreset"},
{"display_name": "Never", "value": "never"},
{"display_name": "Per Student", "value": "per_student"}
]
)
- data = String(help="XML data for the problem", scope=Scope.content)
+ data = String(help="XML data for the problem", scope=Scope.content, default="")
correct_map = Dict(help="Dictionary with the correctness of current student answers",
scope=Scope.user_state, default={})
input_state = Dict(help="Dictionary for maintaining the state of inputtypes", scope=Scope.user_state)
@@ -134,7 +146,7 @@ class CapaFields(object):
values={"min": 0, "step": .1},
scope=Scope.settings
)
- markdown = String(help="Markdown source of this module", scope=Scope.settings)
+ markdown = String(help="Markdown source of this module", default=None, scope=Scope.settings)
source_code = String(
help="Source code for LaTeX and Word problems. This feature is not well-supported.",
scope=Scope.settings
@@ -541,6 +553,16 @@ class CapaModule(CapaFields, XModule):
'ungraded_response': self.handle_ungraded_response
}
+ generic_error_message = (
+ "We're sorry, there was an error with processing your request. "
+ "Please try reloading your page and trying again."
+ )
+
+ not_found_error_message = (
+ "The state of this problem has changed since you loaded this page. "
+ "Please refresh your page."
+ )
+
if dispatch not in handlers:
return 'Error'
@@ -548,9 +570,14 @@ class CapaModule(CapaFields, XModule):
try:
result = handlers[dispatch](data)
+
+ except NotFoundError as err:
+ _, _, traceback_obj = sys.exc_info()
+ raise ProcessingError, (not_found_error_message, err), traceback_obj
+
except Exception as err:
_, _, traceback_obj = sys.exc_info()
- raise ProcessingError(err.message, traceback_obj)
+ raise ProcessingError, (generic_error_message, err), traceback_obj
after = self.get_progress()
@@ -749,6 +776,13 @@ class CapaModule(CapaFields, XModule):
then the output dict would contain {'1': ['test'] }
(the value is a list).
+ Some other inputs such as ChoiceTextInput expect a dict of values in the returned
+ dict If the key ends with '{}' then we will assume that the value is a json
+ encoded dict and deserialize it.
+ For example, if the `data` dict contains {'input_1{}': '{"1_2_1": 1}'}
+ then the output dict would contain {'1': {"1_2_1": 1} }
+ (the value is a dictionary)
+
Raises an exception if:
-A key in the `data` dictionary does not contain at least one underscore
@@ -775,11 +809,22 @@ class CapaModule(CapaFields, XModule):
# the same form input (e.g. checkbox inputs). The convention is that
# if the name ends with '[]' (which looks like an array), then the
# answer will be an array.
+ # if the name ends with '{}' (Which looks like a dict),
+ # then the answer will be a dict
is_list_key = name.endswith('[]')
- name = name[:-2] if is_list_key else name
+ is_dict_key = name.endswith('{}')
+ name = name[:-2] if is_list_key or is_dict_key else name
if is_list_key:
val = data.getlist(key)
+ elif is_dict_key:
+ try:
+ val = json.loads(data[key])
+ # If the submission wasn't deserializable, raise an error.
+ except(KeyError, ValueError):
+ raise ValueError(
+ u"Invalid submission: {val} for {key}".format(val=data[key], key=key)
+ )
else:
val = data[key]
@@ -1101,6 +1146,19 @@ class CapaDescriptor(CapaFields, RawDescriptor):
path[8:],
]
+ @classmethod
+ def from_xml(cls, xml_data, system, org=None, course=None):
+ """
+ Augment regular translation w/ setting the pre-Studio defaults.
+ """
+ problem = super(CapaDescriptor, cls).from_xml(xml_data, system, org, course)
+ # pylint: disable=W0212
+ if 'showanswer' not in problem._model_data:
+ problem.showanswer = "closed"
+ if 'rerandomize' not in problem._model_data:
+ problem.rerandomize = "always"
+ return problem
+
@property
def non_editable_metadata_fields(self):
non_editable_fields = super(CapaDescriptor, self).non_editable_metadata_fields
diff --git a/common/lib/xmodule/xmodule/combined_open_ended_module.py b/common/lib/xmodule/xmodule/combined_open_ended_module.py
index 52d98f032e..e01ae49149 100644
--- a/common/lib/xmodule/xmodule/combined_open_ended_module.py
+++ b/common/lib/xmodule/xmodule/combined_open_ended_module.py
@@ -9,10 +9,11 @@ from xblock.core import Integer, Scope, String, List, Float, Boolean
from xmodule.open_ended_grading_classes.combined_open_ended_modulev1 import CombinedOpenEndedV1Module, CombinedOpenEndedV1Descriptor
from collections import namedtuple
from .fields import Date
+import textwrap
log = logging.getLogger("mitx.courseware")
-V1_SETTINGS_ATTRIBUTES = ["display_name", "attempts", "is_graded", "accept_file_upload",
+V1_SETTINGS_ATTRIBUTES = ["display_name", "max_attempts", "graded", "accept_file_upload",
"skip_spelling_checks", "due", "graceperiod", "weight"]
V1_STUDENT_ATTRIBUTES = ["current_task_number", "task_states", "state",
@@ -27,6 +28,126 @@ VERSION_TUPLES = {
}
DEFAULT_VERSION = 1
+DEFAULT_DATA = textwrap.dedent("""\
+
+
+
Censorship in the Libraries
+
+
'All of us can think of a book that we hope none of our children or any other children have taken off the shelf. But if I have the right to remove that book from the shelf -- that work I abhor -- then you also have exactly the same right and so does everyone else. And then we have no books left on the shelf for any of us.' --Katherine Paterson, Author
+
+
+
+ Write a persuasive essay to a newspaper reflecting your vies on censorship in libraries. Do you believe that certain materials, such as books, music, movies, magazines, etc., should be removed from the shelves if they are found offensive? Support your position with convincing arguments from your own experience, observations, and/or reading.
+
+
+
+
+
+
+
+ Ideas
+
+
+
+
+
+
+
+
+ Content
+
+
+
+
+
+
+
+
+ Organization
+
+
+
+
+
+
+
+ Style
+
+
+
+
+
+
+
+ Voice
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enter essay here.
+ This is the answer.
+ {"grader_settings" : "ml_grading.conf", "problem_id" : "6.002x/Welcome/OETest"}
+
+
+
+
+
+
+
+ Enter essay here.
+ This is the answer.
+ {"grader_settings" : "peer_grading.conf", "problem_id" : "6.002x/Welcome/OETest"}
+
+
+
+
+
+""")
class VersionInteger(Integer):
@@ -51,47 +172,122 @@ class CombinedOpenEndedFields(object):
display_name = String(
display_name="Display Name",
help="This name appears in the horizontal navigation at the top of the page.",
- default="Open Ended Grading", scope=Scope.settings
+ default="Open Response Assessment",
+ scope=Scope.settings
)
- current_task_number = Integer(help="Current task that the student is on.", default=0, scope=Scope.user_state)
- task_states = List(help="List of state dictionaries of each task within this module.", scope=Scope.user_state)
- state = String(help="Which step within the current task that the student is on.", default="initial",
- scope=Scope.user_state)
- student_attempts = Integer(help="Number of attempts taken by the student on this problem", default=0,
- scope=Scope.user_state)
- ready_to_reset = Boolean(
- help="If the problem is ready to be reset or not.", default=False,
+ current_task_number = Integer(
+ help="Current task that the student is on.",
+ default=0,
scope=Scope.user_state
)
- attempts = Integer(
- display_name="Maximum Attempts",
- help="The number of times the student can try to answer this problem.", default=1,
- scope=Scope.settings, values={"min" : 1 }
+ task_states = List(
+ help="List of state dictionaries of each task within this module.",
+ scope=Scope.user_state
+ )
+ state = String(
+ help="Which step within the current task that the student is on.",
+ default="initial",
+ scope=Scope.user_state
+ )
+ graded = Boolean(
+ display_name="Graded",
+ help='Defines whether the student gets credit for grading this problem.',
+ default=False,
+ scope=Scope.settings
+ )
+ student_attempts = Integer(
+ help="Number of attempts taken by the student on this problem",
+ default=0,
+ scope=Scope.user_state
+ )
+ ready_to_reset = Boolean(
+ help="If the problem is ready to be reset or not.",
+ default=False,
+ scope=Scope.user_state
+ )
+ max_attempts = Integer(
+ display_name="Maximum Attempts",
+ help="The number of times the student can try to answer this problem.",
+ default=1,
+ scope=Scope.settings,
+ values={"min" : 1 }
)
- is_graded = Boolean(display_name="Graded", help="Whether or not the problem is graded.", default=False, scope=Scope.settings)
accept_file_upload = Boolean(
display_name="Allow File Uploads",
- help="Whether or not the student can submit files as a response.", default=False, scope=Scope.settings
+ help="Whether or not the student can submit files as a response.",
+ default=False,
+ scope=Scope.settings
)
skip_spelling_checks = Boolean(
display_name="Disable Quality Filter",
help="If False, the Quality Filter is enabled and submissions with poor spelling, short length, or poor grammar will not be peer reviewed.",
- default=False, scope=Scope.settings
+ default=False,
+ scope=Scope.settings
+ )
+ due = Date(
+ help="Date that this problem is due by",
+ default=None,
+ scope=Scope.settings
)
- due = Date(help="Date that this problem is due by", default=None, scope=Scope.settings)
graceperiod = String(
help="Amount of time after the due date that submissions will be accepted",
default=None,
scope=Scope.settings
)
version = VersionInteger(help="Current version number", default=DEFAULT_VERSION, scope=Scope.settings)
- data = String(help="XML data for the problem", scope=Scope.content)
+ data = String(help="XML data for the problem", scope=Scope.content,
+ default=DEFAULT_DATA)
weight = Float(
display_name="Problem Weight",
help="Defines the number of points each problem is worth. If the value is not set, each problem is worth one point.",
- scope=Scope.settings, values={"min" : 0 , "step": ".1"}
+ scope=Scope.settings,
+ values={"min" : 0 , "step": ".1"},
+ default=1
+ )
+ markdown = String(
+ help="Markdown source of this module",
+ default=textwrap.dedent("""\
+ [prompt]
+
Censorship in the Libraries
+
+
'All of us can think of a book that we hope none of our children or any other children have taken off the shelf. But if I have the right to remove that book from the shelf -- that work I abhor -- then you also have exactly the same right and so does everyone else. And then we have no books left on the shelf for any of us.' --Katherine Paterson, Author
+
+
+
+ Write a persuasive essay to a newspaper reflecting your vies on censorship in libraries. Do you believe that certain materials, such as books, music, movies, magazines, etc., should be removed from the shelves if they are found offensive? Support your position with convincing arguments from your own experience, observations, and/or reading.
+
+ [prompt]
+ [rubric]
+ + Ideas
+ - Difficult for the reader to discern the main idea. Too brief or too repetitive to establish or maintain a focus.
+ - Attempts a main idea. Sometimes loses focus or ineffectively displays focus.
+ - Presents a unifying theme or main idea, but may include minor tangents. Stays somewhat focused on topic and task.
+ - Presents a unifying theme or main idea without going off on tangents. Stays completely focused on topic and task.
+ + Content
+ - Includes little information with few or no details or unrelated details. Unsuccessful in attempts to explore any facets of the topic.
+ - Includes little information and few or no details. Explores only one or two facets of the topic.
+ - Includes sufficient information and supporting details. (Details may not be fully developed; ideas may be listed.) Explores some facets of the topic.
+ - Includes in-depth information and exceptional supporting details that are fully developed. Explores all facets of the topic.
+ + Organization
+ - Ideas organized illogically, transitions weak, and response difficult to follow.
+ - Attempts to logically organize ideas. Attempts to progress in an order that enhances meaning, and demonstrates use of transitions.
+ - Ideas organized logically. Progresses in an order that enhances meaning. Includes smooth transitions.
+ + Style
+ - Contains limited vocabulary, with many words used incorrectly. Demonstrates problems with sentence patterns.
+ - Contains basic vocabulary, with words that are predictable and common. Contains mostly simple sentences (although there may be an attempt at more varied sentence patterns).
+ - Includes vocabulary to make explanations detailed and precise. Includes varied sentence patterns, including complex sentences.
+ + Voice
+ - Demonstrates language and tone that may be inappropriate to task and reader.
+ - Demonstrates an attempt to adjust language and tone to task and reader.
+ - Demonstrates effective adjustment of language and tone to task and reader.
+ [rubric]
+ [tasks]
+ (Self), ({4-12}AI), ({9-12}Peer)
+ [tasks]
+
+ """),
+ scope=Scope.settings
)
- markdown = String(help="Markdown source of this module", scope=Scope.settings)
class CombinedOpenEndedModule(CombinedOpenEndedFields, XModule):
@@ -143,37 +339,9 @@ class CombinedOpenEndedModule(CombinedOpenEndedFields, XModule):
def __init__(self, *args, **kwargs):
"""
- Definition file should have one or many task blocks, a rubric block, and a prompt block:
+ Definition file should have one or many task blocks, a rubric block, and a prompt block.
- Sample file:
-
-
- Blah blah rubric.
-
-
- Some prompt.
-
-
-
-
- What hint about this problem would you give to someone?
-
-
- Save Succcesful. Thanks for participating!
-
-
-
-
-
-
- Enter essay here.
- This is the answer.
- {"grader_settings" : "ml_grading.conf",
- "problem_id" : "6.002x/Welcome/OETest"}
-
-
-
-
+ See DEFAULT_DATA for a sample.
"""
XModule.__init__(self, *args, **kwargs)
@@ -254,6 +422,11 @@ class CombinedOpenEndedDescriptor(CombinedOpenEndedFields, RawDescriptor):
js_module_name = "OpenEndedMarkdownEditingDescriptor"
css = {'scss': [resource_string(__name__, 'css/editor/edit.scss'), resource_string(__name__, 'css/combinedopenended/edit.scss')]}
+ metadata_translations = {
+ 'is_graded': 'graded',
+ 'attempts': 'max_attempts',
+ }
+
def get_context(self):
_context = RawDescriptor.get_context(self)
_context.update({'markdown': self.markdown,
diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py
index d75033c8a0..d1a60b5683 100644
--- a/common/lib/xmodule/xmodule/course_module.py
+++ b/common/lib/xmodule/xmodule/course_module.py
@@ -145,16 +145,55 @@ class TextbookList(List):
class CourseFields(object):
- textbooks = TextbookList(help="List of pairs of (title, url) for textbooks used in this course", scope=Scope.content)
+ textbooks = TextbookList(help="List of pairs of (title, url) for textbooks used in this course",
+ default=[], scope=Scope.content)
wiki_slug = String(help="Slug that points to the wiki for this course", scope=Scope.content)
enrollment_start = Date(help="Date that enrollment for this class is opened", scope=Scope.settings)
enrollment_end = Date(help="Date that enrollment for this class is closed", scope=Scope.settings)
- start = Date(help="Start time when this module is visible", scope=Scope.settings)
+ start = Date(help="Start time when this module is visible",
+ # using now(UTC()) resulted in fractional seconds which screwed up comparisons and anyway w/b the
+ # time of first invocation of this stmt on the server
+ default=datetime.fromtimestamp(0, UTC()),
+ scope=Scope.settings)
end = Date(help="Date that this class ends", scope=Scope.settings)
advertised_start = String(help="Date that this course is advertised to start", scope=Scope.settings)
- grading_policy = Dict(help="Grading policy definition for this class", scope=Scope.content)
+ grading_policy = Dict(help="Grading policy definition for this class",
+ default={"GRADER": [
+ {
+ "type": "Homework",
+ "min_count": 12,
+ "drop_count": 2,
+ "short_label": "HW",
+ "weight": 0.15
+ },
+ {
+ "type": "Lab",
+ "min_count": 12,
+ "drop_count": 2,
+ "weight": 0.15
+ },
+ {
+ "type": "Midterm Exam",
+ "short_label": "Midterm",
+ "min_count": 1,
+ "drop_count": 0,
+ "weight": 0.3
+ },
+ {
+ "type": "Final Exam",
+ "short_label": "Final",
+ "min_count": 1,
+ "drop_count": 0,
+ "weight": 0.4
+ }
+ ],
+ "GRADE_CUTOFFS": {
+ "Pass": 0.5
+ }},
+ scope=Scope.content)
show_calculator = Boolean(help="Whether to show the calculator in this course", default=False, scope=Scope.settings)
- display_name = String(help="Display name for this module", scope=Scope.settings)
+ display_name = String(help="Display name for this module", default="Empty", display_name="Display Name", scope=Scope.settings)
+ show_chat = Boolean(help="Whether to show the chat widget in this course", default=False, scope=Scope.settings)
tabs = List(help="List of tabs to enable in this course", scope=Scope.settings)
end_of_course_survey_url = String(help="Url for the end-of-course survey", scope=Scope.settings)
discussion_blackouts = List(help="List of pairs of start/end dates for discussion blackouts", scope=Scope.settings)
@@ -175,7 +214,125 @@ class CourseFields(object):
allow_anonymous_to_peers = Boolean(scope=Scope.settings, default=False)
advanced_modules = List(help="Beta modules used in your course", scope=Scope.settings)
has_children = True
- checklists = List(scope=Scope.settings)
+ checklists = List(scope=Scope.settings,
+ default=[
+ {"short_description" : "Getting Started With Studio",
+ "items" : [{"short_description": "Add Course Team Members",
+ "long_description": "Grant your collaborators permission to edit your course so you can work together.",
+ "is_checked": False,
+ "action_url": "ManageUsers",
+ "action_text": "Edit Course Team",
+ "action_external": False},
+ {"short_description": "Set Important Dates for Your Course",
+ "long_description": "Establish your course's student enrollment and launch dates on the Schedule and Details page.",
+ "is_checked": False,
+ "action_url": "SettingsDetails",
+ "action_text": "Edit Course Details & Schedule",
+ "action_external": False},
+ {"short_description": "Draft Your Course's Grading Policy",
+ "long_description": "Set up your assignment types and grading policy even if you haven't created all your assignments.",
+ "is_checked": False,
+ "action_url": "SettingsGrading",
+ "action_text": "Edit Grading Settings",
+ "action_external": False},
+ {"short_description": "Explore the Other Studio Checklists",
+ "long_description": "Discover other available course authoring tools, and find help when you need it.",
+ "is_checked": False,
+ "action_url": "",
+ "action_text": "",
+ "action_external": False}]
+ },
+ {"short_description" : "Draft a Rough Course Outline",
+ "items" : [{"short_description": "Create Your First Section and Subsection",
+ "long_description": "Use your course outline to build your first Section and Subsection.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False},
+ {"short_description": "Set Section Release Dates",
+ "long_description": "Specify the release dates for each Section in your course. Sections become visible to students on their release dates.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False},
+ {"short_description": "Designate a Subsection as Graded",
+ "long_description": "Set a Subsection to be graded as a specific assignment type. Assignments within graded Subsections count toward a student's final grade.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False},
+ {"short_description": "Reordering Course Content",
+ "long_description": "Use drag and drop to reorder the content in your course.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False},
+ {"short_description": "Renaming Sections",
+ "long_description": "Rename Sections by clicking the Section name from the Course Outline.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False},
+ {"short_description": "Deleting Course Content",
+ "long_description": "Delete Sections, Subsections, or Units you don't need anymore. Be careful, as there is no Undo function.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False},
+ {"short_description": "Add an Instructor-Only Section to Your Outline",
+ "long_description": "Some course authors find using a section for unsorted, in-progress work useful. To do this, create a section and set the release date to the distant future.",
+ "is_checked": False,
+ "action_url": "CourseOutline",
+ "action_text": "Edit Course Outline",
+ "action_external": False}]
+ },
+ {"short_description" : "Explore edX's Support Tools",
+ "items" : [{"short_description": "Explore the Studio Help Forum",
+ "long_description": "Access the Studio Help forum from the menu that appears when you click your user name in the top right corner of Studio.",
+ "is_checked": False,
+ "action_url": "http://help.edge.edx.org/",
+ "action_text": "Visit Studio Help",
+ "action_external": True},
+ {"short_description": "Enroll in edX 101",
+ "long_description": "Register for edX 101, edX's primer for course creation.",
+ "is_checked": False,
+ "action_url": "https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about",
+ "action_text": "Register for edX 101",
+ "action_external": True},
+ {"short_description": "Download the Studio Documentation",
+ "long_description": "Download the searchable Studio reference documentation in PDF form.",
+ "is_checked": False,
+ "action_url": "http://files.edx.org/Getting_Started_with_Studio.pdf",
+ "action_text": "Download Documentation",
+ "action_external": True}]
+ },
+ {"short_description" : "Draft Your Course About Page",
+ "items" : [{"short_description": "Draft a Course Description",
+ "long_description": "Courses on edX have an About page that includes a course video, description, and more. Draft the text students will read before deciding to enroll in your course.",
+ "is_checked": False,
+ "action_url": "SettingsDetails",
+ "action_text": "Edit Course Schedule & Details",
+ "action_external": False},
+ {"short_description": "Add Staff Bios",
+ "long_description": "Showing prospective students who their instructor will be is helpful. Include staff bios on the course About page.",
+ "is_checked": False,
+ "action_url": "SettingsDetails",
+ "action_text": "Edit Course Schedule & Details",
+ "action_external": False},
+ {"short_description": "Add Course FAQs",
+ "long_description": "Include a short list of frequently asked questions about your course.",
+ "is_checked": False,
+ "action_url": "SettingsDetails",
+ "action_text": "Edit Course Schedule & Details",
+ "action_external": False},
+ {"short_description": "Add Course Prerequisites",
+ "long_description": "Let students know what knowledge and/or skills they should have before they enroll in your course.",
+ "is_checked": False,
+ "action_url": "SettingsDetails",
+ "action_text": "Edit Course Schedule & Details",
+ "action_external": False}]
+ }
+ ])
info_sidebar_name = String(scope=Scope.settings, default='Course Handouts')
show_timezone = Boolean(help="True if timezones should be shown on dates in the courseware", scope=Scope.settings, default=True)
enrollment_domain = String(help="External login method associated with user accounts allowed to register in course",
@@ -208,8 +365,6 @@ class CourseFields(object):
class CourseDescriptor(CourseFields, SequenceDescriptor):
module_class = SequenceModule
- template_dir_name = 'course'
-
def __init__(self, *args, **kwargs):
"""
Expects the same arguments as XModuleDescriptor.__init__
@@ -220,18 +375,16 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
self.wiki_slug = self.location.course
msg = None
- if self.start is None:
- msg = "Course loaded without a valid start date. id = %s" % self.id
- self.start = datetime.now(UTC())
- log.critical(msg)
- self.system.error_tracker(msg)
# NOTE: relies on the modulestore to call set_grading_policy() right after
# init. (Modulestore is in charge of figuring out where to load the policy from)
# NOTE (THK): This is a last-minute addition for Fall 2012 launch to dynamically
# disable the syllabus content for courses that do not provide a syllabus
- self.syllabus_present = self.system.resources_fs.exists(path('syllabus'))
+ if self.system.resources_fs is None:
+ self.syllabus_present = False
+ else:
+ self.syllabus_present = self.system.resources_fs.exists(path('syllabus'))
self._grading_policy = {}
self.set_grading_policy(self.grading_policy)
@@ -252,42 +405,33 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
log.error(msg)
continue
- def default_grading_policy(self):
- """
- Return a dict which is a copy of the default grading policy
- """
- return {"GRADER": [
- {
- "type": "Homework",
- "min_count": 12,
- "drop_count": 2,
- "short_label": "HW",
- "weight": 0.15
- },
- {
- "type": "Lab",
- "min_count": 12,
- "drop_count": 2,
- "weight": 0.15
- },
- {
- "type": "Midterm Exam",
- "short_label": "Midterm",
- "min_count": 1,
- "drop_count": 0,
- "weight": 0.3
- },
- {
- "type": "Final Exam",
- "short_label": "Final",
- "min_count": 1,
- "drop_count": 0,
- "weight": 0.4
- }
- ],
- "GRADE_CUTOFFS": {
- "Pass": 0.5
- }}
+ # TODO check that this is still needed here and can't be by defaults.
+ if self.tabs is None:
+ # When calling the various _tab methods, can omit the 'type':'blah' from the
+ # first arg, since that's only used for dispatch
+ tabs = []
+ tabs.append({'type': 'courseware'})
+ tabs.append({'type': 'course_info', 'name': 'Course Info'})
+
+ if self.syllabus_present:
+ tabs.append({'type': 'syllabus'})
+
+ tabs.append({'type': 'textbooks'})
+
+ # # If they have a discussion link specified, use that even if we feature
+ # # flag discussions off. Disabling that is mostly a server safety feature
+ # # at this point, and we don't need to worry about external sites.
+ if self.discussion_link:
+ tabs.append({'type': 'external_discussion', 'link': self.discussion_link})
+ else:
+ tabs.append({'type': 'discussion', 'name': 'Discussion'})
+
+ tabs.append({'type': 'wiki', 'name': 'Wiki'})
+
+ if not self.hide_progress_tab:
+ tabs.append({'type': 'progress', 'name': 'Progress'})
+
+ self.tabs = tabs
def set_grading_policy(self, course_policy):
"""
@@ -298,7 +442,13 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
course_policy = {}
# Load the global settings as a dictionary
- grading_policy = self.default_grading_policy()
+ grading_policy = self.grading_policy
+ # BOY DO I HATE THIS grading_policy CODE ACROBATICS YET HERE I ADD MORE (dhm)--this fixes things persisted w/
+ # defective grading policy values (but not None)
+ if 'GRADER' not in grading_policy:
+ grading_policy['GRADER'] = CourseFields.grading_policy.default['GRADER']
+ if 'GRADE_CUTOFFS' not in grading_policy:
+ grading_policy['GRADE_CUTOFFS'] = CourseFields.grading_policy.default['GRADE_CUTOFFS']
# Override any global settings with the course settings
grading_policy.update(course_policy)
@@ -354,10 +504,6 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
system.error_tracker("Unable to decode grading policy as json")
policy = {}
- # cdodge: import the grading policy information that is on disk and put into the
- # descriptor 'definition' bucket as a dictionary so that it is persisted in the DB
- instance.grading_policy = policy
-
# now set the current instance. set_grading_policy() will apply some inheritance rules
instance.set_grading_policy(policy)
@@ -661,6 +807,7 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
if isinstance(self.advertised_start, basestring):
return try_parse_iso_8601(self.advertised_start)
elif self.advertised_start is None and self.start is None:
+ # TODO this is an impossible state since the init function forces start to have a value
return 'TBD'
else:
return (self.advertised_start or self.start).strftime("%b %d, %Y")
diff --git a/common/lib/xmodule/xmodule/css/capa/display.scss b/common/lib/xmodule/xmodule/css/capa/display.scss
index c326c79b76..9e6826242f 100644
--- a/common/lib/xmodule/xmodule/css/capa/display.scss
+++ b/common/lib/xmodule/xmodule/css/capa/display.scss
@@ -929,4 +929,32 @@ section.problem {
}
}
}
+ .choicetextgroup{
+ input[type="text"]{
+ margin-bottom: 0.5em;
+ }
+ @extend .choicegroup;
+
+ label.choicetextgroup_correct, section.choicetextgroup_correct{
+ @extend label.choicegroup_correct;
+
+ input[type="text"] {
+ border-color: green;
+ }
+ }
+
+ label.choicetextgroup_incorrect, section.choicetextgroup_incorrect{
+ @extend label.choicegroup_incorrect;
+ }
+
+ label.choicetextgroup_show_correct, section.choicetextgroup_show_correct{
+ &:after{
+ content: url('../images/correct-icon.png');
+ margin-left:15px;
+ }
+ }
+ span.mock_label{
+ cursor : default;
+ }
+ }
}
diff --git a/common/lib/xmodule/xmodule/discussion_module.py b/common/lib/xmodule/xmodule/discussion_module.py
index aef4821839..fac6a498e5 100644
--- a/common/lib/xmodule/xmodule/discussion_module.py
+++ b/common/lib/xmodule/xmodule/discussion_module.py
@@ -4,17 +4,27 @@ from xmodule.x_module import XModule
from xmodule.raw_module import RawDescriptor
from xmodule.editing_module import MetadataOnlyEditingDescriptor
from xblock.core import String, Scope
+from uuid import uuid4
class DiscussionFields(object):
- discussion_id = String(scope=Scope.settings)
+ discussion_id = String(scope=Scope.settings, default="$$GUID$$")
+ display_name = String(
+ display_name="Display Name",
+ help="Display name for this module",
+ default="Discussion Tag",
+ scope=Scope.settings)
+ data = String(help="XML data for the problem", scope=Scope.content,
+ default="")
discussion_category = String(
display_name="Category",
+ default="Week 1",
help="A category name for the discussion. This name appears in the left pane of the discussion forum for the course.",
scope=Scope.settings
)
discussion_target = String(
display_name="Subcategory",
+ default="Topic-Level Student-Visible Label",
help="A subcategory name for the discussion. This name appears in the left pane of the discussion forum for the course.",
scope=Scope.settings
)
@@ -36,9 +46,15 @@ class DiscussionModule(DiscussionFields, XModule):
class DiscussionDescriptor(DiscussionFields, MetadataOnlyEditingDescriptor, RawDescriptor):
- module_class = DiscussionModule
- template_dir_name = "discussion"
+ def __init__(self, *args, **kwargs):
+ super(DiscussionDescriptor, self).__init__(*args, **kwargs)
+ # is this too late? i.e., will it get persisted and stay static w/ the first value
+ # any code references. I believe so.
+ if self.discussion_id == '$$GUID$$':
+ self.discussion_id = uuid4().hex
+
+ module_class = DiscussionModule
# The discussion XML format uses `id` and `for` attributes,
# but these would overload other module attributes, so we prefix them
# for actual use in the code
diff --git a/common/lib/xmodule/xmodule/error_module.py b/common/lib/xmodule/xmodule/error_module.py
index a37081c447..db1f998187 100644
--- a/common/lib/xmodule/xmodule/error_module.py
+++ b/common/lib/xmodule/xmodule/error_module.py
@@ -96,6 +96,7 @@ class ErrorDescriptor(ErrorFields, JSONEditingDescriptor):
'contents': contents,
'display_name': 'Error: ' + location.name,
'location': location,
+ 'category': 'error'
}
return cls(
system,
@@ -109,12 +110,12 @@ class ErrorDescriptor(ErrorFields, JSONEditingDescriptor):
}
@classmethod
- def from_json(cls, json_data, system, error_msg='Error not available'):
+ def from_json(cls, json_data, system, location, error_msg='Error not available'):
return cls._construct(
system,
- json.dumps(json_data, indent=4),
+ json.dumps(json_data, skipkeys=False, indent=4),
error_msg,
- location=Location(json_data['location']),
+ location=location
)
@classmethod
diff --git a/common/lib/xmodule/xmodule/fields.py b/common/lib/xmodule/xmodule/fields.py
index a9b4be4fcd..465993a51f 100644
--- a/common/lib/xmodule/xmodule/fields.py
+++ b/common/lib/xmodule/xmodule/fields.py
@@ -58,8 +58,7 @@ class Date(ModelType):
else:
msg = "Field {0} has bad value '{1}'".format(
self._name, field)
- log.warning(msg)
- return None
+ raise TypeError(msg)
def to_json(self, value):
"""
@@ -76,6 +75,8 @@ class Date(ModelType):
return value.strftime('%Y-%m-%dT%H:%M:%SZ')
else:
return value.isoformat()
+ else:
+ raise TypeError("Cannot convert {} to json".format(value))
TIMEDELTA_REGEX = re.compile(r'^((?P\d+?) day(?:s?))?(\s)?((?P\d+?) hour(?:s?))?(\s)?((?P\d+?) minute(?:s)?)?(\s)?((?P\d+?) second(?:s)?)?$')
diff --git a/common/lib/xmodule/xmodule/foldit_module.py b/common/lib/xmodule/xmodule/foldit_module.py
index fdab14b58d..cadf6cef0b 100644
--- a/common/lib/xmodule/xmodule/foldit_module.py
+++ b/common/lib/xmodule/xmodule/foldit_module.py
@@ -91,15 +91,18 @@ class FolditModule(FolditFields, XModule):
PuzzleComplete.completed_puzzles(self.system.anonymous_student_id),
key=lambda d: (d['set'], d['subset']))
- def puzzle_leaders(self, n=10):
+ def puzzle_leaders(self, n=10, courses=None):
"""
Returns a list of n pairs (user, score) corresponding to the top
scores; the pairs are in descending order of score.
"""
from foldit.models import Score
- leaders = [(e['username'], e['score']) for e in Score.get_tops_n(10)]
- leaders.sort(key=lambda x:-x[1])
+ if courses is None:
+ courses = [self.location.course_id]
+
+ leaders = [(leader['username'], leader['score']) for leader in Score.get_tops_n(10, course_list=courses)]
+ leaders.sort(key=lambda x: -x[1])
return leaders
@@ -184,7 +187,6 @@ class FolditDescriptor(FolditFields, XmlDescriptor, EditingDescriptor):
filename_extension = "xml"
has_score = True
- template_dir_name = "foldit"
js = {'coffee': [resource_string(__name__, 'js/src/html/edit.coffee')]}
js_module_name = "HTMLEditingDescriptor"
diff --git a/common/lib/xmodule/xmodule/gst_module.py b/common/lib/xmodule/xmodule/gst_module.py
index e101d90b4c..5a4930ff95 100644
--- a/common/lib/xmodule/xmodule/gst_module.py
+++ b/common/lib/xmodule/xmodule/gst_module.py
@@ -141,7 +141,6 @@ class GraphicalSliderToolModule(GraphicalSliderToolFields, XModule):
class GraphicalSliderToolDescriptor(GraphicalSliderToolFields, MakoModuleDescriptor, XmlDescriptor):
module_class = GraphicalSliderToolModule
- template_dir_name = 'graphical_slider_tool'
@classmethod
def definition_from_xml(cls, xml_object, system):
diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py
index 0f7e789906..0536f5ef5e 100644
--- a/common/lib/xmodule/xmodule/html_module.py
+++ b/common/lib/xmodule/xmodule/html_module.py
@@ -13,12 +13,21 @@ from xmodule.html_checker import check_html
from xmodule.stringify import stringify_children
from xmodule.x_module import XModule
from xmodule.xml_module import XmlDescriptor, name_to_pathname
+import textwrap
log = logging.getLogger("mitx.courseware")
class HtmlFields(object):
- data = String(help="Html contents to display for this module", scope=Scope.content)
+ display_name = String(
+ display_name="Display Name",
+ help="This name appears in the horizontal navigation at the top of the page.",
+ scope=Scope.settings,
+ # it'd be nice to have a useful default but it screws up other things; so,
+ # use display_name_with_default for those
+ default="Blank HTML Page"
+ )
+ data = String(help="Html contents to display for this module", default="", scope=Scope.content)
source_code = String(help="Source code for LaTeX documents. This feature is not well-supported.", scope=Scope.settings)
@@ -32,7 +41,7 @@ class HtmlModule(HtmlFields, XModule):
css = {'scss': [resource_string(__name__, 'css/html/display.scss')]}
def get_html(self):
- if self.system.anonymous_student_id:
+ if self.system.anonymous_student_id:
return self.data.replace("%%USER_ID%%", self.system.anonymous_student_id)
return self.data
@@ -158,9 +167,9 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor):
pathname=pathname)
resource_fs.makedir(os.path.dirname(filepath), recursive=True, allow_recreate=True)
- with resource_fs.open(filepath, 'w') as file:
+ with resource_fs.open(filepath, 'w') as filestream:
html_data = self.data.encode('utf-8')
- file.write(html_data)
+ filestream.write(html_data)
# write out the relative name
relname = path(pathname).basename()
@@ -169,26 +178,88 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor):
elt.set("filename", relname)
return elt
+class AboutFields(object):
+ display_name = String(
+ help="Display name for this module",
+ scope=Scope.settings,
+ default="overview",
+ )
+ data = String(
+ help="Html contents to display for this module",
+ default="",
+ scope=Scope.content
+ )
-class AboutDescriptor(HtmlDescriptor):
+class AboutModule(AboutFields, HtmlModule):
+ """
+ Overriding defaults but otherwise treated as HtmlModule.
+ """
+ pass
+
+class AboutDescriptor(AboutFields, HtmlDescriptor):
"""
These pieces of course content are treated as HtmlModules but we need to overload where the templates are located
in order to be able to create new ones
"""
template_dir_name = "about"
+ module_class = AboutModule
+
+class StaticTabFields(object):
+ """
+ The overrides for Static Tabs
+ """
+ display_name = String(
+ display_name="Display Name",
+ help="This name appears in the horizontal navigation at the top of the page.",
+ scope=Scope.settings,
+ default="Empty",
+ )
+ data = String(
+ default=textwrap.dedent("""\
+
This is where you can add additional pages to your courseware. Click the 'edit' button to begin editing.
+ """),
+ scope=Scope.content,
+ help="HTML for the additional pages"
+ )
-class StaticTabDescriptor(HtmlDescriptor):
+class StaticTabModule(StaticTabFields, HtmlModule):
+ """
+ Supports the field overrides
+ """
+ pass
+
+class StaticTabDescriptor(StaticTabFields, HtmlDescriptor):
"""
These pieces of course content are treated as HtmlModules but we need to overload where the templates are located
in order to be able to create new ones
"""
- template_dir_name = "statictab"
+ template_dir_name = None
+ module_class = StaticTabModule
-class CourseInfoDescriptor(HtmlDescriptor):
+class CourseInfoFields(object):
+ """
+ Field overrides
+ """
+ data = String(
+ help="Html contents to display for this module",
+ default="",
+ scope=Scope.content
+ )
+
+
+class CourseInfoModule(CourseInfoFields, HtmlModule):
+ """
+ Just to support xblock field overrides
+ """
+ pass
+
+
+class CourseInfoDescriptor(CourseInfoFields, HtmlDescriptor):
"""
These pieces of course content are treated as HtmlModules but we need to overload where the templates are located
in order to be able to create new ones
"""
- template_dir_name = "courseinfo"
+ template_dir_name = None
+ module_class = CourseInfoModule
diff --git a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee
index 1efaa6c852..bca89b0dea 100644
--- a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee
+++ b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee
@@ -223,6 +223,58 @@ describe 'Problem', ->
expect($('label[for="input_1_1_3"]')).toHaveAttr 'correct_answer', 'true'
expect($('label[for="input_1_2_1"]')).not.toHaveAttr 'correct_answer', 'true'
+ describe 'radio text question', ->
+ radio_text_xml='''
+
+
+
+
+
+
+'''
+ beforeEach ->
+ # Append a radiotextresponse problem to the problem, so we can check it's javascript functionality
+ @problem.el.prepend(radio_text_xml)
+
+ it 'sets the correct class on the section for the correct choice', ->
+ spyOn($, 'postWithPrefix').andCallFake (url, callback) ->
+ callback answers: "1_2_1": ["1_2_1_choiceinput_0bc"], "1_2_1_choiceinput_0bc": "3"
+ @problem.show()
+
+ expect($('#forinput1_2_1_choiceinput_0bc').attr('class')).toEqual(
+ 'choicetextgroup_show_correct')
+ expect($('#answer_1_2_1_choiceinput_0bc').text()).toEqual('3')
+ expect($('#answer_1_2_1_choiceinput_1bc').text()).toEqual('')
+ expect($('#answer_1_2_1_choiceinput_2bc').text()).toEqual('')
+
+ it 'Should not disable input fields', ->
+ spyOn($, 'postWithPrefix').andCallFake (url, callback) ->
+ callback answers: "1_2_1": ["1_2_1_choiceinput_0bc"], "1_2_1_choiceinput_0bc": "3"
+ @problem.show()
+ expect($('input#1_2_1_choiceinput_0bc').attr('disabled')).not.toEqual('disabled')
+ expect($('input#1_2_1_choiceinput_1bc').attr('disabled')).not.toEqual('disabled')
+ expect($('input#1_2_1_choiceinput_2bc').attr('disabled')).not.toEqual('disabled')
+ expect($('input#1_2_1').attr('disabled')).not.toEqual('disabled')
+
describe 'when the answers are already shown', ->
beforeEach ->
@problem.el.addClass 'showed'
diff --git a/common/lib/xmodule/xmodule/js/spec/combinedopenended/edit_spec.coffee b/common/lib/xmodule/xmodule/js/spec/combinedopenended/edit_spec.coffee
index aa077da450..d859a59dda 100644
--- a/common/lib/xmodule/xmodule/js/spec/combinedopenended/edit_spec.coffee
+++ b/common/lib/xmodule/xmodule/js/spec/combinedopenended/edit_spec.coffee
@@ -11,13 +11,13 @@ describe 'OpenEndedMarkdownEditingDescriptor', ->
@descriptor = new OpenEndedMarkdownEditingDescriptor($('.combinedopenended-editor'))
@descriptor.createXMLEditor('replace with markdown')
saveResult = @descriptor.save()
- expect(saveResult.metadata.markdown).toEqual(null)
+ expect(saveResult.nullout).toEqual(['markdown'])
expect(saveResult.data).toEqual('replace with markdown')
it 'saves xml from the xml editor', ->
loadFixtures 'combinedopenended-without-markdown.html'
@descriptor = new OpenEndedMarkdownEditingDescriptor($('.combinedopenended-editor'))
saveResult = @descriptor.save()
- expect(saveResult.metadata.markdown).toEqual(null)
+ expect(saveResult.nullout).toEqual(['markdown'])
expect(saveResult.data).toEqual('xml only')
describe 'insertPrompt', ->
diff --git a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
index 5161e658e7..1df9587037 100644
--- a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
+++ b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
@@ -11,13 +11,13 @@ describe 'MarkdownEditingDescriptor', ->
@descriptor = new MarkdownEditingDescriptor($('.problem-editor'))
@descriptor.createXMLEditor('replace with markdown')
saveResult = @descriptor.save()
- expect(saveResult.metadata.markdown).toEqual(null)
+ expect(saveResult.nullout).toEqual(['markdown'])
expect(saveResult.data).toEqual('replace with markdown')
it 'saves xml from the xml editor', ->
loadFixtures 'problem-without-markdown.html'
@descriptor = new MarkdownEditingDescriptor($('.problem-editor'))
saveResult = @descriptor.save()
- expect(saveResult.metadata.markdown).toEqual(null)
+ expect(saveResult.nullout).toEqual(['markdown'])
expect(saveResult.data).toEqual('xml only')
describe 'insertMultipleChoice', ->
diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee
index e29276936b..601fb749ac 100644
--- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee
+++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee
@@ -22,7 +22,6 @@ class @Problem
@$('section.action input:button').click @refreshAnswers
@$('section.action input.check').click @check_fd
- #@$('section.action input.check').click @check
@$('section.action input.reset').click @reset
@$('section.action button.show').click @show
@$('section.action input.save').click @save
@@ -162,9 +161,6 @@ class @Problem
# maybe preferable to consolidate all dispatches to use FormData
###
check_fd: =>
- # Calling check from check_fd will result in firing the 'problem_check' event twice, since it is also called in the check function.
- #Logger.log 'problem_check', @answers
-
# If there are no file inputs in the problem, we can fall back on @check
if $('input:file').length == 0
@check()
@@ -239,6 +235,12 @@ class @Problem
check: =>
@check_waitfor()
Logger.log 'problem_check', @answers
+
+ # Segment.io
+ analytics.track "Problem Checked",
+ problem_id: @id
+ answers: @answers
+
$.postWithPrefix "#{@url}/problem_check", @answers, (response) =>
switch response.success
when 'incorrect', 'correct'
@@ -401,6 +403,14 @@ class @Problem
answer = JSON.parse(answers[answer_id])
display.showAnswer(answer)
+ choicetextgroup: (element, display, answers) =>
+ element = $(element)
+
+ input_id = element.attr('id').replace(/inputtype_/,'')
+ answer = answers[input_id]
+ for choice in answer
+ element.find("section#forinput#{choice}").addClass 'choicetextgroup_show_correct'
+
inputtypeHideAnswerMethods:
choicegroup: (element, display) =>
element = $(element)
@@ -408,3 +418,7 @@ class @Problem
javascriptinput: (element, display) =>
display.hideAnswer()
+
+ choicetextgroup: (element, display) =>
+ element = $(element)
+ element.find("section[id^='forinput']").removeClass('choicetextgroup_show_correct')
diff --git a/common/lib/xmodule/xmodule/js/src/combinedopenended/edit.coffee b/common/lib/xmodule/xmodule/js/src/combinedopenended/edit.coffee
index 1b7f9bb4fb..1f3b711804 100644
--- a/common/lib/xmodule/xmodule/js/src/combinedopenended/edit.coffee
+++ b/common/lib/xmodule/xmodule/js/src/combinedopenended/edit.coffee
@@ -50,6 +50,10 @@ Write a persuasive essay to a newspaper reflecting your vies on censorship in li
mode: null
})
@setCurrentEditor(@markdown_editor)
+ selection = @markdown_editor.getSelection()
+ #Auto-add in the needed template if it isn't already in there.
+ if(@markdown_editor.getValue() == "")
+ @markdown_editor.setValue(OpenEndedMarkdownEditingDescriptor.promptTemplate + "\n" + OpenEndedMarkdownEditingDescriptor.rubricTemplate + "\n" + OpenEndedMarkdownEditingDescriptor.tasksTemplate)
# Add listeners for toolbar buttons (only present for markdown editor)
@element.on('click', '.xml-tab', @onShowXMLButton)
@element.on('click', '.format-buttons a', @onToolbarButton)
@@ -153,8 +157,7 @@ Write a persuasive essay to a newspaper reflecting your vies on censorship in li
else
{
data: @xml_editor.getValue()
- metadata:
- markdown: null
+ nullout: ['markdown']
}
@insertRubric: (selectedText) ->
diff --git a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee
index b723f230e9..bd2871eb61 100644
--- a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee
+++ b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee
@@ -123,9 +123,8 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
}
else
{
- data: @xml_editor.getValue()
- metadata:
- markdown: null
+ data: @xml_editor.getValue()
+ nullout: ['markdown']
}
@insertMultipleChoice: (selectedText) ->
diff --git a/common/lib/xmodule/xmodule/modulestore/__init__.py b/common/lib/xmodule/xmodule/modulestore/__init__.py
index 2fa12e2e90..eb721dfc99 100644
--- a/common/lib/xmodule/xmodule/modulestore/__init__.py
+++ b/common/lib/xmodule/xmodule/modulestore/__init__.py
@@ -310,14 +310,7 @@ class ModuleStore(object):
"""
raise NotImplementedError
- def clone_item(self, source, location):
- """
- Clone a new item that is a copy of the item at the location `source`
- and writes it to `location`
- """
- raise NotImplementedError
-
- def update_item(self, location, data):
+ def update_item(self, location, data, allow_not_found=False):
"""
Set the data in the item specified by the location to
data
diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py
index f56393d75e..ae879ba3e8 100644
--- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py
+++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py
@@ -33,7 +33,7 @@ from xblock.runtime import DbModel, KeyValueStore, InvalidScopeError
from xblock.core import Scope
from xmodule.modulestore import ModuleStoreBase, Location, namedtuple_to_son
-from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateItemError
+from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.inheritance import own_metadata, INHERITABLE_METADATA, inherit_metadata
log = logging.getLogger(__name__)
@@ -62,11 +62,12 @@ class MongoKeyValueStore(KeyValueStore):
A KeyValueStore that maps keyed data access to one of the 3 data areas
known to the MongoModuleStore (data, children, and metadata)
"""
- def __init__(self, data, children, metadata, location):
+ def __init__(self, data, children, metadata, location, category):
self._data = data
self._children = children
self._metadata = metadata
self._location = location
+ self._category = category
def get(self, key):
if key.scope == Scope.children:
@@ -78,6 +79,8 @@ class MongoKeyValueStore(KeyValueStore):
elif key.scope == Scope.content:
if key.field_name == 'location':
return self._location
+ elif key.field_name == 'category':
+ return self._category
elif key.field_name == 'data' and not isinstance(self._data, dict):
return self._data
else:
@@ -93,6 +96,8 @@ class MongoKeyValueStore(KeyValueStore):
elif key.scope == Scope.content:
if key.field_name == 'location':
self._location = value
+ elif key.field_name == 'category':
+ self._category = value
elif key.field_name == 'data' and not isinstance(self._data, dict):
self._data = value
else:
@@ -100,6 +105,15 @@ class MongoKeyValueStore(KeyValueStore):
else:
raise InvalidScopeError(key.scope)
+ def set_many(self, update_dict):
+ """set_many method. Implementations should accept an `update_dict` of
+ key-value pairs, and set all the `keys` to the given `value`s."""
+ # `set` simply updates an in-memory db, rather than calling down to a real db,
+ # as mongo bulk save is handled elsewhere. A future improvement would be to pull
+ # the mongo-specific bulk save logic into this method.
+ for key, value in update_dict.iteritems():
+ self.set(key, value)
+
def delete(self, key):
if key.scope == Scope.children:
self._children = []
@@ -109,6 +123,8 @@ class MongoKeyValueStore(KeyValueStore):
elif key.scope == Scope.content:
if key.field_name == 'location':
self._location = Location(None)
+ elif key.field_name == 'category':
+ self._category = None
elif key.field_name == 'data' and not isinstance(self._data, dict):
self._data = None
else:
@@ -123,7 +139,10 @@ class MongoKeyValueStore(KeyValueStore):
return key.field_name in self._metadata
elif key.scope == Scope.content:
if key.field_name == 'location':
+ # WHY TRUE? if it's been deleted should it be False?
return True
+ elif key.field_name == 'category':
+ return self._category is not None
elif key.field_name == 'data' and not isinstance(self._data, dict):
return True
else:
@@ -185,8 +204,9 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
else:
# load the module and apply the inherited metadata
try:
+ category = json_data['location']['category']
class_ = XModuleDescriptor.load_class(
- json_data['location']['category'],
+ category,
self.default_class
)
definition = json_data.get('definition', {})
@@ -201,9 +221,12 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
definition.get('children', []),
metadata,
location,
+ category
)
model_data = DbModel(kvs, class_, None, MongoUsage(self.course_id, location))
+ model_data['category'] = category
+ model_data['location'] = location
module = class_(self, model_data)
if self.cached_metadata is not None:
# parent container pointers don't differentiate between draft and non-draft
@@ -217,6 +240,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
return ErrorDescriptor.from_json(
json_data,
self,
+ json_data['location'],
error_msg=exc_info_to_str(sys.exc_info())
)
@@ -582,51 +606,97 @@ class MongoModuleStore(ModuleStoreBase):
modules = self._load_items(list(items), depth)
return modules
- def clone_item(self, source, location):
+ def create_xmodule(self, location, definition_data=None, metadata=None, system=None):
"""
- Clone a new item that is a copy of the item at the location `source`
- and writes it to `location`
+ Create the new xmodule but don't save it. Returns the new module.
+
+ :param location: a Location--must have a category
+ :param definition_data: can be empty. The initial definition_data for the kvs
+ :param metadata: can be empty, the initial metadata for the kvs
+ :param system: if you already have an xmodule from the course, the xmodule.system value
"""
- item = None
- try:
- source_item = self.collection.find_one(location_to_query(source))
-
- # allow for some programmatically generated substitutions in metadata, e.g. Discussion_id's should be auto-generated
- for key in source_item['metadata'].keys():
- if source_item['metadata'][key] == '$$GUID$$':
- source_item['metadata'][key] = uuid4().hex
-
- source_item['_id'] = Location(location).dict()
- self.collection.insert(
- source_item,
- # Must include this to avoid the django debug toolbar (which defines the deprecated "safe=False")
- # from overriding our default value set in the init method.
- safe=self.collection.safe
+ if not isinstance(location, Location):
+ location = Location(location)
+ # differs from split mongo in that I believe most of this logic should be above the persistence
+ # layer but added it here to enable quick conversion. I'll need to reconcile these.
+ if metadata is None:
+ metadata = {}
+ if system is None:
+ system = CachingDescriptorSystem(
+ self,
+ {},
+ self.default_class,
+ None,
+ self.error_tracker,
+ self.render_template,
+ {}
)
- item = self._load_items([source_item])[0]
+ xblock_class = XModuleDescriptor.load_class(location.category, self.default_class)
+ if definition_data is None:
+ if hasattr(xblock_class, 'data') and getattr(xblock_class, 'data').default is not None:
+ definition_data = getattr(xblock_class, 'data').default
+ else:
+ definition_data = {}
+ dbmodel = self._create_new_model_data(location.category, location, definition_data, metadata)
+ xmodule = xblock_class(system, dbmodel)
+ return xmodule
- # VS[compat] cdodge: This is a hack because static_tabs also have references from the course module, so
- # if we add one then we need to also add it to the policy information (i.e. metadata)
- # we should remove this once we can break this reference from the course to static tabs
- if location.category == 'static_tab':
- course = self.get_course_for_item(item.location)
- existing_tabs = course.tabs or []
- existing_tabs.append({
- 'type': 'static_tab',
- 'name': item.display_name,
- 'url_slug': item.location.name
- })
- course.tabs = existing_tabs
- self.update_metadata(course.location, course._model_data._kvs._metadata)
-
- except pymongo.errors.DuplicateKeyError:
- raise DuplicateItemError(location)
+ def save_xmodule(self, xmodule):
+ """
+ Save the given xmodule (will either create or update based on whether id already exists).
+ Pulls out the data definition v metadata v children locally but saves it all.
+ :param xmodule:
+ """
+ # Save any changes to the xmodule to the MongoKeyValueStore
+ xmodule.save()
+ # split mongo's persist_dag is more general and useful.
+ self.collection.save({
+ '_id': xmodule.location.dict(),
+ 'metadata': own_metadata(xmodule),
+ 'definition': {
+ 'data': xmodule.xblock_kvs._data,
+ 'children': xmodule.children if xmodule.has_children else []
+ }
+ })
# recompute (and update) the metadata inheritance tree which is cached
- self.refresh_cached_metadata_inheritance_tree(Location(location))
- self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location))
+ self.refresh_cached_metadata_inheritance_tree(xmodule.location)
+ self.fire_updated_modulestore_signal(get_course_id_no_run(xmodule.location), xmodule.location)
- return item
+ def create_and_save_xmodule(self, location, definition_data=None, metadata=None, system=None):
+ """
+ Create the new xmodule and save it. Does not return the new module because if the caller
+ will insert it as a child, it's inherited metadata will completely change. The difference
+ between this and just doing create_xmodule and save_xmodule is this ensures static_tabs get
+ pointed to by the course.
+
+ :param location: a Location--must have a category
+ :param definition_data: can be empty. The initial definition_data for the kvs
+ :param metadata: can be empty, the initial metadata for the kvs
+ :param system: if you already have an xmodule from the course, the xmodule.system value
+ """
+ # differs from split mongo in that I believe most of this logic should be above the persistence
+ # layer but added it here to enable quick conversion. I'll need to reconcile these.
+ new_object = self.create_xmodule(location, definition_data, metadata, system)
+ location = new_object.location
+ self.save_xmodule(new_object)
+
+ # VS[compat] cdodge: This is a hack because static_tabs also have references from the course module, so
+ # if we add one then we need to also add it to the policy information (i.e. metadata)
+ # we should remove this once we can break this reference from the course to static tabs
+ # TODO move this special casing to app tier (similar to attaching new element to parent)
+ if location.category == 'static_tab':
+ course = self.get_course_for_item(location)
+ existing_tabs = course.tabs or []
+ existing_tabs.append({
+ 'type': 'static_tab',
+ 'name': new_object.display_name,
+ 'url_slug': new_object.location.name
+ })
+ course.tabs = existing_tabs
+ # Save any changes to the course to the MongoKeyValueStore
+ course.save()
+ self.update_metadata(course.location, course.xblock_kvs._metadata)
def fire_updated_modulestore_signal(self, course_id, location):
"""
@@ -683,7 +753,7 @@ class MongoModuleStore(ModuleStoreBase):
if result['n'] == 0:
raise ItemNotFoundError(location)
- def update_item(self, location, data):
+ def update_item(self, location, data, allow_not_found=False):
"""
Set the data in the item specified by the location to
data
@@ -691,8 +761,11 @@ class MongoModuleStore(ModuleStoreBase):
location: Something that can be passed to Location
data: A nested dictionary of problem data
"""
-
- self._update_single_item(location, {'definition.data': data})
+ try:
+ self._update_single_item(location, {'definition.data': data})
+ except ItemNotFoundError:
+ if not allow_not_found:
+ raise
def update_children(self, location, children):
"""
@@ -729,6 +802,8 @@ class MongoModuleStore(ModuleStoreBase):
tab['name'] = metadata.get('display_name')
break
course.tabs = existing_tabs
+ # Save the updates to the course to the MongoKeyValueStore
+ course.save()
self.update_metadata(course.location, own_metadata(course))
self._update_single_item(location, {'metadata': metadata})
@@ -751,6 +826,8 @@ class MongoModuleStore(ModuleStoreBase):
course = self.get_course_for_item(item.location)
existing_tabs = course.tabs or []
course.tabs = [tab for tab in existing_tabs if tab.get('url_slug') != location.name]
+ # Save the updates to the course to the MongoKeyValueStore
+ course.save()
self.update_metadata(course.location, own_metadata(course))
# Must include this to avoid the django debug toolbar (which defines the deprecated "safe=False")
@@ -775,3 +852,24 @@ class MongoModuleStore(ModuleStoreBase):
are loaded on demand, rather than up front
"""
return {}
+
+ def _create_new_model_data(self, category, location, definition_data, metadata):
+ """
+ To instantiate a new xmodule which will be saved latter, set up the dbModel and kvs
+ """
+ kvs = MongoKeyValueStore(
+ definition_data,
+ [],
+ metadata,
+ location,
+ category
+ )
+
+ class_ = XModuleDescriptor.load_class(
+ category,
+ self.default_class
+ )
+ model_data = DbModel(kvs, class_, None, MongoUsage(None, location))
+ model_data['category'] = category
+ model_data['location'] = location
+ return model_data
diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/draft.py b/common/lib/xmodule/xmodule/modulestore/mongo/draft.py
index f34c3a53f9..d289e03739 100644
--- a/common/lib/xmodule/xmodule/modulestore/mongo/draft.py
+++ b/common/lib/xmodule/xmodule/modulestore/mongo/draft.py
@@ -8,11 +8,12 @@ and otherwise returns i4x://org/course/cat/name).
from datetime import datetime
-from xmodule.modulestore import Location, namedtuple_to_son
-from xmodule.modulestore.exceptions import ItemNotFoundError
-from xmodule.modulestore.inheritance import own_metadata
from xmodule.exceptions import InvalidVersionError
-from xmodule.modulestore.mongo.base import MongoModuleStore
+from xmodule.modulestore import Location, namedtuple_to_son
+from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateItemError
+from xmodule.modulestore.inheritance import own_metadata
+from xmodule.modulestore.mongo.base import location_to_query, get_course_id_no_run, MongoModuleStore
+import pymongo
from pytz import UTC
DRAFT = 'draft'
@@ -92,6 +93,21 @@ class DraftModuleStore(MongoModuleStore):
except ItemNotFoundError:
return wrap_draft(super(DraftModuleStore, self).get_instance(course_id, location, depth=depth))
+ def create_xmodule(self, location, definition_data=None, metadata=None, system=None):
+ """
+ Create the new xmodule but don't save it. Returns the new module with a draft locator
+
+ :param location: a Location--must have a category
+ :param definition_data: can be empty. The initial definition_data for the kvs
+ :param metadata: can be empty, the initial metadata for the kvs
+ :param system: if you already have an xmodule from the course, the xmodule.system value
+ """
+ draft_loc = as_draft(location)
+ if draft_loc.category in DIRECT_ONLY_CATEGORIES:
+ raise InvalidVersionError(location)
+ return super(DraftModuleStore, self).create_xmodule(draft_loc, definition_data, metadata, system)
+
+
def get_items(self, location, course_id=None, depth=0):
"""
Returns a list of XModuleDescriptor instances for the items
@@ -119,14 +135,26 @@ class DraftModuleStore(MongoModuleStore):
]
return [wrap_draft(item) for item in draft_items + non_draft_items]
- def clone_item(self, source, location):
+ def convert_to_draft(self, source_location):
"""
- Clone a new item that is a copy of the item at the location `source`
- and writes it to `location`
+ Create a copy of the source and mark its revision as draft.
+
+ :param source: the location of the source (its revision must be None)
"""
- if Location(location).category in DIRECT_ONLY_CATEGORIES:
- raise InvalidVersionError(location)
- return wrap_draft(super(DraftModuleStore, self).clone_item(source, as_draft(location)))
+ original = self.collection.find_one(location_to_query(source_location))
+ draft_location = as_draft(source_location)
+ if draft_location.category in DIRECT_ONLY_CATEGORIES:
+ raise InvalidVersionError(source_location)
+ original['_id'] = draft_location.dict()
+ try:
+ self.collection.insert(original)
+ except pymongo.errors.DuplicateKeyError:
+ raise DuplicateItemError(original['_id'])
+
+ self.refresh_cached_metadata_inheritance_tree(draft_location)
+ self.fire_updated_modulestore_signal(get_course_id_no_run(draft_location), draft_location)
+
+ return self._load_items([original])[0]
def update_item(self, location, data, allow_not_found=False):
"""
@@ -140,7 +168,7 @@ class DraftModuleStore(MongoModuleStore):
try:
draft_item = self.get_item(location)
if not getattr(draft_item, 'is_draft', False):
- self.clone_item(location, draft_loc)
+ self.convert_to_draft(location)
except ItemNotFoundError, e:
if not allow_not_found:
raise e
@@ -158,7 +186,7 @@ class DraftModuleStore(MongoModuleStore):
draft_loc = as_draft(location)
draft_item = self.get_item(location)
if not getattr(draft_item, 'is_draft', False):
- self.clone_item(location, draft_loc)
+ self.convert_to_draft(location)
return super(DraftModuleStore, self).update_children(draft_loc, children)
@@ -174,7 +202,7 @@ class DraftModuleStore(MongoModuleStore):
draft_item = self.get_item(location)
if not getattr(draft_item, 'is_draft', False):
- self.clone_item(location, draft_loc)
+ self.convert_to_draft(location)
if 'is_draft' in metadata:
del metadata['is_draft']
@@ -218,9 +246,7 @@ class DraftModuleStore(MongoModuleStore):
"""
Turn the published version into a draft, removing the published version
"""
- if Location(location).category in DIRECT_ONLY_CATEGORIES:
- raise InvalidVersionError(location)
- super(DraftModuleStore, self).clone_item(location, as_draft(location))
+ self.convert_to_draft(location)
super(DraftModuleStore, self).delete_item(location)
def _query_children_for_cache_children(self, items):
diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
index 6c5c1f66ca..4f998d57fb 100644
--- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
+++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
@@ -5,7 +5,6 @@ from django.test import TestCase
from django.conf import settings
import xmodule.modulestore.django
-from xmodule.templates import update_templates
from unittest.util import safe_repr
@@ -48,7 +47,7 @@ def draft_mongo_store_config(data_dir):
return {
'default': {
- 'ENGINE': 'xmodule.modulestore.mongo.DraftMongoModuleStore',
+ 'ENGINE': 'xmodule.modulestore.mongo.draft.DraftModuleStore',
'OPTIONS': modulestore_options
},
'direct': {
@@ -110,22 +109,6 @@ class ModuleStoreTestCase(TestCase):
modulestore.collection.remove(query)
modulestore.collection.drop()
- @staticmethod
- def load_templates_if_necessary():
- """
- Load templates into the direct modulestore only if they do not already exist.
- We need the templates, because they are copied to create
- XModules such as sections and problems.
- """
- modulestore = xmodule.modulestore.django.modulestore('direct')
-
- # Count the number of templates
- query = {"_id.course": "templates"}
- num_templates = modulestore.collection.find(query).count()
-
- if num_templates < 1:
- update_templates(modulestore)
-
@classmethod
def setUpClass(cls):
"""
@@ -169,9 +152,6 @@ class ModuleStoreTestCase(TestCase):
# Flush anything that is not a template
ModuleStoreTestCase.flush_mongo_except_templates()
- # Check that we have templates loaded; if not, load them
- ModuleStoreTestCase.load_templates_if_necessary()
-
# Call superclass implementation
super(ModuleStoreTestCase, self)._pre_setup()
@@ -185,34 +165,31 @@ class ModuleStoreTestCase(TestCase):
# Call superclass implementation
super(ModuleStoreTestCase, self)._post_teardown()
+
def assert2XX(self, status_code, msg=None):
"""
Assert that the given value is a success status (between 200 and 299)
"""
- if not 200 <= status_code < 300:
- msg = self._formatMessage(msg, "%s is not a success status" % safe_repr(status_code))
- raise self.failureExecption(msg)
+ msg = self._formatMessage(msg, "%s is not a success status" % safe_repr(status_code))
+ self.assertTrue(status_code >= 200 and status_code < 300, msg=msg)
def assert3XX(self, status_code, msg=None):
"""
Assert that the given value is a redirection status (between 300 and 399)
"""
- if not 300 <= status_code < 400:
- msg = self._formatMessage(msg, "%s is not a redirection status" % safe_repr(status_code))
- raise self.failureExecption(msg)
+ msg = self._formatMessage(msg, "%s is not a redirection status" % safe_repr(status_code))
+ self.assertTrue(status_code >= 300 and status_code < 400, msg=msg)
def assert4XX(self, status_code, msg=None):
"""
Assert that the given value is a client error status (between 400 and 499)
"""
- if not 400 <= status_code < 500:
- msg = self._formatMessage(msg, "%s is not a client error status" % safe_repr(status_code))
- raise self.failureExecption(msg)
+ msg = self._formatMessage(msg, "%s is not a client error status" % safe_repr(status_code))
+ self.assertTrue(status_code >= 400 and status_code < 500, msg=msg)
def assert5XX(self, status_code, msg=None):
"""
Assert that the given value is a server error status (between 500 and 599)
"""
- if not 500 <= status_code < 600:
- msg = self._formatMessage(msg, "%s is not a server error status" % safe_repr(status_code))
- raise self.failureExecption(msg)
+ msg = self._formatMessage(msg, "%s is not a server error status" % safe_repr(status_code))
+ self.assertTrue(status_code >= 500 and status_code < 600, msg=msg)
diff --git a/common/lib/xmodule/xmodule/modulestore/tests/factories.py b/common/lib/xmodule/xmodule/modulestore/tests/factories.py
index 457a88482a..8c3b5d59dd 100644
--- a/common/lib/xmodule/xmodule/modulestore/tests/factories.py
+++ b/common/lib/xmodule/xmodule/modulestore/tests/factories.py
@@ -1,15 +1,14 @@
-from factory import Factory, lazy_attribute_sequence, lazy_attribute
-from uuid import uuid4
import datetime
+from factory import Factory, LazyAttributeSequence
+from uuid import uuid4
+from pytz import UTC
+
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.inheritance import own_metadata
-from xmodule.x_module import ModuleSystem
-from mitxmako.shortcuts import render_to_string
-from xblock.runtime import InvalidScopeError
-from pytz import UTC
-
+from xmodule.course_module import CourseDescriptor
+from xblock.core import Scope
+from xmodule.x_module import XModuleDescriptor
class XModuleCourseFactory(Factory):
"""
@@ -21,9 +20,8 @@ class XModuleCourseFactory(Factory):
@classmethod
def _create(cls, target_class, **kwargs):
- template = Location('i4x', 'edx', 'templates', 'course', 'Empty')
org = kwargs.pop('org', None)
- number = kwargs.pop('number', None)
+ number = kwargs.pop('number', kwargs.pop('course', None))
display_name = kwargs.pop('display_name', None)
location = Location('i4x', org, number, 'course', Location.clean(display_name))
@@ -33,13 +31,13 @@ class XModuleCourseFactory(Factory):
store = modulestore()
# Write the data to the mongo datastore
- new_course = store.clone_item(template, location)
+ new_course = store.create_xmodule(location)
# This metadata code was copied from cms/djangoapps/contentstore/views.py
if display_name is not None:
new_course.display_name = display_name
- new_course.lms.start = datetime.datetime.now(UTC)
+ new_course.lms.start = datetime.datetime.now(UTC).replace(microsecond=0)
new_course.tabs = kwargs.pop(
'tabs',
[
@@ -56,13 +54,7 @@ class XModuleCourseFactory(Factory):
setattr(new_course, k, v)
# Update the data in the mongo datastore
- store.update_metadata(new_course.location, own_metadata(new_course))
- store.update_item(new_course.location, new_course._model_data._kvs._data)
-
- # update_item updates the the course as it exists in the modulestore, but doesn't
- # update the instance we are working with, so have to refetch the course after updating it.
- new_course = store.get_instance(new_course.id, new_course.location)
-
+ store.save_xmodule(new_course)
return new_course
@@ -73,7 +65,6 @@ class Course:
class CourseFactory(XModuleCourseFactory):
FACTORY_FOR = Course
- template = 'i4x://edx/templates/course/Empty'
org = 'MITx'
number = '999'
display_name = 'Robot Super Course'
@@ -86,76 +77,71 @@ class XModuleItemFactory(Factory):
ABSTRACT_FACTORY = True
- display_name = None
+ parent_location = 'i4x://MITx/999/course/Robot_Super_Course'
+ category = 'problem'
+ display_name = LazyAttributeSequence(lambda o, n: "{} {}".format(o.category, n))
- @lazy_attribute
- def category(attr):
- template = Location(attr.template)
- return template.category
-
- @lazy_attribute
- def location(attr):
- parent = Location(attr.parent_location)
- dest_name = attr.display_name.replace(" ", "_") if attr.display_name is not None else uuid4().hex
- return parent._replace(category=attr.category, name=dest_name)
+ @staticmethod
+ def location(parent, category, display_name):
+ dest_name = display_name.replace(" ", "_") if display_name is not None else uuid4().hex
+ return Location(parent).replace(category=category, name=dest_name)
@classmethod
def _create(cls, target_class, **kwargs):
"""
- Uses *kwargs*:
+ Uses ``**kwargs``:
- *parent_location* (required): the location of the parent module
+ :parent_location: (required): the location of the parent module
(e.g. the parent course or section)
- *template* (required): the template to create the item from
- (e.g. i4x://templates/section/Empty)
+ :category: the category of the resulting item.
- *data* (optional): the data for the item
+ :data: (optional): the data for the item
(e.g. XML problem definition for a problem item)
- *display_name* (optional): the display name of the item
+ :display_name: (optional): the display name of the item
- *metadata* (optional): dictionary of metadata attributes
+ :metadata: (optional): dictionary of metadata attributes
- *target_class* is ignored
+ :boilerplate: (optional) the boilerplate for overriding field values
+
+ :target_class: is ignored
"""
DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info']
-
+ # catch any old style users before they get into trouble
+ assert not 'template' in kwargs
parent_location = Location(kwargs.get('parent_location'))
- template = Location(kwargs.get('template'))
data = kwargs.get('data')
+ category = kwargs.get('category')
display_name = kwargs.get('display_name')
metadata = kwargs.get('metadata', {})
+ location = kwargs.get('location', XModuleItemFactory.location(parent_location, category, display_name))
+ assert location != parent_location
+ if kwargs.get('boilerplate') is not None:
+ template_id = kwargs.get('boilerplate')
+ clz = XModuleDescriptor.load_class(category)
+ template = clz.get_template(template_id)
+ assert template is not None
+ metadata.update(template.get('metadata', {}))
+ if not isinstance(data, basestring):
+ data.update(template.get('data'))
store = modulestore('direct')
# This code was based off that in cms/djangoapps/contentstore/views.py
parent = store.get_item(parent_location)
- new_item = store.clone_item(template, kwargs.get('location'))
-
# replace the display name with an optional parameter passed in from the caller
if display_name is not None:
- new_item.display_name = display_name
+ metadata['display_name'] = display_name
+ store.create_and_save_xmodule(location, metadata=metadata, definition_data=data)
- # Add additional metadata or override current metadata
- item_metadata = own_metadata(new_item)
- item_metadata.update(metadata)
- store.update_metadata(new_item.location.url(), item_metadata)
+ if location.category not in DETACHED_CATEGORIES:
+ parent.children.append(location.url())
+ store.update_children(parent_location, parent.children)
- # replace the data with the optional *data* parameter
- if data is not None:
- store.update_item(new_item.location, data)
-
- if new_item.location.category not in DETACHED_CATEGORIES:
- store.update_children(parent_location, parent.children + [new_item.location.url()])
-
- # update_children updates the the item as it exists in the modulestore, but doesn't
- # update the instance we are working with, so have to refetch the item after updating it.
- new_item = store.get_item(new_item.location)
-
- return new_item
+ return store.get_item(location)
class Item:
@@ -164,40 +150,4 @@ class Item:
class ItemFactory(XModuleItemFactory):
FACTORY_FOR = Item
-
- parent_location = 'i4x://MITx/999/course/Robot_Super_Course'
- template = 'i4x://edx/templates/chapter/Empty'
-
- @lazy_attribute_sequence
- def display_name(attr, n):
- return "{} {}".format(attr.category.title(), n)
-
-
-def get_test_xmodule_for_descriptor(descriptor):
- """
- Attempts to create an xmodule which responds usually correctly from the descriptor. Not guaranteed.
-
- :param descriptor:
- """
- module_sys = ModuleSystem(
- ajax_url='',
- track_function=None,
- get_module=None,
- render_template=render_to_string,
- replace_urls=None,
- xblock_model_data=_test_xblock_model_data_accessor(descriptor)
- )
- return descriptor.xmodule(module_sys)
-
-
-def _test_xblock_model_data_accessor(descriptor):
- simple_map = {}
- for field in descriptor.fields:
- try:
- simple_map[field.name] = getattr(descriptor, field.name)
- except InvalidScopeError:
- simple_map[field.name] = field.default
- for field in descriptor.module_class.fields:
- if field.name not in simple_map:
- simple_map[field.name] = field.default
- return lambda o: simple_map
+ category = 'chapter'
diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
index 44e69fb0ed..c149724cc7 100644
--- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
+++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
@@ -9,7 +9,6 @@ from xblock.runtime import KeyValueStore, InvalidScopeError
from xmodule.modulestore import Location
from xmodule.modulestore.mongo import MongoModuleStore, MongoKeyValueStore
from xmodule.modulestore.xml_importer import import_from_xml
-from xmodule.templates import update_templates
from .test_modulestore import check_path_to_location
from . import DATA_DIR
@@ -51,7 +50,6 @@ class TestMongoModuleStore(object):
# Explicitly list the courses to load (don't want the big one)
courses = ['toy', 'simple']
import_from_xml(store, DATA_DIR, courses)
- update_templates(store)
return store
@staticmethod
@@ -126,7 +124,7 @@ class TestMongoKeyValueStore(object):
self.location = Location('i4x://org/course/category/name@version')
self.children = ['i4x://org/course/child/a', 'i4x://org/course/child/b']
self.metadata = {'meta': 'meta_val'}
- self.kvs = MongoKeyValueStore(self.data, self.children, self.metadata, self.location)
+ self.kvs = MongoKeyValueStore(self.data, self.children, self.metadata, self.location, 'category')
def _check_read(self, key, expected_value):
assert_equals(expected_value, self.kvs.get(key))
diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py
index 26c8b9bfca..8bc3142c77 100644
--- a/common/lib/xmodule/xmodule/modulestore/xml.py
+++ b/common/lib/xmodule/xmodule/modulestore/xml.py
@@ -194,6 +194,10 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
if hasattr(descriptor, 'children'):
for child in descriptor.get_children():
parent_tracker.add_parent(child.location, descriptor.location)
+
+ # After setting up the descriptor, save any changes that we have
+ # made to attributes on the descriptor to the underlying KeyValueStore.
+ descriptor.save()
return descriptor
render_template = lambda: ''
@@ -463,7 +467,10 @@ class XMLModuleStore(ModuleStoreBase):
# tabs are referenced in policy.json through a 'slug' which is just the filename without the .html suffix
slug = os.path.splitext(os.path.basename(filepath))[0]
loc = Location('i4x', course_descriptor.location.org, course_descriptor.location.course, category, slug)
- module = HtmlDescriptor(system, {'data': html, 'location': loc})
+ module = HtmlDescriptor(
+ system,
+ {'data': html, 'location': loc, 'category': category}
+ )
# VS[compat]:
# Hack because we need to pull in the 'display_name' for static tabs (because we need to edit them)
# from the course policy
diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py
index 1fe62035e6..933eb0b5bb 100644
--- a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py
+++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py
@@ -78,37 +78,7 @@ class CombinedOpenEndedV1Module():
instance_state=None, shared_state=None, metadata=None, static_data=None, **kwargs):
"""
- Definition file should have one or many task blocks, a rubric block, and a prompt block:
-
- Sample file:
-
-
- Blah blah rubric.
-
-
- Some prompt.
-
-
-
-
- What hint about this problem would you give to someone?
-
-
- Save Succcesful. Thanks for participating!
-
-
-
-
-
-
- Enter essay here.
- This is the answer.
- {"grader_settings" : "ml_grading.conf",
- "problem_id" : "6.002x/Welcome/OETest"}
-
-
-
-
+ Definition file should have one or many task blocks, a rubric block, and a prompt block. See DEFAULT_DATA in combined_open_ended_module for a sample.
"""
@@ -131,14 +101,14 @@ class CombinedOpenEndedV1Module():
# Allow reset is true if student has failed the criteria to move to the next child task
self.ready_to_reset = instance_state.get('ready_to_reset', False)
- self.attempts = self.instance_state.get('attempts', MAX_ATTEMPTS)
- self.is_scored = self.instance_state.get('is_graded', IS_SCORED) in TRUE_DICT
- self.accept_file_upload = self.instance_state.get('accept_file_upload', ACCEPT_FILE_UPLOAD) in TRUE_DICT
- self.skip_basic_checks = self.instance_state.get('skip_spelling_checks', SKIP_BASIC_CHECKS) in TRUE_DICT
+ self.max_attempts = instance_state.get('max_attempts', MAX_ATTEMPTS)
+ self.is_scored = instance_state.get('graded', IS_SCORED) in TRUE_DICT
+ self.accept_file_upload = instance_state.get('accept_file_upload', ACCEPT_FILE_UPLOAD) in TRUE_DICT
+ self.skip_basic_checks = instance_state.get('skip_spelling_checks', SKIP_BASIC_CHECKS) in TRUE_DICT
- due_date = self.instance_state.get('due', None)
+ due_date = instance_state.get('due', None)
- grace_period_string = self.instance_state.get('graceperiod', None)
+ grace_period_string = instance_state.get('graceperiod', None)
try:
self.timeinfo = TimeInfo(due_date, grace_period_string)
except Exception:
@@ -153,7 +123,7 @@ class CombinedOpenEndedV1Module():
# Static data is passed to the child modules to render
self.static_data = {
'max_score': self._max_score,
- 'max_attempts': self.attempts,
+ 'max_attempts': self.max_attempts,
'prompt': definition['prompt'],
'rubric': definition['rubric'],
'display_name': self.display_name,
@@ -643,15 +613,18 @@ class CombinedOpenEndedV1Module():
if not self.ready_to_reset:
return self.out_of_sync_error(data)
- if self.student_attempts > self.attempts:
+ if self.student_attempts >= self.max_attempts-1:
+ if self.student_attempts==self.max_attempts-1:
+ self.student_attempts +=1
return {
'success': False,
# This is a student_facing_error
'error': (
'You have attempted this question {0} times. '
'You are only allowed to attempt it {1} times.'
- ).format(self.student_attempts, self.attempts)
+ ).format(self.student_attempts, self.max_attempts)
}
+ self.student_attempts +=1
self.state = self.INITIAL
self.ready_to_reset = False
for i in xrange(0, len(self.task_xml)):
@@ -726,7 +699,12 @@ class CombinedOpenEndedV1Module():
"""
max_score = None
score = None
- if self.is_scored and self.weight is not None:
+
+ #The old default was None, so set to 1 if it is the old default weight
+ weight = self.weight
+ if weight is None:
+ weight = 1
+ if self.is_scored:
# Finds the maximum score of all student attempts and keeps it.
score_mat = []
for i in xrange(0, len(self.task_states)):
@@ -739,7 +717,7 @@ class CombinedOpenEndedV1Module():
for z in xrange(0, len(score)):
if score[z] is None:
score[z] = 0
- score[z] *= float(self.weight)
+ score[z] *= float(weight)
score_mat.append(score)
if len(score_mat) > 0:
@@ -753,7 +731,7 @@ class CombinedOpenEndedV1Module():
if max_score is not None:
# Weight the max score if it is not None
- max_score *= float(self.weight)
+ max_score *= float(weight)
else:
# Without a max_score, we cannot have a score!
score = None
@@ -810,7 +788,6 @@ class CombinedOpenEndedV1Descriptor():
filename_extension = "xml"
has_score = True
- template_dir_name = "combinedopenended"
def __init__(self, system):
self.system = system
diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py
index 0f0851fbf7..8d8a85f788 100644
--- a/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py
+++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py
@@ -730,7 +730,6 @@ class OpenEndedDescriptor():
filename_extension = "xml"
has_score = True
- template_dir_name = "openended"
def __init__(self, system):
self.system = system
diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/self_assessment_module.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/self_assessment_module.py
index a5498289e2..1262e1f68f 100644
--- a/common/lib/xmodule/xmodule/open_ended_grading_classes/self_assessment_module.py
+++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/self_assessment_module.py
@@ -287,7 +287,6 @@ class SelfAssessmentDescriptor():
filename_extension = "xml"
has_score = True
- template_dir_name = "selfassessment"
def __init__(self, system):
self.system = system
diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py
index 7df444a892..09cac9a6b4 100644
--- a/common/lib/xmodule/xmodule/peer_grading_module.py
+++ b/common/lib/xmodule/xmodule/peer_grading_module.py
@@ -9,6 +9,7 @@ from .capa_module import ComplexEncoder
from .x_module import XModule
from xmodule.raw_module import RawDescriptor
from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.exceptions import ItemNotFoundError
from .timeinfo import TimeInfo
from xblock.core import Dict, String, Scope, Boolean, Integer, Float
from xmodule.fields import Date
@@ -19,36 +20,37 @@ from django.utils.timezone import UTC
log = logging.getLogger(__name__)
-USE_FOR_SINGLE_LOCATION = False
-LINK_TO_LOCATION = ""
-MAX_SCORE = 1
-IS_GRADED = False
EXTERNAL_GRADER_NO_CONTACT_ERROR = "Failed to contact external graders. Please notify course staff."
-
class PeerGradingFields(object):
use_for_single_location = Boolean(
display_name="Show Single Problem",
help='When True, only the single problem specified by "Link to Problem Location" is shown. '
'When False, a panel is displayed with all problems available for peer grading.',
- default=USE_FOR_SINGLE_LOCATION, scope=Scope.settings
+ default=False,
+ scope=Scope.settings
)
link_to_location = String(
display_name="Link to Problem Location",
help='The location of the problem being graded. Only used when "Show Single Problem" is True.',
- default=LINK_TO_LOCATION, scope=Scope.settings
+ default="",
+ scope=Scope.settings
)
- is_graded = Boolean(
+ graded = Boolean(
display_name="Graded",
help='Defines whether the student gets credit for grading this problem. Only used when "Show Single Problem" is True.',
- default=IS_GRADED, scope=Scope.settings
+ default=False,
+ scope=Scope.settings
)
- due_date = Date(help="Due date that should be displayed.", default=None, scope=Scope.settings)
- grace_period_string = String(help="Amount of grace to give on the due date.", default=None, scope=Scope.settings)
- max_grade = Integer(
- help="The maximum grade that a student can receive for this problem.", default=MAX_SCORE,
- scope=Scope.settings, values={"min": 0}
+ due = Date(
+ help="Due date that should be displayed.",
+ default=None,
+ scope=Scope.settings)
+ grace_period_string = String(
+ help="Amount of grace to give on the due date.",
+ default=None,
+ scope=Scope.settings
)
student_data_for_location = Dict(
help="Student data for a given peer grading problem.",
@@ -57,8 +59,18 @@ class PeerGradingFields(object):
weight = Float(
display_name="Problem Weight",
help="Defines the number of points each problem is worth. If the value is not set, each problem is worth one point.",
- scope=Scope.settings, values={"min": 0, "step": ".1"}
+ scope=Scope.settings, values={"min": 0, "step": ".1"},
+ default=1
)
+ display_name = String(
+ display_name="Display Name",
+ help="Display name for this module",
+ scope=Scope.settings,
+ default="Peer Grading Interface"
+ )
+ data = String(help="Html contents to display for this module",
+ default='',
+ scope=Scope.content)
class PeerGradingModule(PeerGradingFields, XModule):
@@ -89,35 +101,31 @@ class PeerGradingModule(PeerGradingFields, XModule):
if self.use_for_single_location:
try:
self.linked_problem = modulestore().get_instance(self.system.course_id, self.link_to_location)
- except:
+ except ItemNotFoundError:
log.error("Linked location {0} for peer grading module {1} does not exist".format(
self.link_to_location, self.location))
raise
- due_date = self.linked_problem._model_data.get('peer_grading_due', None)
+ due_date = self.linked_problem._model_data.get('due', None)
if due_date:
self._model_data['due'] = due_date
try:
- self.timeinfo = TimeInfo(self.due_date, self.grace_period_string)
- except:
- log.error("Error parsing due date information in location {0}".format(location))
+ self.timeinfo = TimeInfo(self.due, self.grace_period_string)
+ except Exception:
+ log.error("Error parsing due date information in location {0}".format(self.location))
raise
self.display_due_date = self.timeinfo.display_due_date
try:
self.student_data_for_location = json.loads(self.student_data_for_location)
- except:
+ except Exception:
pass
self.ajax_url = self.system.ajax_url
if not self.ajax_url.endswith("/"):
self.ajax_url = self.ajax_url + "/"
- # Integer could return None, so keep this check.
- if not isinstance(self.max_grade, int):
- raise TypeError("max_grade needs to be an integer.")
-
def closed(self):
return self._closed(self.timeinfo)
@@ -201,11 +209,16 @@ class PeerGradingModule(PeerGradingFields, XModule):
def get_score(self):
max_score = None
score = None
+ weight = self.weight
+
+ #The old default was None, so set to 1 if it is the old default weight
+ if weight is None:
+ weight = 1
score_dict = {
'score': score,
'total': max_score,
}
- if not self.use_for_single_location or not self.is_graded:
+ if not self.use_for_single_location or not self.graded:
return score_dict
try:
@@ -225,11 +238,10 @@ class PeerGradingModule(PeerGradingFields, XModule):
# Ensures that once a student receives a final score for peer grading, that it does not change.
self.student_data_for_location = response
- if self.weight is not None:
- score = int(count_graded >= count_required and count_graded > 0) * float(self.weight)
- total = self.max_grade * float(self.weight)
- score_dict['score'] = score
- score_dict['total'] = total
+ score = int(count_graded >= count_required and count_graded > 0) * float(weight)
+ total = float(weight)
+ score_dict['score'] = score
+ score_dict['total'] = total
return score_dict
@@ -240,8 +252,8 @@ class PeerGradingModule(PeerGradingFields, XModule):
randomization, and 5/7 on another
'''
max_grade = None
- if self.use_for_single_location and self.is_graded:
- max_grade = self.max_grade
+ if self.use_for_single_location and self.graded:
+ max_grade = self.weight
return max_grade
def get_next_submission(self, data):
@@ -521,7 +533,7 @@ class PeerGradingModule(PeerGradingFields, XModule):
problem_location = problem['location']
descriptor = _find_corresponding_module_for_location(problem_location)
if descriptor:
- problem['due'] = descriptor._model_data.get('peer_grading_due', None)
+ problem['due'] = descriptor._model_data.get('due', None)
grace_period_string = descriptor._model_data.get('graceperiod', None)
try:
problem_timeinfo = TimeInfo(problem['due'], grace_period_string)
@@ -604,14 +616,18 @@ class PeerGradingDescriptor(PeerGradingFields, RawDescriptor):
has_score = True
always_recalculate_grades = True
- template_dir_name = "peer_grading"
#Specify whether or not to pass in open ended interface
needs_open_ended_interface = True
+ metadata_translations = {
+ 'is_graded': 'graded',
+ 'attempts': 'max_attempts',
+ 'due_data' : 'due'
+ }
+
@property
def non_editable_metadata_fields(self):
non_editable_fields = super(PeerGradingDescriptor, self).non_editable_metadata_fields
- non_editable_fields.extend([PeerGradingFields.due_date, PeerGradingFields.grace_period_string,
- PeerGradingFields.max_grade])
+ non_editable_fields.extend([PeerGradingFields.due, PeerGradingFields.grace_period_string])
return non_editable_fields
diff --git a/common/lib/xmodule/xmodule/poll_module.py b/common/lib/xmodule/xmodule/poll_module.py
index ca12f239ab..8e7407752a 100644
--- a/common/lib/xmodule/xmodule/poll_module.py
+++ b/common/lib/xmodule/xmodule/poll_module.py
@@ -140,7 +140,6 @@ class PollDescriptor(PollFields, MakoModuleDescriptor, XmlDescriptor):
_child_tag_name = 'answer'
module_class = PollModule
- template_dir_name = 'poll'
@classmethod
def definition_from_xml(cls, xml_object, system):
diff --git a/common/lib/xmodule/xmodule/raw_module.py b/common/lib/xmodule/xmodule/raw_module.py
index 554be73926..4c6c719224 100644
--- a/common/lib/xmodule/xmodule/raw_module.py
+++ b/common/lib/xmodule/xmodule/raw_module.py
@@ -13,7 +13,7 @@ class RawDescriptor(XmlDescriptor, XMLEditingDescriptor):
Module that provides a raw editing view of its data and children. It
requires that the definition xml is valid.
"""
- data = String(help="XML data for the module", scope=Scope.content)
+ data = String(help="XML data for the module", default="", scope=Scope.content)
@classmethod
def definition_from_xml(cls, xml_object, system):
diff --git a/common/lib/xmodule/xmodule/templates.py b/common/lib/xmodule/xmodule/templates.py
index 6479b3df24..8e350bb618 100644
--- a/common/lib/xmodule/xmodule/templates.py
+++ b/common/lib/xmodule/xmodule/templates.py
@@ -1,34 +1,18 @@
"""
-This module handles loading xmodule templates from disk into the modulestore.
-These templates are used by the CMS to provide baseline content that
-can be cloned when adding new modules to a course.
+This module handles loading xmodule templates
+These templates are used by the CMS to provide content that overrides xmodule defaults for
+samples.
-`Template`s are defined in x_module. They contain 3 attributes:
- metadata: A dictionary with the template metadata. This should contain
- any values for fields
- * with scope Scope.settings
- * that have values different than the field defaults
- * and that are to be editable in Studio
- data: A JSON value that defines the template content. This should be a dictionary
- containing values for fields
- * with scope Scope.content
- * that have values different than the field defaults
- * and that are to be editable in Studio
- or, if the module uses a single Scope.content String field named `data`, this
- should be a string containing the contents of that field
- children: A list of Location urls that define the template children
-
-Templates are defined on XModuleDescriptor types, in the template attribute.
+``Template``s are defined in x_module. They contain 2 attributes:
+ :metadata: A dictionary with the template metadata
+ :data: A JSON value that defines the template content
"""
-
+# should this move to cms since it's really only for module crud?
import logging
-from fs.memoryfs import MemoryFS
from collections import defaultdict
from .x_module import XModuleDescriptor
-from .mako_module import MakoDescriptorSystem
-from .modulestore import Location
log = logging.getLogger(__name__)
@@ -37,73 +21,9 @@ def all_templates():
"""
Returns all templates for enabled modules, grouped by descriptor type
"""
-
+ # TODO use memcache to memoize w/ expiration
templates = defaultdict(list)
for category, descriptor in XModuleDescriptor.load_classes():
templates[category] = descriptor.templates()
return templates
-
-
-class TemplateTestSystem(MakoDescriptorSystem):
- """
- This system exists to help verify that XModuleDescriptors can be instantiated
- from their defined templates before we load the templates into the modulestore.
- """
- def __init__(self):
- super(TemplateTestSystem, self).__init__(
- lambda *a, **k: None,
- MemoryFS(),
- lambda msg: None,
- render_template=lambda *a, **k: None,
- )
-
-
-def update_templates(modulestore):
- """
- Updates the set of templates in the modulestore with all templates currently
- available from the installed plugins
- """
-
- # cdodge: build up a list of all existing templates. This will be used to determine which
- # templates have been removed from disk - and thus we need to remove from the DB
- templates_to_delete = modulestore.get_items(['i4x', 'edx', 'templates', None, None, None])
-
- for category, templates in all_templates().items():
- for template in templates:
- if 'display_name' not in template.metadata:
- log.warning('No display_name specified in template {0}, skipping'.format(template))
- continue
-
- template_location = Location('i4x', 'edx', 'templates', category, Location.clean_for_url_name(template.metadata['display_name']))
-
- try:
- json_data = {
- 'definition': {
- 'data': template.data,
- 'children': template.children
- },
- 'metadata': template.metadata
- }
- json_data['location'] = template_location.dict()
-
- XModuleDescriptor.load_from_json(json_data, TemplateTestSystem())
- except:
- log.warning('Unable to instantiate {cat} from template {template}, skipping'.format(
- cat=category,
- template=template
- ), exc_info=True)
- continue
-
- modulestore.update_item(template_location, template.data)
- modulestore.update_children(template_location, template.children)
- modulestore.update_metadata(template_location, template.metadata)
-
- # remove template from list of templates to delete
- templates_to_delete = [t for t in templates_to_delete if t.location != template_location]
-
- # now remove all templates which appear to have removed from disk
- if len(templates_to_delete) > 0:
- logging.debug('deleting dangling templates = {0}'.format(templates_to_delete))
- for template in templates_to_delete:
- modulestore.delete_item(template.location)
diff --git a/common/lib/xmodule/xmodule/templates/about/empty.yaml b/common/lib/xmodule/xmodule/templates/about/empty.yaml
deleted file mode 100644
index fa3ed606bd..0000000000
--- a/common/lib/xmodule/xmodule/templates/about/empty.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-metadata:
- display_name: Empty
-data: "
This is where you can add additional information about your course.
"
-children: []
\ No newline at end of file
diff --git a/common/lib/xmodule/xmodule/templates/about/overview.yaml b/common/lib/xmodule/xmodule/templates/about/overview.yaml
index 0031ebffaf..9b2e895526 100644
--- a/common/lib/xmodule/xmodule/templates/about/overview.yaml
+++ b/common/lib/xmodule/xmodule/templates/about/overview.yaml
@@ -3,51 +3,50 @@ metadata:
display_name: overview
data: |
-
-
About This Course
-
Include your long course description here. The long course description should contain 150-400 words.
+
+
About This Course
+
Include your long course description here. The long course description should contain 150-400 words.
-
This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.
-
+
This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.
+
-
-
Prerequisites
-
Add information about course prerequisites here.
-
+
+
Prerequisites
+
Add information about course prerequisites here.
+
-
-
Course Staff
-
-
-
-
+
+
Course Staff
+
+
+
+
-
Staff Member #1
-
Biography of instructor/staff member #1
-
+
Staff Member #1
+
Biography of instructor/staff member #1
+
-
-
-
-
+
+
+
+
-
Staff Member #2
-
Biography of instructor/staff member #2
-
-
+
Staff Member #2
+
Biography of instructor/staff member #2
+
+
-
-
-
Frequently Asked Questions
-
-
Do I need to buy a textbook?
-
No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.
-
+
+
+
Frequently Asked Questions
+
+
Do I need to buy a textbook?
+
No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.
Enter your (optional) instructions for the exercise in HTML format.
-
Annotations are specified by an <annotation> tag which may may have the following attributes:
-
-
title (optional). Title of the annotation. Defaults to Commentary if omitted.
-
body (required). Text of the annotation.
-
problem (optional). Numeric index of the problem associated with this annotation. This is a zero-based index, so the first problem on the page would have problem="0".
-
highlight (optional). Possible values: yellow, red, orange, green, blue, or purple. Defaults to yellow if this attribute is omitted.
-
-
-
Add your HTML with annotation spans here.
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sodales laoreet est, egestas gravida felis egestas nec. Aenean at volutpat erat. Cras commodo viverra nibh in aliquam.
-
Nulla facilisi. Pellentesque id vestibulum libero. Suspendisse potenti. Morbi scelerisque nisi vitae felis dictum mattis. Nam sit amet magna elit. Nullam volutpat cursus est, sit amet sagittis odio vulputate et. Curabitur euismod, orci in vulputate imperdiet, augue lorem tempor purus, id aliquet augue turpis a est. Aenean a sagittis libero. Praesent fringilla pretium magna, non condimentum risus elementum nec. Pellentesque faucibus elementum pharetra. Pellentesque vitae metus eros.
-
-
-
-
-
-
-
- Enter essay here.
- This is the answer.
- {"grader_settings" : "peer_grading.conf", "problem_id" : "700x/Demo"}
-
-
-
-
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/course/empty.yaml b/common/lib/xmodule/xmodule/templates/course/empty.yaml
deleted file mode 100644
index 89f1bfcf21..0000000000
--- a/common/lib/xmodule/xmodule/templates/course/empty.yaml
+++ /dev/null
@@ -1,124 +0,0 @@
----
-metadata:
- display_name: Empty
- start: 2020-10-10T10:00
- checklists: [
- {"short_description" : "Getting Started With Studio",
- "items" : [{"short_description": "Add Course Team Members",
- "long_description": "Grant your collaborators permission to edit your course so you can work together.",
- "is_checked": false,
- "action_url": "ManageUsers",
- "action_text": "Edit Course Team",
- "action_external": false},
- {"short_description": "Set Important Dates for Your Course",
- "long_description": "Establish your course's student enrollment and launch dates on the Schedule and Details page.",
- "is_checked": false,
- "action_url": "SettingsDetails",
- "action_text": "Edit Course Details & Schedule",
- "action_external": false},
- {"short_description": "Draft Your Course's Grading Policy",
- "long_description": "Set up your assignment types and grading policy even if you haven't created all your assignments.",
- "is_checked": false,
- "action_url": "SettingsGrading",
- "action_text": "Edit Grading Settings",
- "action_external": false},
- {"short_description": "Explore the Other Studio Checklists",
- "long_description": "Discover other available course authoring tools, and find help when you need it.",
- "is_checked": false,
- "action_url": "",
- "action_text": "",
- "action_external": false}]
- },
- {"short_description" : "Draft a Rough Course Outline",
- "items" : [{"short_description": "Create Your First Section and Subsection",
- "long_description": "Use your course outline to build your first Section and Subsection.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false},
- {"short_description": "Set Section Release Dates",
- "long_description": "Specify the release dates for each Section in your course. Sections become visible to students on their release dates.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false},
- {"short_description": "Designate a Subsection as Graded",
- "long_description": "Set a Subsection to be graded as a specific assignment type. Assignments within graded Subsections count toward a student's final grade.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false},
- {"short_description": "Reordering Course Content",
- "long_description": "Use drag and drop to reorder the content in your course.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false},
- {"short_description": "Renaming Sections",
- "long_description": "Rename Sections by clicking the Section name from the Course Outline.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false},
- {"short_description": "Deleting Course Content",
- "long_description": "Delete Sections, Subsections, or Units you don't need anymore. Be careful, as there is no Undo function.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false},
- {"short_description": "Add an Instructor-Only Section to Your Outline",
- "long_description": "Some course authors find using a section for unsorted, in-progress work useful. To do this, create a section and set the release date to the distant future.",
- "is_checked": false,
- "action_url": "CourseOutline",
- "action_text": "Edit Course Outline",
- "action_external": false}]
- },
- {"short_description" : "Explore edX's Support Tools",
- "items" : [{"short_description": "Explore the Studio Help Forum",
- "long_description": "Access the Studio Help forum from the menu that appears when you click your user name in the top right corner of Studio.",
- "is_checked": false,
- "action_url": "http://help.edge.edx.org/",
- "action_text": "Visit Studio Help",
- "action_external": true},
- {"short_description": "Enroll in edX 101",
- "long_description": "Register for edX 101, edX's primer for course creation.",
- "is_checked": false,
- "action_url": "https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about",
- "action_text": "Register for edX 101",
- "action_external": true},
- {"short_description": "Download the Studio Documentation",
- "long_description": "Download the searchable Studio reference documentation in PDF form.",
- "is_checked": false,
- "action_url": "http://files.edx.org/Getting_Started_with_Studio.pdf",
- "action_text": "Download Documentation",
- "action_external": true}]
- },
- {"short_description" : "Draft Your Course About Page",
- "items" : [{"short_description": "Draft a Course Description",
- "long_description": "Courses on edX have an About page that includes a course video, description, and more. Draft the text students will read before deciding to enroll in your course.",
- "is_checked": false,
- "action_url": "SettingsDetails",
- "action_text": "Edit Course Schedule & Details",
- "action_external": false},
- {"short_description": "Add Staff Bios",
- "long_description": "Showing prospective students who their instructor will be is helpful. Include staff bios on the course About page.",
- "is_checked": false,
- "action_url": "SettingsDetails",
- "action_text": "Edit Course Schedule & Details",
- "action_external": false},
- {"short_description": "Add Course FAQs",
- "long_description": "Include a short list of frequently asked questions about your course.",
- "is_checked": false,
- "action_url": "SettingsDetails",
- "action_text": "Edit Course Schedule & Details",
- "action_external": false},
- {"short_description": "Add Course Prerequisites",
- "long_description": "Let students know what knowledge and/or skills they should have before they enroll in your course.",
- "is_checked": false,
- "action_url": "SettingsDetails",
- "action_text": "Edit Course Schedule & Details",
- "action_external": false}]
- }
- ]
-data: { 'textbooks' : [ ], 'wiki_slug' : null }
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/courseinfo/empty.yaml b/common/lib/xmodule/xmodule/templates/courseinfo/empty.yaml
deleted file mode 100644
index c6958ed887..0000000000
--- a/common/lib/xmodule/xmodule/templates/courseinfo/empty.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-metadata:
- display_name: Empty
-data: ""
-children: []
\ No newline at end of file
diff --git a/common/lib/xmodule/xmodule/templates/default/empty.yaml b/common/lib/xmodule/xmodule/templates/default/empty.yaml
deleted file mode 100644
index a2fb2b5832..0000000000
--- a/common/lib/xmodule/xmodule/templates/default/empty.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-metadata:
- display_name: Empty
-data: ""
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/discussion/default.yaml b/common/lib/xmodule/xmodule/templates/discussion/default.yaml
deleted file mode 100644
index 049e34b3e7..0000000000
--- a/common/lib/xmodule/xmodule/templates/discussion/default.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
----
-metadata:
- display_name: Discussion Tag
- for: Topic-Level Student-Visible Label
- id: $$GUID$$
- discussion_category: Week 1
-data: |
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/html/announcement.yaml b/common/lib/xmodule/xmodule/templates/html/announcement.yaml
index 82fe8fbc03..c0ecc61524 100644
--- a/common/lib/xmodule/xmodule/templates/html/announcement.yaml
+++ b/common/lib/xmodule/xmodule/templates/html/announcement.yaml
@@ -1,7 +1,6 @@
---
metadata:
- display_name: Announcement
-
+ display_name: Announcement
data: |
@@ -22,4 +21,3 @@ data: |
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/html/empty.yaml b/common/lib/xmodule/xmodule/templates/html/empty.yaml
deleted file mode 100644
index 40b005af28..0000000000
--- a/common/lib/xmodule/xmodule/templates/html/empty.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-metadata:
- display_name: Blank HTML Page
-
-data: |
-
-children: []
\ No newline at end of file
diff --git a/common/lib/xmodule/xmodule/templates/html/everything.yaml b/common/lib/xmodule/xmodule/templates/html/everything.yaml
deleted file mode 100644
index 348ce64fa1..0000000000
--- a/common/lib/xmodule/xmodule/templates/html/everything.yaml
+++ /dev/null
@@ -1,33 +0,0 @@
----
-metadata:
- display_name: Announcement
-
-data: |
-
Heading of document
-
First subheading
-
This is a paragraph. It will take care of line breaks for you.
HTML only parses the location
-
- of tags for inserting line breaks into your doc, not
- line
- breaks
- you
- add
- yourself.
-
-
Links
-
You can refer to other parts of the internet with a link, to other parts of your course by prepending your link with /course/
-
Now a list:
-
-
An item
-
Another item
-
And yet another
-
-
This list has an ordering
-
-
An item
-
Another item
-
Yet another item
-
-
Note, we have a lot of standard edX styles, so please try to avoid any custom styling, and make sure that you make a note of any custom styling that you do yourself so that we can incorporate it into
- tools that other people can use.
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/html/latex_html.yaml b/common/lib/xmodule/xmodule/templates/html/latex_html.yaml
index ff92f2aead..2db7e98c65 100644
--- a/common/lib/xmodule/xmodule/templates/html/latex_html.yaml
+++ b/common/lib/xmodule/xmodule/templates/html/latex_html.yaml
@@ -1,16 +1,16 @@
---
metadata:
display_name: E-text Written in LaTeX
- source_code: |
- \subsection{Example of E-text in LaTeX}
+source_code: |
+ \subsection{Example of E-text in LaTeX}
- It is very convenient to write complex equations in LaTeX.
+ It is very convenient to write complex equations in LaTeX.
- \begin{equation}
- x = \frac{-b\pm\sqrt{b^2-4*a*c}}{2a}
- \end{equation}
+ \begin{equation}
+ x = \frac{-b\pm\sqrt{b^2-4*a*c}}{2a}
+ \end{equation}
- Seize the moment.
+ Seize the moment.
data: |
@@ -19,4 +19,3 @@ data: |
It is very convenient to write complex equations in LaTeX.
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/peer_grading/default.yaml b/common/lib/xmodule/xmodule/templates/peer_grading/default.yaml
deleted file mode 100644
index 5d88a18ad8..0000000000
--- a/common/lib/xmodule/xmodule/templates/peer_grading/default.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
----
-metadata:
- display_name: Peer Grading Interface
- max_grade: 1
-data: |
-
-
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/blank_common.yaml b/common/lib/xmodule/xmodule/templates/problem/blank_common.yaml
new file mode 100644
index 0000000000..3dcac29aba
--- /dev/null
+++ b/common/lib/xmodule/xmodule/templates/problem/blank_common.yaml
@@ -0,0 +1,5 @@
+---
+metadata:
+ display_name: Blank Common Problem
+ markdown: ""
+data: ""
diff --git a/common/lib/xmodule/xmodule/templates/problem/circuitschematic.yaml b/common/lib/xmodule/xmodule/templates/problem/circuitschematic.yaml
index 56f802a6a3..051dfe1912 100644
--- a/common/lib/xmodule/xmodule/templates/problem/circuitschematic.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/circuitschematic.yaml
@@ -1,63 +1,60 @@
-
---
metadata:
display_name: Circuit Schematic Builder
- rerandomize: never
- showanswer: finished
+ markdown: !!null
data: |
-
- Please make a voltage divider that splits the provided voltage evenly.
-
-
-
-
-
-
- dc_value = "dc analysis not found"
- for response in submission[0]:
- if response[0] == 'dc':
- for node in response[1:]:
- dc_value = node['output']
-
- if dc_value == .5:
- correct = ['correct']
- else:
- correct = ['incorrect']
-
-
-
-
Make a high pass filter
-
-
-
-
- ac_values = None
- for response in submission[0]:
- if response[0] == 'ac':
- for node in response[1:]:
- ac_values = node['NodeA']
- print "the ac analysis value:", ac_values
- if ac_values == None:
- correct = ['incorrect']
- elif ac_values[0][1] < ac_values[1][1]:
- correct = ['correct']
- else:
- correct = ['incorrect']
-
-
-
-
-
-
Explanation
-
A voltage divider that evenly divides the input voltage can be formed with two identically valued resistors, with the sampled voltage taken in between the two.
-
-
A simple high-pass filter without any further constaints can be formed by simply putting a resister in series with a capacitor. The actual values of the components do not really matter in order to meet the constraints of the problem.
-
-
-
-
-children: []
+
+ Please make a voltage divider that splits the provided voltage evenly.
+
+
+
+
+
+
+ dc_value = "dc analysis not found"
+ for response in submission[0]:
+ if response[0] == 'dc':
+ for node in response[1:]:
+ dc_value = node['output']
+
+ if dc_value == .5:
+ correct = ['correct']
+ else:
+ correct = ['incorrect']
+
+
+
+
Make a high pass filter
+
+
+
+
+ ac_values = None
+ for response in submission[0]:
+ if response[0] == 'ac':
+ for node in response[1:]:
+ ac_values = node['NodeA']
+ print "the ac analysis value:", ac_values
+ if ac_values == None:
+ correct = ['incorrect']
+ elif ac_values[0][1] < ac_values[1][1]:
+ correct = ['correct']
+ else:
+ correct = ['incorrect']
+
+
+
+
+
+
Explanation
+
A voltage divider that evenly divides the input voltage can be formed with two identically valued resistors, with the sampled voltage taken in between the two.
+
+
A simple high-pass filter without any further constaints can be formed by simply putting a resister in series with a capacitor. The actual values of the components do not really matter in order to meet the constraints of the problem.
- A custom python-evaluated input problem accepts one or more lines of text input from the
- student, and evaluates the inputs for correctness based on evaluation using a
- python script embedded within the problem.
-
+
+
+ A custom python-evaluated input problem accepts one or more lines of text input from the
+ student, and evaluates the inputs for correctness based on evaluation using a
+ python script embedded within the problem.
+
-
+
-
Enter two integers which sum to 10:
-
-
-
-
+
Enter two integers which sum to 10:
+
+
+
+
-
Enter two integers which sum to 20:
-
-
-
-
-
-
-
-
Explanation
-
Any set of integers on the line \(y = 10 - x\) and \(y = 20 - x\) satisfy these constraints.
-
-
-
-
-
-children: []
+
Enter two integers which sum to 20:
+
+
+
+
+
+
+
+
Explanation
+
Any set of integers on the line \(y = 10 - x\) and \(y = 20 - x\) satisfy these constraints.
+
+
+
+
diff --git a/common/lib/xmodule/xmodule/templates/problem/drag_and_drop.yaml b/common/lib/xmodule/xmodule/templates/problem/drag_and_drop.yaml
new file mode 100644
index 0000000000..678b75716b
--- /dev/null
+++ b/common/lib/xmodule/xmodule/templates/problem/drag_and_drop.yaml
@@ -0,0 +1,41 @@
+---
+metadata:
+ display_name: Drag and Drop
+ markdown: !!null
+data: |
+
+ Here's an example of a "Drag and Drop" question set. Click and drag each word in the scrollbar below, up to the numbered bucket which matches the number of letters in the word.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ correct_answer = {
+ '1': [[70, 150], 121],
+ '6': [[190, 150], 121],
+ '8': [[190, 150], 121],
+ '2': [[310, 150], 121],
+ '9': [[310, 150], 121],
+ '11': [[310, 150], 121],
+ '4': [[420, 150], 121],
+ '7': [[420, 150], 121],
+ '3': [[550, 150], 121],
+ '5': [[550, 150], 121],
+ '10': [[550, 150], 121]}
+ if draganddrop.grade(submission[0], correct_answer):
+ correct = ['correct']
+ else:
+ correct = ['incorrect']
+
+
+
diff --git a/common/lib/xmodule/xmodule/templates/problem/empty.yaml b/common/lib/xmodule/xmodule/templates/problem/empty.yaml
deleted file mode 100644
index 97a2aef423..0000000000
--- a/common/lib/xmodule/xmodule/templates/problem/empty.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
----
-metadata:
- display_name: Blank Common Problem
- rerandomize: never
- showanswer: finished
- markdown: ""
-data: |
-
-
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/emptyadvanced.yaml b/common/lib/xmodule/xmodule/templates/problem/emptyadvanced.yaml
deleted file mode 100644
index 3d696ec2fd..0000000000
--- a/common/lib/xmodule/xmodule/templates/problem/emptyadvanced.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
----
-metadata:
- display_name: Blank Advanced Problem
- rerandomize: never
- showanswer: finished
-data: |
-
-
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/forumularesponse.yaml b/common/lib/xmodule/xmodule/templates/problem/forumularesponse.yaml
index 0401a01c31..807a7833e4 100644
--- a/common/lib/xmodule/xmodule/templates/problem/forumularesponse.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/forumularesponse.yaml
@@ -1,8 +1,7 @@
---
metadata:
display_name: Math Expression Input
- rerandomize: never
- showanswer: finished
+ markdown: !!null
data: |
- An image mapped input problem presents an image for the student. Input is
- given by the location of mouse clicks on the image. Correctness of input can be evaluated based on expected dimensions of a rectangle.
-
-
-
Which object in this image is required by the fire code?
-
-
-
-
-
-
Explanation
-
The fire code requires that all exits be clearly marked, so the red exit sign is the correct answer.
-
-
+
+ An image mapped input problem presents an image for the student.
+ Input is given by the location of mouse clicks on the image.
+ Correctness of input can be evaluated based on expected dimensions of a rectangle.
+
+
Which animal shown below is a kitten?
+
+
+
+
+
+
Explanation
+
The animal on the right is a kitten. The animal on the left is a puppy, not a kitten.
+
+
-
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml b/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml
index 82d7e8c1ae..097055cfe3 100644
--- a/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml
@@ -85,6 +85,7 @@ metadata:
can contain equations: $\alpha = \frac{2}{\sqrt{1+\gamma}}$ }
This is some text after the showhide example.
+ markdown: !!null
data: |
@@ -214,4 +215,3 @@ data: |
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml b/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml
index 10d51de280..68845564d5 100644
--- a/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml
@@ -1,35 +1,25 @@
---
metadata:
display_name: Multiple Choice
- rerandomize: never
- showanswer: finished
- markdown:
- "A multiple choice problem presents radio buttons for student input. Students can only select a single
+ markdown: |
+ A multiple choice problem presents radio buttons for student input. Students can only select a single
option presented. Multiple Choice questions have been the subject of many areas of research due to the early
invention and adoption of bubble sheets.
-
One of the main elements that goes into a good multiple choice question is the existence of good distractors.
That is, each of the alternate responses presented to the student should be the result of a plausible mistake
that a student might make.
-
What Apple device competed with the portable CD player?
-
( ) The iPad
-
( ) Napster
-
(x) The iPod
-
( ) The vegetable peeler
-
[explanation]
The release of the iPod allowed consumers to carry their entire music library with them in a
format that did not rely on fragile and energy-intensive spinning disks.
[explanation]
- "
data: |
@@ -54,4 +44,3 @@ data: |
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml b/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml
index 548fd94fab..e97a54b460 100644
--- a/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml
@@ -1,45 +1,33 @@
---
metadata:
display_name: Numerical Input
- rerandomize: never
- showanswer: finished
- markdown:
- "A numerical input problem accepts a line of text input from the
+ markdown: |
+ A numerical input problem accepts a line of text input from the
student, and evaluates the input for correctness based on its
numerical value.
-
The answer is correct if it is within a specified numerical tolerance
of the expected answer.
-
Enter the numerical value of Pi:
-
= 3.14159 +- .02
-
Enter the approximate value of 502*9:
-
= 4518 +- 15%
-
-
+
Enter the number of fingers on a human hand:
-
= 5
-
[explanation]
Pi, or the the ratio between a circle's circumference to its diameter, is an irrational number
known to extreme precision. It is value is approximately equal to 3.14.
-
+
Although you can get an exact value by typing 502*9 into a calculator, the result will be close to
500*10, or 5,000. The grader accepts any response within 15% of the true value, 4518, so that you
can use any estimation technique that you like.
-
+
If you look at your hand, you can count that you have five fingers.
[explanation]
- "
-
data: |
@@ -83,5 +71,3 @@ data: |
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml b/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml
index c2edfb1cbc..44af7a850a 100644
--- a/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml
@@ -1,21 +1,16 @@
---
metadata:
display_name: Dropdown
- rerandomize: never
- showanswer: finished
- markdown:
- "Dropdown problems give a limited set of options for students to respond with, and present those options
+ markdown: |
+ Dropdown problems give a limited set of options for students to respond with, and present those options
in a format that encourages them to search for a specific answer rather than being immediately presented
with options from which to recognize the correct answer.
-
The answer options and the identification of the correct answer is defined in the optioninput tag.
-
Translation between Dropdown and __________ is extremely straightforward:
-
- [[(Multiple Choice), Text Input, Numerical Input, External Response, Image Response]]
+ [[(Multiple Choice), Text Input, Numerical Input, External Response, Image Response]]
[explanation]
Multiple Choice also allows students to select from a variety of pre-written responses, although the
@@ -23,7 +18,6 @@ metadata:
slightly because students are more likely to think of an answer and then search for it rather than
relying purely on recognition to answer the question.
[explanation]
- "
data: |
Dropdown problems give a limited set of options for students to respond with, and present those options
@@ -45,4 +39,3 @@ data: |
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/problem_with_hint.yaml b/common/lib/xmodule/xmodule/templates/problem/problem_with_hint.yaml
index 73a94ed941..aa1000a93a 100644
--- a/common/lib/xmodule/xmodule/templates/problem/problem_with_hint.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/problem_with_hint.yaml
@@ -46,9 +46,8 @@ metadata:
enter your answer in upper or lower case, with or without quotes.
\edXabox{type="custom" cfn='test_str' expect='python' hintfn='hint_fn'}
-
+ markdown: !!null
data: |
-
@@ -92,4 +91,3 @@ data: |
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/problem/string_response.yaml b/common/lib/xmodule/xmodule/templates/problem/string_response.yaml
index 64e3dc062f..cf95fe8331 100644
--- a/common/lib/xmodule/xmodule/templates/problem/string_response.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/string_response.yaml
@@ -1,18 +1,13 @@
---
metadata:
display_name: Text Input
- rerandomize: never
- showanswer: finished
- # Note, the extra newlines are needed to make the yaml parser add blank lines instead of folding
- markdown:
- "A text input problem accepts a line of text from the
+ markdown: |
+ A text input problem accepts a line of text from the
student, and evaluates the input for correctness based on an expected
answer.
-
The answer is correct if it matches every character of the expected answer. This can be a problem with
international spelling, dates, or anything where the format of the answer is not clear.
-
Which US state has Lansing as its capital?
@@ -23,9 +18,8 @@ metadata:
Lansing is the capital of Michigan, although it is not Michgan's largest city,
or even the seat of the county in which it resides.
[explanation]
- "
data: |
-
+
A text input problem accepts a line of text from the
@@ -46,4 +40,3 @@ data: |
This is where you can add additional pages to your courseware. Click the 'edit' button to begin editing.
"
-children: []
\ No newline at end of file
diff --git a/common/lib/xmodule/xmodule/templates/video/default.yaml b/common/lib/xmodule/xmodule/templates/video/default.yaml
deleted file mode 100644
index 048e7396c7..0000000000
--- a/common/lib/xmodule/xmodule/templates/video/default.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-metadata:
- display_name: default
-data: ""
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/videoalpha/default.yaml b/common/lib/xmodule/xmodule/templates/videoalpha/default.yaml
deleted file mode 100644
index 1c25b272a3..0000000000
--- a/common/lib/xmodule/xmodule/templates/videoalpha/default.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
----
-metadata:
- display_name: Video Alpha
- version: 1
-data: |
-
-
-
-
-
-children: []
diff --git a/common/lib/xmodule/xmodule/templates/word_cloud/default.yaml b/common/lib/xmodule/xmodule/templates/word_cloud/default.yaml
deleted file mode 100644
index 53e9eeaae4..0000000000
--- a/common/lib/xmodule/xmodule/templates/word_cloud/default.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-metadata:
- display_name: Word cloud
-data: {}
-children: []
diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py
index 1e84174291..0f3dfa5b85 100644
--- a/common/lib/xmodule/xmodule/tests/test_capa_module.py
+++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py
@@ -636,10 +636,10 @@ class CapaModuleTest(unittest.TestCase):
# Expect that the problem was reset
module.new_lcp.assert_called_once_with(None)
- module.choose_new_seed.assert_called_once_with()
def test_reset_problem_closed(self):
- module = CapaFactory.create()
+ # pre studio default
+ module = CapaFactory.create(rerandomize="always")
# Simulate that the problem is closed
with patch('xmodule.capa_module.CapaModule.closed') as mock_closed:
@@ -900,13 +900,13 @@ class CapaModuleTest(unittest.TestCase):
module = CapaFactory.create(done=False)
self.assertFalse(module.should_show_reset_button())
- # Otherwise, DO show the reset button
- module = CapaFactory.create(done=True)
+ # pre studio default value, DO show the reset button
+ module = CapaFactory.create(rerandomize="always", done=True)
self.assertTrue(module.should_show_reset_button())
# If survey question for capa (max_attempts = 0),
# DO show the reset button
- module = CapaFactory.create(max_attempts=0, done=True)
+ module = CapaFactory.create(rerandomize="always", max_attempts=0, done=True)
self.assertTrue(module.should_show_reset_button())
def test_should_show_save_button(self):
@@ -940,8 +940,8 @@ class CapaModuleTest(unittest.TestCase):
module = CapaFactory.create(max_attempts=None, rerandomize="per_student", done=True)
self.assertFalse(module.should_show_save_button())
- # Otherwise, DO show the save button
- module = CapaFactory.create(done=False)
+ # pre-studio default, DO show the save button
+ module = CapaFactory.create(rerandomize="always", done=False)
self.assertTrue(module.should_show_save_button())
# If we're not randomizing and we have limited attempts, then we can save
diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
index e1f8d135de..8162d588bb 100644
--- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
+++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
@@ -335,7 +335,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
's3_interface': test_util_open_ended.S3_INTERFACE,
'open_ended_grading_interface': test_util_open_ended.OPEN_ENDED_GRADING_INTERFACE,
'skip_basic_checks': False,
- 'is_graded': True,
+ 'graded': True,
}
oeparam = etree.XML('''
@@ -453,7 +453,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
self.assertFalse(changed)
def test_get_score_realistic(self):
- instance_state = r"""{"ready_to_reset": false, "skip_spelling_checks": true, "current_task_number": 1, "weight": 5.0, "graceperiod": "1 day 12 hours 59 minutes 59 seconds", "is_graded": "True", "task_states": ["{\"child_created\": false, \"child_attempts\": 4, \"version\": 1, \"child_history\": [{\"answer\": \"The students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the group\\u2019s procedure, describe what additional information you would need in order to replicate the expe\", \"post_assessment\": \"{\\\"submission_id\\\": 3097, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: More grammar errors than average.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"the students data are recorded in the table below . starting mass g ending mass g difference in mass g marble . . . limestone . . . wood . . . plastic . . . after reading the groups procedure , describe what additional information you would need in order to replicate the expe\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3233, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"After 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the\", \"post_assessment\": \"[3]\", \"score\": 3}, {\"answer\": \"To replicate the experiment, the procedure would require more detail. One piece of information that is omitted is the amount of vinegar used in the experiment. It is also important to know what temperature the experiment was kept at during the 24 hours. Finally, the procedure needs to include details about the experiment, for example if the whole sample must be submerged.\", \"post_assessment\": \"[3]\", \"score\": 3}, {\"answer\": \"e the mass of four different samples.\\r\\nPour vinegar in each of four separate, but identical, containers.\\r\\nPlace a sample of one material into one container and label. Repeat with remaining samples, placing a single sample into a single container.\\r\\nAfter 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\", \"post_assessment\": \"[3]\", \"score\": 3}, {\"answer\": \"\", \"post_assessment\": \"[3]\", \"score\": 3}], \"max_score\": 3, \"child_state\": \"done\"}", "{\"child_created\": false, \"child_attempts\": 0, \"version\": 1, \"child_history\": [{\"answer\": \"The students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the group\\u2019s procedure, describe what additional information you would need in order to replicate the expe\", \"post_assessment\": \"{\\\"submission_id\\\": 3097, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: More grammar errors than average.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"the students data are recorded in the table below . starting mass g ending mass g difference in mass g marble . . . limestone . . . wood . . . plastic . . . after reading the groups procedure , describe what additional information you would need in order to replicate the expe\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3233, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"After 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the\", \"post_assessment\": \"{\\\"submission_id\\\": 3098, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"after hours , remove the samples from the containers and rinse each sample with distilled water . allow the samples to sit and dry for minutes . determine the mass of each sample . the students data are recorded in the table below . starting mass g ending mass g difference in mass g marble . . . limestone . . . wood . . . plastic . . . after reading the\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3235, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"To replicate the experiment, the procedure would require more detail. One piece of information that is omitted is the amount of vinegar used in the experiment. It is also important to know what temperature the experiment was kept at during the 24 hours. Finally, the procedure needs to include details about the experiment, for example if the whole sample must be submerged.\", \"post_assessment\": \"{\\\"submission_id\\\": 3099, \\\"score\\\": 3, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"to replicate the experiment , the procedure would require more detail . one piece of information that is omitted is the amount of vinegar used in the experiment . it is also important to know what temperature the experiment was kept at during the hours . finally , the procedure needs to include details about the experiment , for example if the whole sample must be submerged .\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3237, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality3\\\"}\", \"score\": 3}, {\"answer\": \"e the mass of four different samples.\\r\\nPour vinegar in each of four separate, but identical, containers.\\r\\nPlace a sample of one material into one container and label. Repeat with remaining samples, placing a single sample into a single container.\\r\\nAfter 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\", \"post_assessment\": \"{\\\"submission_id\\\": 3100, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"e the mass of four different samples . pour vinegar in each of four separate , but identical , containers . place a sample of one material into one container and label . repeat with remaining samples , placing a single sample into a single container . after hours , remove the samples from the containers and rinse each sample with distilled water . allow the samples to sit and dry for minutes . determine the mass of each sample . the students data are recorded in the table below . \\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3239, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"\", \"post_assessment\": \"{\\\"submission_id\\\": 3101, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"invalid essay .\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3241, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}], \"max_score\": 3, \"child_state\": \"done\"}"], "attempts": "10000", "student_attempts": 0, "due": null, "state": "done", "accept_file_upload": false, "display_name": "Science Question -- Machine Assessed"}"""
+ instance_state = r"""{"ready_to_reset": false, "skip_spelling_checks": true, "current_task_number": 1, "weight": 5.0, "graceperiod": "1 day 12 hours 59 minutes 59 seconds", "graded": "True", "task_states": ["{\"child_created\": false, \"child_attempts\": 4, \"version\": 1, \"child_history\": [{\"answer\": \"The students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the group\\u2019s procedure, describe what additional information you would need in order to replicate the expe\", \"post_assessment\": \"{\\\"submission_id\\\": 3097, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: More grammar errors than average.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"the students data are recorded in the table below . starting mass g ending mass g difference in mass g marble . . . limestone . . . wood . . . plastic . . . after reading the groups procedure , describe what additional information you would need in order to replicate the expe\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3233, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"After 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the\", \"post_assessment\": \"[3]\", \"score\": 3}, {\"answer\": \"To replicate the experiment, the procedure would require more detail. One piece of information that is omitted is the amount of vinegar used in the experiment. It is also important to know what temperature the experiment was kept at during the 24 hours. Finally, the procedure needs to include details about the experiment, for example if the whole sample must be submerged.\", \"post_assessment\": \"[3]\", \"score\": 3}, {\"answer\": \"e the mass of four different samples.\\r\\nPour vinegar in each of four separate, but identical, containers.\\r\\nPlace a sample of one material into one container and label. Repeat with remaining samples, placing a single sample into a single container.\\r\\nAfter 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\", \"post_assessment\": \"[3]\", \"score\": 3}, {\"answer\": \"\", \"post_assessment\": \"[3]\", \"score\": 3}], \"max_score\": 3, \"child_state\": \"done\"}", "{\"child_created\": false, \"child_attempts\": 0, \"version\": 1, \"child_history\": [{\"answer\": \"The students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the group\\u2019s procedure, describe what additional information you would need in order to replicate the expe\", \"post_assessment\": \"{\\\"submission_id\\\": 3097, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: More grammar errors than average.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"the students data are recorded in the table below . starting mass g ending mass g difference in mass g marble . . . limestone . . . wood . . . plastic . . . after reading the groups procedure , describe what additional information you would need in order to replicate the expe\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3233, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"After 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\\r\\nStarting Mass (g)\\tEnding Mass (g)\\tDifference in Mass (g)\\r\\nMarble\\t 9.8\\t 9.4\\t\\u20130.4\\r\\nLimestone\\t10.4\\t 9.1\\t\\u20131.3\\r\\nWood\\t11.2\\t11.2\\t 0.0\\r\\nPlastic\\t 7.2\\t 7.1\\t\\u20130.1\\r\\nAfter reading the\", \"post_assessment\": \"{\\\"submission_id\\\": 3098, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"after hours , remove the samples from the containers and rinse each sample with distilled water . allow the samples to sit and dry for minutes . determine the mass of each sample . the students data are recorded in the table below . starting mass g ending mass g difference in mass g marble . . . limestone . . . wood . . . plastic . . . after reading the\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3235, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"To replicate the experiment, the procedure would require more detail. One piece of information that is omitted is the amount of vinegar used in the experiment. It is also important to know what temperature the experiment was kept at during the 24 hours. Finally, the procedure needs to include details about the experiment, for example if the whole sample must be submerged.\", \"post_assessment\": \"{\\\"submission_id\\\": 3099, \\\"score\\\": 3, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"to replicate the experiment , the procedure would require more detail . one piece of information that is omitted is the amount of vinegar used in the experiment . it is also important to know what temperature the experiment was kept at during the hours . finally , the procedure needs to include details about the experiment , for example if the whole sample must be submerged .\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3237, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality3\\\"}\", \"score\": 3}, {\"answer\": \"e the mass of four different samples.\\r\\nPour vinegar in each of four separate, but identical, containers.\\r\\nPlace a sample of one material into one container and label. Repeat with remaining samples, placing a single sample into a single container.\\r\\nAfter 24 hours, remove the samples from the containers and rinse each sample with distilled water.\\r\\nAllow the samples to sit and dry for 30 minutes.\\r\\nDetermine the mass of each sample.\\r\\nThe students\\u2019 data are recorded in the table below.\\r\\n\", \"post_assessment\": \"{\\\"submission_id\\\": 3100, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"e the mass of four different samples . pour vinegar in each of four separate , but identical , containers . place a sample of one material into one container and label . repeat with remaining samples , placing a single sample into a single container . after hours , remove the samples from the containers and rinse each sample with distilled water . allow the samples to sit and dry for minutes . determine the mass of each sample . the students data are recorded in the table below . \\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3239, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}, {\"answer\": \"\", \"post_assessment\": \"{\\\"submission_id\\\": 3101, \\\"score\\\": 0, \\\"feedback\\\": \\\"{\\\\\\\"spelling\\\\\\\": \\\\\\\"Spelling: Ok.\\\\\\\", \\\\\\\"grammar\\\\\\\": \\\\\\\"Grammar: Ok.\\\\\\\", \\\\\\\"markup-text\\\\\\\": \\\\\\\"invalid essay .\\\\\\\"}\\\", \\\"success\\\": true, \\\"grader_id\\\": 3241, \\\"grader_type\\\": \\\"ML\\\", \\\"rubric_scores_complete\\\": true, \\\"rubric_xml\\\": \\\"Response Quality0\\\"}\", \"score\": 0}], \"max_score\": 3, \"child_state\": \"done\"}"], "attempts": "10000", "student_attempts": 0, "due": null, "state": "done", "accept_file_upload": false, "display_name": "Science Question -- Machine Assessed"}"""
instance_state = json.loads(instance_state)
rubric = """
@@ -504,11 +504,13 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
See if we can load the module and save an answer
@return:
"""
- #Load the module
+ # Load the module
module = self.get_module_from_location(self.problem_location, COURSE)
- #Try saving an answer
+ # Try saving an answer
module.handle_ajax("save_answer", {"student_answer": self.answer})
+ # Save our modifications to the underlying KeyValueStore so they can be persisted
+ module.save()
task_one_json = json.loads(module.task_states[0])
self.assertEqual(task_one_json['child_history'][0]['answer'], self.answer)
@@ -629,3 +631,58 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
#reset the problem
module.handle_ajax("reset", {})
self.assertEqual(module.state, "initial")
+
+class OpenEndedModuleXmlAttemptTest(unittest.TestCase, DummyModulestore):
+ """
+ Test if student is able to reset the problem
+ """
+ problem_location = Location(["i4x", "edX", "open_ended", "combinedopenended", "SampleQuestion1Attempt"])
+ answer = "blah blah"
+ assessment = [0, 1]
+ hint = "blah"
+
+ def setUp(self):
+ self.test_system = get_test_system()
+ self.test_system.xqueue['interface'] = Mock(
+ send_to_queue=Mock(side_effect=[1, "queued"])
+ )
+ self.setup_modulestore(COURSE)
+
+ def test_reset_fail(self):
+ """
+ Test the flow of the module if we complete the self assessment step and then reset
+ Since the problem only allows one attempt, should fail.
+ @return:
+ """
+ assessment = [0, 1]
+ module = self.get_module_from_location(self.problem_location, COURSE)
+
+ #Simulate a student saving an answer
+ module.handle_ajax("save_answer", {"student_answer": self.answer})
+ status = module.handle_ajax("get_status", {})
+ self.assertTrue(isinstance(status, basestring))
+
+ #Mock a student submitting an assessment
+ assessment_dict = MockQueryDict()
+ assessment_dict.update({'assessment': sum(assessment), 'score_list[]': assessment})
+ module.handle_ajax("save_assessment", assessment_dict)
+ task_one_json = json.loads(module.task_states[0])
+ self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment)
+ status = module.handle_ajax("get_status", {})
+ self.assertTrue(isinstance(status, basestring))
+
+ #Move to the next step in the problem
+ module.handle_ajax("next_problem", {})
+ self.assertEqual(module.current_task_number, 0)
+
+ html = module.get_html()
+ self.assertTrue(isinstance(html, basestring))
+
+ #Module should now be done
+ rubric = module.handle_ajax("get_combined_rubric", {})
+ self.assertTrue(isinstance(rubric, basestring))
+ self.assertEqual(module.state, "done")
+
+ #Try to reset, should fail because only 1 attempt is allowed
+ reset_data = json.loads(module.handle_ajax("reset", {}))
+ self.assertEqual(reset_data['success'], False)
diff --git a/common/lib/xmodule/xmodule/tests/test_conditional.py b/common/lib/xmodule/xmodule/tests/test_conditional.py
index abb8b4941a..b28d236369 100644
--- a/common/lib/xmodule/xmodule/tests/test_conditional.py
+++ b/common/lib/xmodule/xmodule/tests/test_conditional.py
@@ -217,8 +217,11 @@ class ConditionalModuleXmlTest(unittest.TestCase):
html = ajax['html']
self.assertFalse(any(['This is a secret' in item for item in html]))
- # now change state of the capa problem to make it completed
- inner_get_module(Location('i4x://HarvardX/ER22x/problem/choiceprob')).attempts = 1
+ # Now change state of the capa problem to make it completed
+ inner_module = inner_get_module(Location('i4x://HarvardX/ER22x/problem/choiceprob'))
+ inner_module.attempts = 1
+ # Save our modifications to the underlying KeyValueStore so they can be persisted
+ inner_module.save()
ajax = json.loads(module.handle_ajax('', ''))
print "post-attempt ajax: ", ajax
diff --git a/common/lib/xmodule/xmodule/tests/test_fields.py b/common/lib/xmodule/xmodule/tests/test_fields.py
index f0eb082dcf..8453adaa20 100644
--- a/common/lib/xmodule/xmodule/tests/test_fields.py
+++ b/common/lib/xmodule/xmodule/tests/test_fields.py
@@ -44,7 +44,8 @@ class DateTest(unittest.TestCase):
def test_return_None(self):
self.assertIsNone(DateTest.date.from_json(""))
self.assertIsNone(DateTest.date.from_json(None))
- self.assertIsNone(DateTest.date.from_json(['unknown value']))
+ with self.assertRaises(TypeError):
+ DateTest.date.from_json(['unknown value'])
def test_old_due_date_format(self):
current = datetime.datetime.today()
@@ -83,6 +84,8 @@ class DateTest(unittest.TestCase):
DateTest.date.to_json(
DateTest.date.from_json("2012-12-31T23:00:01-01:00")),
"2012-12-31T23:00:01-01:00")
+ with self.assertRaises(TypeError):
+ DateTest.date.to_json('2012-12-31T23:00:01-01:00')
class TimedeltaTest(unittest.TestCase):
diff --git a/common/lib/xmodule/xmodule/tests/test_import.py b/common/lib/xmodule/xmodule/tests/test_import.py
index 30c8939b5b..2fe9d70627 100644
--- a/common/lib/xmodule/xmodule/tests/test_import.py
+++ b/common/lib/xmodule/xmodule/tests/test_import.py
@@ -156,11 +156,7 @@ class ImportTestCase(BaseCourseTestCase):
child = descriptor.get_children()[0]
self.assertEqual(child.lms.due, ImportTestCase.date.from_json(v))
self.assertEqual(child._inheritable_metadata, child._inherited_metadata)
- self.assertEqual(2, len(child._inherited_metadata))
- self.assertLessEqual(
- ImportTestCase.date.from_json(child._inherited_metadata['start']),
- datetime.datetime.now(UTC())
- )
+ self.assertEqual(1, len(child._inherited_metadata))
self.assertEqual(v, child._inherited_metadata['due'])
# Now export and check things
@@ -218,10 +214,8 @@ class ImportTestCase(BaseCourseTestCase):
self.assertEqual(child.lms.due, None)
# pylint: disable=W0212
self.assertEqual(child._inheritable_metadata, child._inherited_metadata)
- self.assertEqual(1, len(child._inherited_metadata))
- # why do these tests look in the internal structure v just calling child.start?
self.assertLessEqual(
- ImportTestCase.date.from_json(child._inherited_metadata['start']),
+ child.lms.start,
datetime.datetime.now(UTC())
)
@@ -249,12 +243,7 @@ class ImportTestCase(BaseCourseTestCase):
self.assertEqual(descriptor.lms.due, ImportTestCase.date.from_json(course_due))
self.assertEqual(child.lms.due, ImportTestCase.date.from_json(child_due))
# Test inherited metadata. Due does not appear here (because explicitly set on child).
- self.assertEqual(1, len(child._inherited_metadata))
- self.assertLessEqual(
- ImportTestCase.date.from_json(child._inherited_metadata['start']),
- datetime.datetime.now(UTC()))
- # Test inheritable metadata. This has the course inheritable value for due.
- self.assertEqual(2, len(child._inheritable_metadata))
+ self.assertEqual(1, len(child._inheritable_metadata))
self.assertEqual(course_due, child._inheritable_metadata['due'])
def test_is_pointer_tag(self):
diff --git a/common/lib/xmodule/xmodule/tests/test_logic.py b/common/lib/xmodule/xmodule/tests/test_logic.py
index 9be533885c..5fe7aa2832 100644
--- a/common/lib/xmodule/xmodule/tests/test_logic.py
+++ b/common/lib/xmodule/xmodule/tests/test_logic.py
@@ -28,7 +28,8 @@ class LogicTest(unittest.TestCase):
def setUp(self):
class EmptyClass:
"""Empty object."""
- pass
+ url_name = ''
+ category = 'test'
self.system = get_test_system()
self.descriptor = EmptyClass()
diff --git a/common/lib/xmodule/xmodule/tests/test_xml_module.py b/common/lib/xmodule/xmodule/tests/test_xml_module.py
index 7ccc71dd96..a277ff2900 100644
--- a/common/lib/xmodule/xmodule/tests/test_xml_module.py
+++ b/common/lib/xmodule/xmodule/tests/test_xml_module.py
@@ -141,6 +141,7 @@ class EditableMetadataFieldsTest(unittest.TestCase):
def get_xml_editable_fields(self, model_data):
system = get_test_system()
system.render_template = Mock(return_value="
Test Template HTML
")
+ model_data['category'] = 'test'
return XmlDescriptor(runtime=system, model_data=model_data).editable_metadata_fields
def get_descriptor(self, model_data):
diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py
index 3c6203107d..5354297c2b 100644
--- a/common/lib/xmodule/xmodule/video_module.py
+++ b/common/lib/xmodule/xmodule/video_module.py
@@ -21,6 +21,17 @@ log = logging.getLogger(__name__)
class VideoFields(object):
"""Fields for `VideoModule` and `VideoDescriptor`."""
+ display_name = String(
+ display_name="Display Name",
+ help="This name appears in the horizontal navigation at the top of the page.",
+ scope=Scope.settings,
+ # it'd be nice to have a useful default but it screws up other things; so,
+ # use display_name_with_default for those
+ default="Video Title"
+ )
+ data = String(help="XML data for the problem",
+ default='',
+ scope=Scope.content)
position = Integer(help="Current position in the video", scope=Scope.user_state, default=0)
show_captions = Boolean(help="This controls whether or not captions are shown by default.", display_name="Show Captions", scope=Scope.settings, default=True)
youtube_id_1_0 = String(help="This is the Youtube ID reference for the normal speed video.", display_name="Default Speed", scope=Scope.settings, default="OEoXaMPEzfM")
@@ -86,7 +97,6 @@ class VideoDescriptor(VideoFields,
MetadataOnlyEditingDescriptor,
RawDescriptor):
module_class = VideoModule
- template_dir_name = "video"
def __init__(self, *args, **kwargs):
super(VideoDescriptor, self).__init__(*args, **kwargs)
@@ -118,6 +128,13 @@ class VideoDescriptor(VideoFields,
_parse_video_xml(video, xml_data)
return video
+ def definition_to_xml(self, resource_fs):
+ """
+ Override the base implementation. We don't actually have anything in the 'data' field
+ (it's an empty string), so we just return a simple XML element
+ """
+ return etree.Element('video')
+
def _parse_video_xml(video, xml_data):
"""
@@ -129,6 +146,10 @@ def _parse_video_xml(video, xml_data):
display_name = xml.get('display_name')
if display_name:
video.display_name = display_name
+ elif video.url_name is not None:
+ # copies the logic of display_name_with_default in order that studio created videos will have an
+ # initial non guid name
+ video.display_name = video.url_name.replace('_', ' ')
youtube = xml.get('youtube')
if youtube:
diff --git a/common/lib/xmodule/xmodule/videoalpha_module.py b/common/lib/xmodule/xmodule/videoalpha_module.py
index 3b5b90e674..d8ed8949f1 100644
--- a/common/lib/xmodule/xmodule/videoalpha_module.py
+++ b/common/lib/xmodule/xmodule/videoalpha_module.py
@@ -28,15 +28,27 @@ from xblock.core import Integer, Scope, String
import datetime
import time
+import textwrap
log = logging.getLogger(__name__)
class VideoAlphaFields(object):
"""Fields for `VideoAlphaModule` and `VideoAlphaDescriptor`."""
- data = String(help="XML data for the problem", scope=Scope.content)
+ data = String(help="XML data for the problem",
+ default=textwrap.dedent('''\
+
+
+
+
+ '''),
+ scope=Scope.content)
position = Integer(help="Current position in the video", scope=Scope.user_state, default=0)
- display_name = String(help="Display name for this module", scope=Scope.settings)
+ display_name = String(
+ display_name="Display Name", help="Display name for this module",
+ default="Video Alpha",
+ scope=Scope.settings
+ )
class VideoAlphaModule(VideoAlphaFields, XModule):
@@ -167,4 +179,3 @@ class VideoAlphaModule(VideoAlphaFields, XModule):
class VideoAlphaDescriptor(VideoAlphaFields, RawDescriptor):
"""Descriptor for `VideoAlphaModule`."""
module_class = VideoAlphaModule
- template_dir_name = "videoalpha"
diff --git a/common/lib/xmodule/xmodule/word_cloud_module.py b/common/lib/xmodule/xmodule/word_cloud_module.py
index a7f3f92795..004e6ed320 100644
--- a/common/lib/xmodule/xmodule/word_cloud_module.py
+++ b/common/lib/xmodule/xmodule/word_cloud_module.py
@@ -14,7 +14,7 @@ from xmodule.raw_module import RawDescriptor
from xmodule.editing_module import MetadataOnlyEditingDescriptor
from xmodule.x_module import XModule
-from xblock.core import Scope, Dict, Boolean, List, Integer
+from xblock.core import Scope, Dict, Boolean, List, Integer, String
log = logging.getLogger(__name__)
@@ -31,6 +31,12 @@ def pretty_bool(value):
class WordCloudFields(object):
"""XFields for word cloud."""
+ display_name = String(
+ display_name="Display Name",
+ help="Display name for this module",
+ scope=Scope.settings,
+ default="Word cloud"
+ )
num_inputs = Integer(
display_name="Inputs",
help="Number of text boxes available for students to input words/sentences.",
@@ -234,7 +240,7 @@ class WordCloudModule(WordCloudFields, XModule):
return self.content
-class WordCloudDescriptor(MetadataOnlyEditingDescriptor, RawDescriptor, WordCloudFields):
+class WordCloudDescriptor(WordCloudFields, MetadataOnlyEditingDescriptor, RawDescriptor):
"""Descriptor for WordCloud Xmodule."""
module_class = WordCloudModule
template_dir_name = 'word_cloud'
diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py
index 0f5bbf4f2e..aee8e26171 100644
--- a/common/lib/xmodule/xmodule/x_module.py
+++ b/common/lib/xmodule/xmodule/x_module.py
@@ -7,8 +7,8 @@ from lxml import etree
from collections import namedtuple
from pkg_resources import resource_listdir, resource_string, resource_isdir
-from xmodule.modulestore import Location
-from xmodule.modulestore.exceptions import ItemNotFoundError
+from xmodule.modulestore import inheritance, Location
+from xmodule.modulestore.exceptions import ItemNotFoundError, InsufficientSpecificationError
from xblock.core import XBlock, Scope, String, Integer, Float, ModelType
@@ -101,6 +101,8 @@ class XModuleFields(object):
display_name="Display Name",
help="This name appears in the horizontal navigation at the top of the page.",
scope=Scope.settings,
+ # it'd be nice to have a useful default but it screws up other things; so,
+ # use display_name_with_default for those
default=None
)
@@ -113,6 +115,14 @@ class XModuleFields(object):
scope=Scope.content,
default=Location(None),
)
+ # Please note that in order to be compatible with XBlocks more generally,
+ # the LMS and CMS shouldn't be using this field. It's only for internal
+ # consumption by the XModules themselves
+ category = String(
+ display_name="xmodule category",
+ help="This is the category id for the XModule. It's for internal use only",
+ scope=Scope.content,
+ )
class XModule(XModuleFields, HTMLSnippet, XBlock):
@@ -148,8 +158,16 @@ class XModule(XModuleFields, HTMLSnippet, XBlock):
self._model_data = model_data
self.system = runtime
self.descriptor = descriptor
- self.url_name = self.location.name
- self.category = self.location.category
+ # LMS tests don't require descriptor but really it's required
+ if descriptor:
+ self.url_name = descriptor.url_name
+ # don't need to set category as it will automatically get from descriptor
+ elif isinstance(self.location, Location):
+ self.url_name = self.location.name
+ if not hasattr(self, 'category'):
+ self.category = self.location.category
+ else:
+ raise InsufficientSpecificationError()
self._loaded_children = None
@property
@@ -290,36 +308,67 @@ Template = namedtuple("Template", "metadata data children")
class ResourceTemplates(object):
+ """
+ Gets the templates associated w/ a containing cls. The cls must have a 'template_dir_name' attribute.
+ It finds the templates as directly in this directory under 'templates'.
+ """
@classmethod
def templates(cls):
"""
- Returns a list of Template objects that describe possible templates that can be used
- to create a module of this type.
- If no templates are provided, there will be no way to create a module of
- this type
+ Returns a list of dictionary field: value objects that describe possible templates that can be used
+ to seed a module of this type.
Expects a class attribute template_dir_name that defines the directory
inside the 'templates' resource directory to pull templates from
"""
templates = []
- dirname = os.path.join('templates', cls.template_dir_name)
- if not resource_isdir(__name__, dirname):
- log.warning("No resource directory {dir} found when loading {cls_name} templates".format(
- dir=dirname,
- cls_name=cls.__name__,
- ))
- return []
-
- for template_file in resource_listdir(__name__, dirname):
- if not template_file.endswith('.yaml'):
- log.warning("Skipping unknown template file %s" % template_file)
- continue
- template_content = resource_string(__name__, os.path.join(dirname, template_file))
- template = yaml.safe_load(template_content)
- templates.append(Template(**template))
+ dirname = cls.get_template_dir()
+ if dirname is not None:
+ for template_file in resource_listdir(__name__, dirname):
+ if not template_file.endswith('.yaml'):
+ log.warning("Skipping unknown template file %s", template_file)
+ continue
+ template_content = resource_string(__name__, os.path.join(dirname, template_file))
+ template = yaml.safe_load(template_content)
+ template['template_id'] = template_file
+ templates.append(template)
return templates
+ @classmethod
+ def get_template_dir(cls):
+ if getattr(cls, 'template_dir_name', None):
+ dirname = os.path.join('templates', getattr(cls, 'template_dir_name'))
+ if not resource_isdir(__name__, dirname):
+ log.warning("No resource directory {dir} found when loading {cls_name} templates".format(
+ dir=dirname,
+ cls_name=cls.__name__,
+ ))
+ return None
+ else:
+ return dirname
+ else:
+ return None
+
+ @classmethod
+ def get_template(cls, template_id):
+ """
+ Get a single template by the given id (which is the file name identifying it w/in the class's
+ template_dir_name)
+
+ """
+ dirname = cls.get_template_dir()
+ if dirname is not None:
+ try:
+ template_content = resource_string(__name__, os.path.join(dirname, template_id))
+ except IOError:
+ return None
+ template = yaml.safe_load(template_content)
+ template['template_id'] = template_id
+ return template
+ else:
+ return None
+
class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
"""
@@ -346,9 +395,6 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
# be equal
equality_attributes = ('_model_data', 'location')
- # Name of resource directory to load templates from
- template_dir_name = "default"
-
# Class level variable
# True if this descriptor always requires recalculation of grades, for
@@ -386,8 +432,12 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
"""
super(XModuleDescriptor, self).__init__(*args, **kwargs)
self.system = self.runtime
- self.url_name = self.location.name
- self.category = self.location.category
+ if isinstance(self.location, Location):
+ self.url_name = self.location.name
+ if not hasattr(self, 'category'):
+ self.category = self.location.category
+ else:
+ raise InsufficientSpecificationError()
self._child_instances = None
@property
@@ -419,11 +469,14 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
if self._child_instances is None:
self._child_instances = []
for child_loc in self.children:
- try:
- child = self.system.load_item(child_loc)
- except ItemNotFoundError:
- log.exception('Unable to load item {loc}, skipping'.format(loc=child_loc))
- continue
+ if isinstance(child_loc, XModuleDescriptor):
+ child = child_loc
+ else:
+ try:
+ child = self.system.load_item(child_loc)
+ except ItemNotFoundError:
+ log.exception('Unable to load item {loc}, skipping'.format(loc=child_loc))
+ continue
self._child_instances.append(child)
return self._child_instances
@@ -591,6 +644,13 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
"""
return [('{}', '{}')]
+ @property
+ def xblock_kvs(self):
+ """
+ Use w/ caution. Really intended for use by the persistence layer.
+ """
+ return self._model_data._kvs
+
# =============================== BUILTIN METHODS ==========================
def __eq__(self, other):
eq = (self.__class__ == other.__class__ and
diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py
index 0528bbfb6c..882e308c77 100644
--- a/common/lib/xmodule/xmodule/xml_module.py
+++ b/common/lib/xmodule/xmodule/xml_module.py
@@ -356,6 +356,7 @@ class XmlDescriptor(XModuleDescriptor):
if key not in set(f.name for f in cls.fields + cls.lms.fields):
model_data['xml_attributes'][key] = value
model_data['location'] = location
+ model_data['category'] = xml_object.tag
return cls(
system,
diff --git a/common/static/css/pdfviewer.css b/common/static/css/pdfviewer.css
index 656bc47c29..8b0253261b 100644
--- a/common/static/css/pdfviewer.css
+++ b/common/static/css/pdfviewer.css
@@ -100,7 +100,7 @@ select {
.toolbar {
/* position: absolute; */
left: 0;
- right: 0;
+ right: 0;
height: 32px;
z-index: 9999;
cursor: default;
@@ -185,6 +185,7 @@ select {
margin: 0;
}
+.splitToolbarButton > .toolbarButton, /*added */
.splitToolbarButton:hover > .toolbarButton,
.splitToolbarButton:focus > .toolbarButton,
.splitToolbarButton.toggled > .toolbarButton,
diff --git a/common/static/js/capa/choicetextinput.js b/common/static/js/capa/choicetextinput.js
new file mode 100644
index 0000000000..4d7540f938
--- /dev/null
+++ b/common/static/js/capa/choicetextinput.js
@@ -0,0 +1,75 @@
+(function () {
+ var update = function () {
+ // Whenever a value changes create a new serialized version of this
+ // problem's inputs and set the hidden input fields value to equal it.
+ var parent = $(this).closest('.problems-wrapper');
+ // find the closest parent problems-wrapper and use that as the problem
+ // grab the input id from the input
+ // real_input is the hidden input field
+ var real_input = $('input.choicetextvalue', parent);
+ var all_inputs = $('.choicetextinput .ctinput', parent);
+ var user_inputs = {};
+ $(all_inputs).each(function (index, elt) {
+ var node = $(elt);
+ var name = node.attr('id');
+ var val = node.val();
+ var radio_value = node.attr('value');
+ var type = node.attr('type');
+ var is_checked = node.attr('checked');
+ if (type === "radio" || type === "checkbox") {
+ if (is_checked === "checked" || is_checked === "true") {
+ user_inputs[name] = radio_value;
+ }
+ } else {
+ user_inputs[name] = val;
+ }
+ });
+ var val_string = JSON.stringify(user_inputs);
+ //this is what gets submitted as the answer, we deserialize it later
+ real_input.val(val_string);
+ };
+
+ var check_parent = function (event) {
+ // This looks for the containing choice of a textinput
+ // and sets it to be checked.
+ var elt = $(event.target);
+ var parent_container = elt.closest('section[id^="forinput"]');
+ var choice = parent_container.find("input[type='checkbox'], input[type='radio']");
+ choice.attr("checked", "checked");
+ choice.change();
+ //need to check it then trigger the change event
+ };
+
+ var imitate_label = function (event) {
+ // This causes a section to check and uncheck
+ // a radiobutton/checkbox whenever a user clicks on it
+ // If the button/checkbox is disabled, nothing happens
+ var elt = $(event.target);
+ var parent_container = elt.closest('section[id^="forinput"]');
+ var choice = parent_container.find("input[type='checkbox'], input[type='radio']");
+ if (choice.attr("type") === "radio") {
+ choice.attr("checked", "checked");
+ } else {
+ if (choice.attr('checked')) {
+ choice.prop("checked", false);
+ } else {
+ choice.prop("checked", true);
+ }
+
+ }
+ choice.change();
+ update();
+
+ };
+ var choices = $('.mock_label');
+ var inputs = $('.choicetextinput .ctinput');
+ var text_inputs = $('.choicetextinput .ctinput[type="text"]');
+ // update on load
+ inputs.each(update);
+ // and on every change
+ // This allows text inside of choices to behave as if they were part of
+ // a label for the choice's button/checkbox
+ choices.click(imitate_label);
+ inputs.bind("change", update);
+ text_inputs.click(check_parent);
+}).call(this);
diff --git a/common/templates/mathjax_include.html b/common/templates/mathjax_include.html
index 803f2145a4..0ddbd68eee 100644
--- a/common/templates/mathjax_include.html
+++ b/common/templates/mathjax_include.html
@@ -33,4 +33,4 @@
-
+
diff --git a/common/test/data/open_ended/combinedopenended/SampleQuestion1Attempt.xml b/common/test/data/open_ended/combinedopenended/SampleQuestion1Attempt.xml
new file mode 100644
index 0000000000..9bfabca191
--- /dev/null
+++ b/common/test/data/open_ended/combinedopenended/SampleQuestion1Attempt.xml
@@ -0,0 +1,24 @@
+
+
+
+
+ Writing Applications
+
+
+
+
+ Language Conventions
+
+
+
+
+
+
+
Censorship in the Libraries
+
"All of us can think of a book that we hope none of our children or any other children have taken off the shelf. But if I have the right to remove that book from the shelf -- that work I abhor -- then you also have exactly the same right and so does everyone else. And then we have no books left on the shelf for any of us." --Katherine Paterson, Author
+
Write a persuasive essay to a newspaper reflecting your vies on censorship in libraries. Do you believe that certain materials, such as books, music, movies, magazines, etc., should be removed from the shelves if they are found offensive? Support your position with convincing arguments from your own experience, observations, and/or reading.
+
+
+
+
+
\ No newline at end of file
diff --git a/common/test/data/open_ended/course/2012_Fall.xml b/common/test/data/open_ended/course/2012_Fall.xml
index 32c810174b..609d12f94c 100644
--- a/common/test/data/open_ended/course/2012_Fall.xml
+++ b/common/test/data/open_ended/course/2012_Fall.xml
@@ -1,6 +1,7 @@
+
diff --git a/lms/djangoapps/courseware/features/common.py b/lms/djangoapps/courseware/features/common.py
index 0aa079ebac..7632f22d6a 100644
--- a/lms/djangoapps/courseware/features/common.py
+++ b/lms/djangoapps/courseware/features/common.py
@@ -5,12 +5,10 @@ from __future__ import absolute_import
from lettuce import world, step
from nose.tools import assert_equals, assert_in
-from lettuce.django import django_url
from django.contrib.auth.models import User
from student.models import CourseEnrollment
from xmodule.modulestore import Location
-from xmodule.modulestore.django import _MODULESTORES, modulestore
-from xmodule.templates import update_templates
+from xmodule.modulestore.django import modulestore
from xmodule.course_module import CourseDescriptor
from courseware.courses import get_course_by_id
from xmodule import seq_module, vertical_module
@@ -20,7 +18,7 @@ logger = getLogger(__name__)
@step(u'The course "([^"]*)" exists$')
-def create_course(step, course):
+def create_course(_step, course):
# First clear the modulestore so we don't try to recreate
# the same course twice
@@ -38,9 +36,10 @@ def create_course(step, course):
world.scenario_dict['SECTION'] = world.ItemFactory.create(parent_location=world.scenario_dict['COURSE'].location,
display_name='Test Section')
- problem_section = world.ItemFactory.create(parent_location=world.scenario_dict['SECTION'].location,
- template='i4x://edx/templates/sequential/Empty',
- display_name='Test Section')
+ world.ItemFactory.create(
+ parent_location=world.scenario_dict['SECTION'].location,
+ category='sequential',
+ display_name='Test Section')
@step(u'I am registered for the course "([^"]*)"$')
@@ -60,10 +59,11 @@ def i_am_registered_for_the_course(step, course):
@step(u'The course "([^"]*)" has extra tab "([^"]*)"$')
-def add_tab_to_course(step, course, extra_tab_name):
- section_item = world.ItemFactory.create(parent_location=course_location(course),
- template="i4x://edx/templates/static_tab/Empty",
- display_name=str(extra_tab_name))
+def add_tab_to_course(_step, course, extra_tab_name):
+ world.ItemFactory.create(
+ parent_location=course_location(course),
+ category="static_tab",
+ display_name=str(extra_tab_name))
def course_id(course_num):
diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py
index 7c2474ae1a..c87e6122a4 100644
--- a/lms/djangoapps/courseware/features/navigation.py
+++ b/lms/djangoapps/courseware/features/navigation.py
@@ -24,11 +24,11 @@ def view_course_multiple_sections(step):
display_name=section_name(2))
place1 = world.ItemFactory.create(parent_location=section1.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name=subsection_name(1))
place2 = world.ItemFactory.create(parent_location=section2.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name=subsection_name(2))
add_problem_to_course_section('model_course', 'multiple choice', place1.location)
@@ -46,7 +46,7 @@ def view_course_multiple_subsections(step):
display_name=section_name(1))
place1 = world.ItemFactory.create(parent_location=section1.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name=subsection_name(1))
place2 = world.ItemFactory.create(parent_location=section1.location,
@@ -66,7 +66,7 @@ def view_course_multiple_sequences(step):
display_name=section_name(1))
place1 = world.ItemFactory.create(parent_location=section1.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name=subsection_name(1))
add_problem_to_course_section('model_course', 'multiple choice', place1.location)
@@ -177,9 +177,8 @@ def add_problem_to_course_section(course, problem_type, parent_location, extraMe
# Create a problem item using our generated XML
# We set rerandomize=always in the metadata so that the "Reset" button
# will appear.
- template_name = "i4x://edx/templates/problem/Blank_Common_Problem"
world.ItemFactory.create(parent_location=parent_location,
- template=template_name,
+ category='problem',
display_name=str(problem_type),
data=problem_xml,
metadata=metadata)
diff --git a/lms/djangoapps/courseware/features/problems.feature b/lms/djangoapps/courseware/features/problems.feature
index 4a5e64e9f4..fe6a695475 100644
--- a/lms/djangoapps/courseware/features/problems.feature
+++ b/lms/djangoapps/courseware/features/problems.feature
@@ -21,6 +21,8 @@ Feature: Answer problems
| formula |
| script |
| code |
+ | radio_text |
+ | checkbox_text |
Scenario: I can answer a problem incorrectly
Given External graders respond "incorrect"
@@ -40,6 +42,8 @@ Feature: Answer problems
| formula |
| script |
| code |
+ | radio_text |
+ | checkbox_text |
Scenario: I can submit a blank answer
Given I am viewing a "" problem
@@ -57,6 +61,8 @@ Feature: Answer problems
| numerical |
| formula |
| script |
+ | radio_text |
+ | checkbox_text |
Scenario: I can reset a problem
@@ -84,6 +90,10 @@ Feature: Answer problems
| formula | incorrect |
| script | correct |
| script | incorrect |
+ | radio_text | correct |
+ | radio_text | incorrect |
+ | checkbox_text | correct |
+ | checkbox_text | incorrect |
Scenario: I can answer a problem with one attempt correctly and not reset
diff --git a/lms/djangoapps/courseware/features/problems.py b/lms/djangoapps/courseware/features/problems.py
index 82bb4959a8..e0c3c004da 100644
--- a/lms/djangoapps/courseware/features/problems.py
+++ b/lms/djangoapps/courseware/features/problems.py
@@ -17,7 +17,7 @@ def view_problem_with_attempts(step, problem_type, attempts):
i_am_registered_for_the_course(step, 'model_course')
# Ensure that the course has this problem type
- add_problem_to_course(world.scenario_dict['COURSE'].number, problem_type, {'attempts': attempts})
+ add_problem_to_course(world.scenario_dict['COURSE'].number, problem_type, {'max_attempts': attempts})
# Go to the one section in the factory-created course
# which should be loaded with the correct problem
diff --git a/lms/djangoapps/courseware/features/problems_setup.py b/lms/djangoapps/courseware/features/problems_setup.py
index 1805da55d0..67dfbf0dc5 100644
--- a/lms/djangoapps/courseware/features/problems_setup.py
+++ b/lms/djangoapps/courseware/features/problems_setup.py
@@ -18,7 +18,7 @@ from capa.tests.response_xml_factory import OptionResponseXMLFactory, \
ChoiceResponseXMLFactory, MultipleChoiceResponseXMLFactory, \
StringResponseXMLFactory, NumericalResponseXMLFactory, \
FormulaResponseXMLFactory, CustomResponseXMLFactory, \
- CodeResponseXMLFactory
+ CodeResponseXMLFactory, ChoiceTextResponseXMLFactory
from nose.tools import assert_true
@@ -131,6 +131,32 @@ PROBLEM_DICT = {
'grader_payload': '{"grader": "ps1/Spring2013/test_grader.py"}', },
'correct': ['span.correct'],
'incorrect': ['span.incorrect'],
+ 'unanswered': ['span.unanswered']},
+
+ 'radio_text': {
+ 'factory': ChoiceTextResponseXMLFactory(),
+ 'kwargs': {
+ 'question_text': 'The correct answer is Choice 0 and input 8',
+ 'type': 'radiotextgroup',
+ 'choices': [("true", {"answer": "8", "tolerance": "1"}),
+ ("false", {"answer": "8", "tolerance": "1"})
+ ]
+ },
+ 'correct': ['section.choicetextgroup_correct'],
+ 'incorrect': ['span.incorrect', 'section.choicetextgroup_incorrect'],
+ 'unanswered': ['span.unanswered']},
+
+ 'checkbox_text': {
+ 'factory': ChoiceTextResponseXMLFactory(),
+ 'kwargs': {
+ 'question_text': 'The correct answer is Choice 0 and input 8',
+ 'type': 'checkboxtextgroup',
+ 'choices': [("true", {"answer": "8", "tolerance": "1"}),
+ ("false", {"answer": "8", "tolerance": "1"})
+ ]
+ },
+ 'correct': ['span.correct'],
+ 'incorrect': ['span.incorrect'],
'unanswered': ['span.unanswered']}
}
@@ -196,6 +222,19 @@ def answer_problem(problem_type, correctness):
# (configured in the problem XML above)
pass
+ elif problem_type == 'radio_text' or problem_type == 'checkbox_text':
+
+ input_value = "8" if correctness == 'correct' else "5"
+ choice = "choiceinput_0bc" if correctness == 'correct' else "choiceinput_1bc"
+ world.css_check(inputfield(problem_type, choice=choice))
+ world.css_fill(
+ inputfield(
+ problem_type,
+ choice="choiceinput_0_numtolerance_input_0"
+ ),
+ input_value
+ )
+
def problem_has_answer(problem_type, answer_class):
if problem_type == "drop down":
@@ -244,6 +283,17 @@ def problem_has_answer(problem_type, answer_class):
expected = "x^2+2*x+y" if answer_class == 'correct' else 'x^2'
assert_textfield('formula', expected)
+ elif problem_type in ("radio_text", "checkbox_text"):
+ if answer_class == 'blank':
+ expected = ('', '')
+ assert_choicetext_values(problem_type, (), expected)
+ elif answer_class == 'incorrect':
+ expected = ('5', '')
+ assert_choicetext_values(problem_type, ["choiceinput_1bc"], expected)
+ else:
+ expected = ('8', '')
+ assert_choicetext_values(problem_type, ["choiceinput_0bc"], expected)
+
else:
# The other response types use random data,
# which would be difficult to check
@@ -273,9 +323,9 @@ def add_problem_to_course(course, problem_type, extraMeta=None):
# Create a problem item using our generated XML
# We set rerandomize=always in the metadata so that the "Reset" button
# will appear.
- template_name = "i4x://edx/templates/problem/Blank_Common_Problem"
- world.ItemFactory.create(parent_location=section_location(course),
- template=template_name,
+ category_name = "problem"
+ return world.ItemFactory.create(parent_location=section_location(course),
+ category=category_name,
display_name=str(problem_type),
data=problem_xml,
metadata=metadata)
@@ -292,6 +342,12 @@ def inputfield(problem_type, choice=None, input_num=1):
sel = ("input#input_i4x-edx-model_course-problem-%s_2_%s" %
(problem_type.replace(" ", "_"), str(input_num)))
+ # this is necessary due to naming requirement for this problem type
+ if problem_type in ("radio_text", "checkbox_text"):
+ sel = "input#i4x-edx-model_course-problem-{0}_2_{1}".format(
+ problem_type.replace(" ", "_"), str(input_num)
+ )
+
if choice is not None:
base = "_choice_" if problem_type == "multiple choice" else "_"
sel = sel + base + str(choice)
@@ -325,3 +381,29 @@ def assert_checked(problem_type, choices):
def assert_textfield(problem_type, expected_text, input_num=1):
element_value = world.css_value(inputfield(problem_type, input_num=input_num))
assert element_value == expected_text
+
+
+def assert_choicetext_values(problem_type, choices, expected_values):
+ """
+ Asserts that only the given choices are checked, and given
+ text fields have a desired value
+ """
+ # Names of the radio buttons or checkboxes
+ all_choices = ['choiceinput_0bc', 'choiceinput_1bc']
+ # Names of the numtolerance_inputs
+ all_inputs = [
+ "choiceinput_0_numtolerance_input_0",
+ "choiceinput_1_numtolerance_input_0"
+ ]
+ for this_choice in all_choices:
+ element = world.css_find(inputfield(problem_type, choice=this_choice))
+
+ if this_choice in choices:
+ assert element.checked
+ else:
+ assert not element.checked
+
+ for (name, expected) in zip(all_inputs, expected_values):
+ element = world.css_find(inputfield(problem_type, name))
+ # Remove any trailing spaces that may have been added
+ assert element.value.strip() == expected
diff --git a/lms/djangoapps/courseware/features/video.py b/lms/djangoapps/courseware/features/video.py
index 6b05af51b5..f95ffd9917 100644
--- a/lms/djangoapps/courseware/features/video.py
+++ b/lms/djangoapps/courseware/features/video.py
@@ -43,14 +43,13 @@ def view_videoalpha(step):
def add_video_to_course(course):
- template_name = 'i4x://edx/templates/video/default'
world.ItemFactory.create(parent_location=section_location(course),
- template=template_name,
+ category='video',
display_name='Video')
def add_videoalpha_to_course(course):
- template_name = 'i4x://edx/templates/videoalpha/Video_Alpha'
+ category = 'videoalpha'
world.ItemFactory.create(parent_location=section_location(course),
- template=template_name,
+ category=category,
display_name='Video Alpha')
diff --git a/lms/djangoapps/courseware/management/commands/clean_history.py b/lms/djangoapps/courseware/management/commands/clean_history.py
new file mode 100644
index 0000000000..4286e17658
--- /dev/null
+++ b/lms/djangoapps/courseware/management/commands/clean_history.py
@@ -0,0 +1,239 @@
+"""A command to clean the StudentModuleHistory table.
+
+When we added XBlock storage, each field modification wrote a new history row
+to the db. Now that we have bulk saves to avoid that database hammering, we
+need to clean out the unnecessary rows from the database.
+
+This command that does that.
+
+"""
+
+import datetime
+import json
+import logging
+import optparse
+import time
+import traceback
+
+from django.core.management.base import NoArgsCommand
+from django.db import connection
+
+
+class Command(NoArgsCommand):
+ """The actual clean_history command to clean history rows."""
+
+ help = "Deletes unneeded rows from the StudentModuleHistory table."
+
+ option_list = NoArgsCommand.option_list + (
+ optparse.make_option(
+ '--batch',
+ type='int',
+ default=100,
+ help="Batch size, number of module_ids to examine in a transaction.",
+ ),
+ optparse.make_option(
+ '--dry-run',
+ action='store_true',
+ default=False,
+ help="Don't change the database, just show what would be done.",
+ ),
+ optparse.make_option(
+ '--sleep',
+ type='float',
+ default=0,
+ help="Seconds to sleep between batches.",
+ ),
+ )
+
+ def handle_noargs(self, **options):
+ # We don't want to see the SQL output from the db layer.
+ logging.getLogger("django.db.backends").setLevel(logging.INFO)
+
+ smhc = StudentModuleHistoryCleaner(
+ dry_run=options["dry_run"],
+ )
+ smhc.main(batch_size=options["batch"], sleep=options["sleep"])
+
+
+class StudentModuleHistoryCleaner(object):
+ """Logic to clean rows from the StudentModuleHistory table."""
+
+ DELETE_GAP_SECS = 0.5 # Rows this close can be discarded.
+ STATE_FILE = "clean_history.json"
+ BATCH_SIZE = 100
+
+ def __init__(self, dry_run=False):
+ self.dry_run = dry_run
+ self.next_student_module_id = 0
+ self.last_student_module_id = 0
+
+ def main(self, batch_size=None, sleep=0):
+ """Invoked from the management command to do all the work."""
+
+ batch_size = batch_size or self.BATCH_SIZE
+
+ connection.enter_transaction_management()
+
+ self.last_student_module_id = self.get_last_student_module_id()
+ self.load_state()
+
+ while self.next_student_module_id <= self.last_student_module_id:
+ for smid in self.module_ids_to_check(batch_size):
+ try:
+ self.clean_one_student_module(smid)
+ except Exception: # pylint: disable=W0703
+ trace = traceback.format_exc()
+ self.say("Couldn't clean student_module_id {}:\n{}".format(smid, trace))
+ if not self.dry_run:
+ self.commit()
+ self.save_state()
+ if sleep:
+ time.sleep(sleep)
+
+ def say(self, message):
+ """
+ Display a message to the user.
+
+ The message will have a trailing newline added to it.
+
+ """
+ print message
+
+ def commit(self):
+ """
+ Commit the transaction.
+ """
+ self.say("Committing")
+ connection.commit()
+
+ def load_state(self):
+ """
+ Load the latest state from disk.
+ """
+ try:
+ state_file = open(self.STATE_FILE)
+ except IOError:
+ self.say("No stored state")
+ self.next_student_module_id = 0
+ else:
+ with state_file:
+ state = json.load(state_file)
+ self.say(
+ "Loaded stored state: {}".format(
+ json.dumps(state, sort_keys=True)
+ )
+ )
+ self.next_student_module_id = state['next_student_module_id']
+
+ def save_state(self):
+ """
+ Save the state to disk.
+ """
+ state = {
+ 'next_student_module_id': self.next_student_module_id,
+ }
+ with open(self.STATE_FILE, "w") as state_file:
+ json.dump(state, state_file)
+ self.say("Saved state: {}".format(json.dumps(state, sort_keys=True)))
+
+ def get_last_student_module_id(self):
+ """
+ Return the id of the last student_module.
+ """
+ cursor = connection.cursor()
+ cursor.execute("""
+ SELECT max(student_module_id) FROM courseware_studentmodulehistory
+ """)
+ last = cursor.fetchone()[0]
+ self.say("Last student_module_id is {}".format(last))
+ return last
+
+ def module_ids_to_check(self, batch_size):
+ """Produce a sequence of student module ids to check.
+
+ `batch_size` is how many module ids to produce, max.
+
+ The sequence starts with `next_student_module_id`, and goes up to
+ and including `last_student_module_id`.
+
+ `next_student_module_id` is updated as each id is yielded.
+
+ """
+ start = self.next_student_module_id
+ for smid in range(start, start+batch_size):
+ if smid > self.last_student_module_id:
+ break
+ yield smid
+ self.next_student_module_id = smid+1
+
+ def get_history_for_student_modules(self, student_module_id):
+ """
+ Get the history rows for a student module.
+
+ ```student_module_id```: the id of the student module we're
+ interested in.
+
+ Return a list: [(id, created), ...], all the rows of history.
+
+ """
+ cursor = connection.cursor()
+ cursor.execute("""
+ SELECT id, created FROM courseware_studentmodulehistory
+ WHERE student_module_id = %s
+ ORDER BY created, id
+ """,
+ [student_module_id]
+ )
+ history = cursor.fetchall()
+ return history
+
+ def delete_history(self, ids_to_delete):
+ """
+ Delete history rows.
+
+ ```ids_to_delete```: a non-empty list (or set...) of history row ids to delete.
+
+ """
+ assert ids_to_delete
+ cursor = connection.cursor()
+ cursor.execute("""
+ DELETE FROM courseware_studentmodulehistory
+ WHERE id IN ({ids})
+ """.format(ids=",".join(str(i) for i in ids_to_delete))
+ )
+
+ def clean_one_student_module(self, student_module_id):
+ """Clean one StudentModule's-worth of history.
+
+ `student_module_id`: the id of the StudentModule to process.
+
+ """
+ delete_gap = datetime.timedelta(seconds=self.DELETE_GAP_SECS)
+
+ history = self.get_history_for_student_modules(student_module_id)
+ if not history:
+ self.say("No history for student_module_id {}".format(student_module_id))
+ return
+
+ ids_to_delete = []
+ next_created = None
+ for history_id, created in reversed(history):
+ if next_created is not None:
+ # Compare this timestamp with the next one.
+ if (next_created - created) < delete_gap:
+ # This row is followed closely by another, we can discard
+ # this one.
+ ids_to_delete.append(history_id)
+
+ next_created = created
+
+ verb = "Would have deleted" if self.dry_run else "Deleting"
+ self.say("{verb} {to_delete} rows of {total} for student_module_id {id}".format(
+ verb=verb,
+ to_delete=len(ids_to_delete),
+ total=len(history),
+ id=student_module_id,
+ ))
+
+ if ids_to_delete and not self.dry_run:
+ self.delete_history(ids_to_delete)
diff --git a/lms/djangoapps/courseware/management/tests/test_clean_history.py b/lms/djangoapps/courseware/management/tests/test_clean_history.py
new file mode 100644
index 0000000000..2a70556ffe
--- /dev/null
+++ b/lms/djangoapps/courseware/management/tests/test_clean_history.py
@@ -0,0 +1,483 @@
+"""Test the clean_history management command."""
+
+import fnmatch
+from mock import Mock
+import os.path
+import textwrap
+
+import dateutil.parser
+
+from django.test import TransactionTestCase
+from django.db import connection
+
+from courseware.management.commands.clean_history import StudentModuleHistoryCleaner
+
+# In lots of places in this file, smhc == StudentModuleHistoryCleaner
+
+def parse_date(sdate):
+ """Parse a string date into a datetime."""
+ parsed = dateutil.parser.parse(sdate)
+ parsed = parsed.replace(tzinfo=dateutil.tz.gettz('UTC'))
+ return parsed
+
+class SmhcSayStubbed(StudentModuleHistoryCleaner):
+ """StudentModuleHistoryCleaner, but with .say() stubbed for testing."""
+ def __init__(self, **kwargs):
+ super(SmhcSayStubbed, self).__init__(**kwargs)
+ self.said_lines = []
+
+ def say(self, msg):
+ self.said_lines.append(msg)
+
+
+class SmhcDbMocked(SmhcSayStubbed):
+ """StudentModuleHistoryCleaner, but with db access mocked."""
+ def __init__(self, **kwargs):
+ super(SmhcDbMocked, self).__init__(**kwargs)
+ self.get_history_for_student_modules = Mock()
+ self.delete_history = Mock()
+
+ def set_rows(self, rows):
+ """Set the mocked history rows."""
+ rows = [(row_id, parse_date(created)) for row_id, created in rows]
+ self.get_history_for_student_modules.return_value = rows
+
+
+class HistoryCleanerTest(TransactionTestCase):
+ """Base class for all history cleaner tests."""
+
+ maxDiff = None
+
+ def setUp(self):
+ super(HistoryCleanerTest, self).setUp()
+ self.addCleanup(self.clean_up_state_file)
+
+ def write_state_file(self, state):
+ """Write the string `state` into the state file read by StudentModuleHistoryCleaner."""
+ with open(StudentModuleHistoryCleaner.STATE_FILE, "w") as state_file:
+ state_file.write(state)
+
+ def read_state_file(self):
+ """Return the string contents of the state file read by StudentModuleHistoryCleaner."""
+ with open(StudentModuleHistoryCleaner.STATE_FILE) as state_file:
+ return state_file.read()
+
+ def clean_up_state_file(self):
+ """Remove any state file lying around."""
+ if os.path.exists(StudentModuleHistoryCleaner.STATE_FILE):
+ os.remove(StudentModuleHistoryCleaner.STATE_FILE)
+
+ def assert_said(self, smhc, *msgs):
+ """Fail if the `smhc` didn't say `msgs`.
+
+ The messages passed here are `fnmatch`-style patterns: "*" means anything.
+
+ """
+ for said, pattern in zip(smhc.said_lines, msgs):
+ if not fnmatch.fnmatch(said, pattern):
+ fmt = textwrap.dedent("""\
+ Messages:
+
+ {msgs}
+
+ don't match patterns:
+
+ {patterns}
+
+ Failed at {said!r} and {pattern!r}
+ """)
+
+ msg = fmt.format(
+ msgs="\n".join(smhc.said_lines),
+ patterns="\n".join(msgs),
+ said=said,
+ pattern=pattern
+ )
+ self.fail(msg)
+
+ def parse_rows(self, rows):
+ """Parse convenient rows into real data."""
+ rows = [
+ (row_id, parse_date(created), student_module_id)
+ for row_id, created, student_module_id in rows
+ ]
+ return rows
+
+ def write_history(self, rows):
+ """Write history rows to the db.
+
+ Each row should be (id, created, student_module_id).
+
+ """
+ cursor = connection.cursor()
+ cursor.executemany("""
+ INSERT INTO courseware_studentmodulehistory
+ (id, created, student_module_id)
+ VALUES (%s, %s, %s)
+ """,
+ self.parse_rows(rows),
+ )
+
+ def read_history(self):
+ """Read the history from the db, and return it as a list of tuples.
+
+ Returns [(id, created, student_module_id), ...]
+
+ """
+ cursor = connection.cursor()
+ cursor.execute("""
+ SELECT id, created, student_module_id FROM courseware_studentmodulehistory
+ """)
+ return cursor.fetchall()
+
+ def assert_history(self, rows):
+ """Assert that the history rows are the same as `rows`."""
+ self.assertEqual(self.parse_rows(rows), self.read_history())
+
+
+class HistoryCleanerNoDbTest(HistoryCleanerTest):
+ """Tests of StudentModuleHistoryCleaner with db access mocked."""
+
+ def test_empty(self):
+ smhc = SmhcDbMocked()
+ smhc.set_rows([])
+
+ smhc.clean_one_student_module(1)
+ self.assert_said(smhc, "No history for student_module_id 1")
+
+ # Nothing to delete, so delete_history wasn't called.
+ self.assertFalse(smhc.delete_history.called)
+
+ def test_one_row(self):
+ smhc = SmhcDbMocked()
+ smhc.set_rows([
+ (1, "2013-07-13 12:11:10.987"),
+ ])
+ smhc.clean_one_student_module(1)
+ self.assert_said(smhc, "Deleting 0 rows of 1 for student_module_id 1")
+ # Nothing to delete, so delete_history wasn't called.
+ self.assertFalse(smhc.delete_history.called)
+
+ def test_one_row_dry_run(self):
+ smhc = SmhcDbMocked(dry_run=True)
+ smhc.set_rows([
+ (1, "2013-07-13 12:11:10.987"),
+ ])
+ smhc.clean_one_student_module(1)
+ self.assert_said(smhc, "Would have deleted 0 rows of 1 for student_module_id 1")
+ # Nothing to delete, so delete_history wasn't called.
+ self.assertFalse(smhc.delete_history.called)
+
+ def test_two_rows_close(self):
+ smhc = SmhcDbMocked()
+ smhc.set_rows([
+ (7, "2013-07-13 12:34:56.789"),
+ (9, "2013-07-13 12:34:56.987"),
+ ])
+ smhc.clean_one_student_module(1)
+ self.assert_said(smhc, "Deleting 1 rows of 2 for student_module_id 1")
+ smhc.delete_history.assert_called_once_with([7])
+
+ def test_two_rows_far(self):
+ smhc = SmhcDbMocked()
+ smhc.set_rows([
+ (7, "2013-07-13 12:34:56.789"),
+ (9, "2013-07-13 12:34:57.890"),
+ ])
+ smhc.clean_one_student_module(1)
+ self.assert_said(smhc, "Deleting 0 rows of 2 for student_module_id 1")
+ self.assertFalse(smhc.delete_history.called)
+
+ def test_a_bunch_of_rows(self):
+ smhc = SmhcDbMocked()
+ smhc.set_rows([
+ ( 4, "2013-07-13 16:30:00.000"), # keep
+ ( 8, "2013-07-13 16:30:01.100"),
+ (15, "2013-07-13 16:30:01.200"),
+ (16, "2013-07-13 16:30:01.300"), # keep
+ (23, "2013-07-13 16:30:02.400"),
+ (42, "2013-07-13 16:30:02.500"),
+ (98, "2013-07-13 16:30:02.600"), # keep
+ (99, "2013-07-13 16:30:59.000"), # keep
+ ])
+ smhc.clean_one_student_module(17)
+ self.assert_said(smhc, "Deleting 4 rows of 8 for student_module_id 17")
+ smhc.delete_history.assert_called_once_with([42, 23, 15, 8])
+
+
+class HistoryCleanerWitDbTest(HistoryCleanerTest):
+ """Tests of StudentModuleHistoryCleaner with a real db."""
+
+ def test_no_history(self):
+ # Cleaning a student_module_id with no history leaves the db unchanged.
+ smhc = SmhcSayStubbed()
+ self.write_history([
+ ( 4, "2013-07-13 16:30:00.000", 11), # keep
+ ( 8, "2013-07-13 16:30:01.100", 11),
+ (15, "2013-07-13 16:30:01.200", 11),
+ (16, "2013-07-13 16:30:01.300", 11), # keep
+ (23, "2013-07-13 16:30:02.400", 11),
+ (42, "2013-07-13 16:30:02.500", 11),
+ (98, "2013-07-13 16:30:02.600", 11), # keep
+ (99, "2013-07-13 16:30:59.000", 11), # keep
+ ])
+
+ smhc.clean_one_student_module(22)
+ self.assert_said(smhc, "No history for student_module_id 22")
+ self.assert_history([
+ ( 4, "2013-07-13 16:30:00.000", 11), # keep
+ ( 8, "2013-07-13 16:30:01.100", 11),
+ (15, "2013-07-13 16:30:01.200", 11),
+ (16, "2013-07-13 16:30:01.300", 11), # keep
+ (23, "2013-07-13 16:30:02.400", 11),
+ (42, "2013-07-13 16:30:02.500", 11),
+ (98, "2013-07-13 16:30:02.600", 11), # keep
+ (99, "2013-07-13 16:30:59.000", 11), # keep
+ ])
+
+ def test_a_bunch_of_rows(self):
+ # Cleaning a student_module_id with 8 records, 4 to delete.
+ smhc = SmhcSayStubbed()
+ self.write_history([
+ ( 4, "2013-07-13 16:30:00.000", 11), # keep
+ ( 8, "2013-07-13 16:30:01.100", 11),
+ (15, "2013-07-13 16:30:01.200", 11),
+ (16, "2013-07-13 16:30:01.300", 11), # keep
+ (17, "2013-07-13 16:30:01.310", 22), # other student_module_id!
+ (23, "2013-07-13 16:30:02.400", 11),
+ (42, "2013-07-13 16:30:02.500", 11),
+ (98, "2013-07-13 16:30:02.600", 11), # keep
+ (99, "2013-07-13 16:30:59.000", 11), # keep
+ ])
+
+ smhc.clean_one_student_module(11)
+ self.assert_said(smhc, "Deleting 4 rows of 8 for student_module_id 11")
+ self.assert_history([
+ ( 4, "2013-07-13 16:30:00.000", 11), # keep
+ (16, "2013-07-13 16:30:01.300", 11), # keep
+ (17, "2013-07-13 16:30:01.310", 22), # other student_module_id!
+ (98, "2013-07-13 16:30:02.600", 11), # keep
+ (99, "2013-07-13 16:30:59.000", 11), # keep
+ ])
+
+ def test_a_bunch_of_rows_dry_run(self):
+ # Cleaning a student_module_id with 8 records, 4 to delete,
+ # but don't really do it.
+ smhc = SmhcSayStubbed(dry_run=True)
+ self.write_history([
+ ( 4, "2013-07-13 16:30:00.000", 11), # keep
+ ( 8, "2013-07-13 16:30:01.100", 11),
+ (15, "2013-07-13 16:30:01.200", 11),
+ (16, "2013-07-13 16:30:01.300", 11), # keep
+ (23, "2013-07-13 16:30:02.400", 11),
+ (42, "2013-07-13 16:30:02.500", 11),
+ (98, "2013-07-13 16:30:02.600", 11), # keep
+ (99, "2013-07-13 16:30:59.000", 11), # keep
+ ])
+
+ smhc.clean_one_student_module(11)
+ self.assert_said(smhc, "Would have deleted 4 rows of 8 for student_module_id 11")
+ self.assert_history([
+ ( 4, "2013-07-13 16:30:00.000", 11), # keep
+ ( 8, "2013-07-13 16:30:01.100", 11),
+ (15, "2013-07-13 16:30:01.200", 11),
+ (16, "2013-07-13 16:30:01.300", 11), # keep
+ (23, "2013-07-13 16:30:02.400", 11),
+ (42, "2013-07-13 16:30:02.500", 11),
+ (98, "2013-07-13 16:30:02.600", 11), # keep
+ (99, "2013-07-13 16:30:59.000", 11), # keep
+ ])
+
+ def test_a_bunch_of_rows_in_jumbled_order(self):
+ # Cleaning a student_module_id with 8 records, 4 to delete.
+ smhc = SmhcSayStubbed()
+ self.write_history([
+ (23, "2013-07-13 16:30:01.100", 11),
+ (24, "2013-07-13 16:30:01.300", 11), # keep
+ (27, "2013-07-13 16:30:02.500", 11),
+ (30, "2013-07-13 16:30:01.350", 22), # other student_module_id!
+ (32, "2013-07-13 16:30:59.000", 11), # keep
+ (50, "2013-07-13 16:30:02.400", 11),
+ (51, "2013-07-13 16:30:02.600", 11), # keep
+ (56, "2013-07-13 16:30:00.000", 11), # keep
+ (57, "2013-07-13 16:30:01.200", 11),
+ ])
+
+ smhc.clean_one_student_module(11)
+ self.assert_said(smhc, "Deleting 4 rows of 8 for student_module_id 11")
+ self.assert_history([
+ (24, "2013-07-13 16:30:01.300", 11), # keep
+ (30, "2013-07-13 16:30:01.350", 22), # other student_module_id!
+ (32, "2013-07-13 16:30:59.000", 11), # keep
+ (51, "2013-07-13 16:30:02.600", 11), # keep
+ (56, "2013-07-13 16:30:00.000", 11), # keep
+ ])
+
+ def test_a_bunch_of_rows_with_timestamp_ties(self):
+ # Sometimes rows are written with identical timestamps. The one with
+ # the greater id is the winner in that case.
+ smhc = SmhcSayStubbed()
+ self.write_history([
+ (21, "2013-07-13 16:30:01.100", 11),
+ (24, "2013-07-13 16:30:01.100", 11), # keep
+ (22, "2013-07-13 16:30:01.100", 11),
+ (23, "2013-07-13 16:30:01.100", 11),
+ (27, "2013-07-13 16:30:02.500", 11),
+ (30, "2013-07-13 16:30:01.350", 22), # other student_module_id!
+ (32, "2013-07-13 16:30:59.000", 11), # keep
+ (50, "2013-07-13 16:30:02.500", 11), # keep
+ ])
+
+ smhc.clean_one_student_module(11)
+ self.assert_said(smhc, "Deleting 4 rows of 7 for student_module_id 11")
+ self.assert_history([
+ (24, "2013-07-13 16:30:01.100", 11), # keep
+ (30, "2013-07-13 16:30:01.350", 22), # other student_module_id!
+ (32, "2013-07-13 16:30:59.000", 11), # keep
+ (50, "2013-07-13 16:30:02.500", 11), # keep
+ ])
+
+ def test_get_last_student_module(self):
+ # Can we find the last student_module_id properly?
+ smhc = SmhcSayStubbed()
+ self.write_history([
+ (23, "2013-07-13 16:30:01.100", 11),
+ (24, "2013-07-13 16:30:01.300", 44),
+ (27, "2013-07-13 16:30:02.500", 11),
+ (30, "2013-07-13 16:30:01.350", 22),
+ (32, "2013-07-13 16:30:59.000", 11),
+ (51, "2013-07-13 16:30:02.600", 33),
+ (56, "2013-07-13 16:30:00.000", 11),
+ ])
+ last = smhc.get_last_student_module_id()
+ self.assertEqual(last, 44)
+ self.assert_said(smhc, "Last student_module_id is 44")
+
+ def test_load_state_with_no_stored_state(self):
+ smhc = SmhcSayStubbed()
+ self.assertFalse(os.path.exists(smhc.STATE_FILE))
+ smhc.load_state()
+ self.assertEqual(smhc.next_student_module_id, 0)
+ self.assert_said(smhc, "No stored state")
+
+ def test_load_stored_state(self):
+ self.write_state_file('{"next_student_module_id": 23}')
+ smhc = SmhcSayStubbed()
+ smhc.load_state()
+ self.assertEqual(smhc.next_student_module_id, 23)
+ self.assert_said(smhc, 'Loaded stored state: {"next_student_module_id": 23}')
+
+ def test_save_state(self):
+ smhc = SmhcSayStubbed()
+ smhc.next_student_module_id = 47
+ smhc.save_state()
+ state = self.read_state_file()
+ self.assertEqual(state, '{"next_student_module_id": 47}')
+
+
+class SmhcForTestingMain(SmhcSayStubbed):
+ """A StudentModuleHistoryCleaner with a few function stubbed for testing main."""
+
+ def __init__(self, *args, **kwargs):
+ self.exception_smids = kwargs.pop('exception_smids', ())
+ super(SmhcForTestingMain, self).__init__(*args, **kwargs)
+
+ def clean_one_student_module(self, smid):
+ self.say("(not really cleaning {})".format(smid))
+ if smid in self.exception_smids:
+ raise Exception("Something went wrong!")
+
+ def commit(self):
+ self.say("(not really committing)")
+
+
+class HistoryCleanerMainTest(HistoryCleanerTest):
+ """Tests of StudentModuleHistoryCleaner.main(), using SmhcForTestingMain."""
+
+ def test_only_one_record(self):
+ smhc = SmhcForTestingMain()
+ self.write_history([
+ (1, "2013-07-15 11:47:00.000", 1),
+ ])
+ smhc.main()
+ self.assert_said(smhc,
+ 'Last student_module_id is 1',
+ 'No stored state',
+ '(not really cleaning 0)',
+ '(not really cleaning 1)',
+ '(not really committing)',
+ 'Saved state: {"next_student_module_id": 2}',
+ )
+
+ def test_already_processed_some(self):
+ smhc = SmhcForTestingMain()
+ self.write_state_file('{"next_student_module_id": 25}')
+ self.write_history([
+ (1, "2013-07-15 15:04:00.000", 23),
+ (2, "2013-07-15 15:04:11.000", 23),
+ (3, "2013-07-15 15:04:01.000", 24),
+ (4, "2013-07-15 15:04:00.000", 25),
+ (5, "2013-07-15 15:04:00.000", 26),
+ ])
+ smhc.main()
+ self.assert_said(smhc,
+ 'Last student_module_id is 26',
+ 'Loaded stored state: {"next_student_module_id": 25}',
+ '(not really cleaning 25)',
+ '(not really cleaning 26)',
+ '(not really committing)',
+ 'Saved state: {"next_student_module_id": 27}'
+ )
+
+ def test_working_in_batches(self):
+ smhc = SmhcForTestingMain()
+ self.write_state_file('{"next_student_module_id": 25}')
+ self.write_history([
+ (3, "2013-07-15 15:04:01.000", 24),
+ (4, "2013-07-15 15:04:00.000", 25),
+ (5, "2013-07-15 15:04:00.000", 26),
+ (6, "2013-07-15 15:04:00.000", 27),
+ (7, "2013-07-15 15:04:00.000", 28),
+ (8, "2013-07-15 15:04:00.000", 29),
+ ])
+ smhc.main(batch_size=3)
+ self.assert_said(smhc,
+ 'Last student_module_id is 29',
+ 'Loaded stored state: {"next_student_module_id": 25}',
+ '(not really cleaning 25)',
+ '(not really cleaning 26)',
+ '(not really cleaning 27)',
+ '(not really committing)',
+ 'Saved state: {"next_student_module_id": 28}',
+ '(not really cleaning 28)',
+ '(not really cleaning 29)',
+ '(not really committing)',
+ 'Saved state: {"next_student_module_id": 30}',
+ )
+
+ def test_something_failing_while_cleaning(self):
+ smhc = SmhcForTestingMain(exception_smids=[26])
+ self.write_state_file('{"next_student_module_id": 25}')
+ self.write_history([
+ (3, "2013-07-15 15:04:01.000", 24),
+ (4, "2013-07-15 15:04:00.000", 25),
+ (5, "2013-07-15 15:04:00.000", 26),
+ (6, "2013-07-15 15:04:00.000", 27),
+ (7, "2013-07-15 15:04:00.000", 28),
+ (8, "2013-07-15 15:04:00.000", 29),
+ ])
+ smhc.main(batch_size=3)
+ self.assert_said(smhc,
+ 'Last student_module_id is 29',
+ 'Loaded stored state: {"next_student_module_id": 25}',
+ '(not really cleaning 25)',
+ '(not really cleaning 26)',
+ "Couldn't clean student_module_id 26:\nTraceback*Exception: Something went wrong!\n",
+ '(not really cleaning 27)',
+ '(not really committing)',
+ 'Saved state: {"next_student_module_id": 28}',
+ '(not really cleaning 28)',
+ '(not really cleaning 29)',
+ '(not really committing)',
+ 'Saved state: {"next_student_module_id": 30}',
+ )
diff --git a/lms/djangoapps/courseware/model_data.py b/lms/djangoapps/courseware/model_data.py
index 790f1fd721..44be16e441 100644
--- a/lms/djangoapps/courseware/model_data.py
+++ b/lms/djangoapps/courseware/model_data.py
@@ -12,9 +12,14 @@ from .models import (
XModuleStudentPrefsField,
XModuleStudentInfoField
)
+import logging
+
+from django.db import DatabaseError
from xblock.runtime import KeyValueStore, InvalidScopeError
-from xblock.core import Scope
+from xblock.core import KeyValueMultiSaveError, Scope
+
+log = logging.getLogger(__name__)
class InvalidWriteError(Exception):
@@ -242,9 +247,10 @@ class ModelDataCache(object):
course_id=self.course_id,
student=self.user,
module_state_key=key.block_scope_id.url(),
- defaults={'state': json.dumps({}),
- 'module_type': key.block_scope_id.category,
- },
+ defaults={
+ 'state': json.dumps({}),
+ 'module_type': key.block_scope_id.category,
+ },
)
elif key.scope == Scope.content:
field_object, _ = XModuleContentField.objects.get_or_create(
@@ -328,22 +334,57 @@ class LmsKeyValueStore(KeyValueStore):
return json.loads(field_object.value)
def set(self, key, value):
- if key.field_name in self._descriptor_model_data:
- raise InvalidWriteError("Not allowed to overwrite descriptor model data", key.field_name)
+ """
+ Set a single value in the KeyValueStore
+ """
+ self.set_many({key: value})
- field_object = self._model_data_cache.find_or_create(key)
+ def set_many(self, kv_dict):
+ """
+ Provide a bulk save mechanism.
- if key.scope not in self._allowed_scopes:
- raise InvalidScopeError(key.scope)
+ `kv_dict`: A dictionary of dirty fields that maps
+ xblock.DbModel._key : value
- if key.scope == Scope.user_state:
- state = json.loads(field_object.state)
- state[key.field_name] = value
- field_object.state = json.dumps(state)
- else:
- field_object.value = json.dumps(value)
+ """
+ saved_fields = []
+ # field_objects maps a field_object to a list of associated fields
+ field_objects = dict()
+ for field in kv_dict:
+ # Check field for validity
+ if field.field_name in self._descriptor_model_data:
+ raise InvalidWriteError("Not allowed to overwrite descriptor model data", field.field_name)
- field_object.save()
+ if field.scope not in self._allowed_scopes:
+ raise InvalidScopeError(field.scope)
+
+ # If the field is valid and isn't already in the dictionary, add it.
+ field_object = self._model_data_cache.find_or_create(field)
+ if field_object not in field_objects.keys():
+ field_objects[field_object] = []
+ # Update the list of associated fields
+ field_objects[field_object].append(field)
+
+ # Special case when scope is for the user state, because this scope saves fields in a single row
+ if field.scope == Scope.user_state:
+ state = json.loads(field_object.state)
+ state[field.field_name] = kv_dict[field]
+ field_object.state = json.dumps(state)
+ else:
+ # The remaining scopes save fields on different rows, so
+ # we don't have to worry about conflicts
+ field_object.value = json.dumps(kv_dict[field])
+
+ for field_object in field_objects:
+ try:
+ # Save the field object that we made above
+ field_object.save()
+ # If save is successful on this scope, add the saved fields to
+ # the list of successful saves
+ saved_fields.extend([field.field_name for field in field_objects[field_object]])
+ except DatabaseError:
+ log.error('Error saving fields %r', field_objects[field_object])
+ raise KeyValueMultiSaveError(saved_fields)
def delete(self, key):
if key.field_name in self._descriptor_model_data:
diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py
index db7ba1641e..de709f7652 100644
--- a/lms/djangoapps/courseware/module_render.py
+++ b/lms/djangoapps/courseware/module_render.py
@@ -10,7 +10,7 @@ from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.http import Http404
-from django.http import HttpResponse, HttpResponseBadRequest
+from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import pyparsing
@@ -27,7 +27,7 @@ from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.x_module import ModuleSystem
-from xmodule_modifiers import replace_course_urls, replace_static_urls, add_histogram, wrap_xmodule
+from xmodule_modifiers import replace_course_urls, replace_static_urls, add_histogram, wrap_xmodule, save_module # pylint: disable=F0401
import static_replace
from psychometrics.psychoanalyze import make_psychometrics_data_update_handler
@@ -36,8 +36,11 @@ from student.models import unique_id_for_user
from courseware.access import has_access
from courseware.masquerade import setup_masquerade
from courseware.model_data import LmsKeyValueStore, LmsUsage, ModelDataCache
+from xblock.runtime import KeyValueStore
+from xblock.core import Scope
from courseware.models import StudentModule
from util.sandboxing import can_execute_unsafe_code
+from util.json_request import JsonResponse
log = logging.getLogger(__name__)
@@ -225,7 +228,7 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
userid=str(user.id),
mod_id=descriptor.location.url(),
dispatch=dispatch),
- )
+ )
return xqueue_callback_url_prefix + relative_xqueue_callback_url
# Default queuename is course-specific and is derived from the course that
@@ -233,11 +236,12 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
# TODO: Queuename should be derived from 'course_settings.json' of each course
xqueue_default_queuename = descriptor.location.org + '-' + descriptor.location.course
- xqueue = {'interface': xqueue_interface,
- 'construct_callback': make_xqueue_callback,
- 'default_queuename': xqueue_default_queuename.replace(' ', '_'),
- 'waittime': settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS
- }
+ xqueue = {
+ 'interface': xqueue_interface,
+ 'construct_callback': make_xqueue_callback,
+ 'default_queuename': xqueue_default_queuename.replace(' ', '_'),
+ 'waittime': settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS
+ }
# This is a hacky way to pass settings to the combined open ended xmodule
# It needs an S3 interface to upload images to S3
@@ -285,18 +289,24 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
)
def publish(event):
+ """A function that allows XModules to publish events. This only supports grade changes right now."""
if event.get('event_name') != 'grade':
return
- student_module, created = StudentModule.objects.get_or_create(
- course_id=course_id,
- student=user,
- module_type=descriptor.location.category,
- module_state_key=descriptor.location.url(),
- defaults={'state': '{}'},
+ usage = LmsUsage(descriptor.location, descriptor.location)
+ # Construct the key for the module
+ key = KeyValueStore.Key(
+ scope=Scope.user_state,
+ student_id=user.id,
+ block_scope_id=usage.id,
+ field_name='grade'
)
+
+ student_module = model_data_cache.find_or_create(key)
+ # Update the grades
student_module.grade = event.get('value')
student_module.max_grade = event.get('max_value')
+ # Save all changes to the underlying KeyValueStore
student_module.save()
# Bin score into range and increment stats
@@ -387,9 +397,31 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
if has_access(user, module, 'staff', course_id):
module.get_html = add_histogram(module.get_html, module, user)
+ # force the module to save after rendering
+ module.get_html = save_module(module.get_html, module)
return module
+def find_target_student_module(request, user_id, course_id, mod_id):
+ """
+ Retrieve target StudentModule
+ """
+ user = User.objects.get(id=user_id)
+ model_data_cache = ModelDataCache.cache_for_descriptor_descendents(
+ course_id,
+ user,
+ modulestore().get_instance(course_id, mod_id),
+ depth=0,
+ select_for_update=True
+ )
+ instance = get_module(user, request, mod_id, model_data_cache, course_id, grade_bucket_type='xqueue')
+ if instance is None:
+ msg = "No module {0} for user {1}--access denied?".format(mod_id, user)
+ log.debug(msg)
+ raise Http404
+ return instance
+
+
@csrf_exempt
def xqueue_callback(request, course_id, userid, mod_id, dispatch):
'''
@@ -408,20 +440,7 @@ def xqueue_callback(request, course_id, userid, mod_id, dispatch):
if not isinstance(header, dict) or 'lms_key' not in header:
raise Http404
- # Retrieve target StudentModule
- user = User.objects.get(id=userid)
- model_data_cache = ModelDataCache.cache_for_descriptor_descendents(
- course_id,
- user,
- modulestore().get_instance(course_id, mod_id),
- depth=0,
- select_for_update=True
- )
- instance = get_module(user, request, mod_id, model_data_cache, course_id, grade_bucket_type='xqueue')
- if instance is None:
- msg = "No module {0} for user {1}--access denied?".format(mod_id, user)
- log.debug(msg)
- raise Http404
+ instance = find_target_student_module(request, userid, course_id, mod_id)
# Transfer 'queuekey' from xqueue response header to the data.
# This is required to use the interface defined by 'handle_ajax'
@@ -432,6 +451,8 @@ def xqueue_callback(request, course_id, userid, mod_id, dispatch):
try:
# Can ignore the return value--not used for xqueue_callback
instance.handle_ajax(dispatch, data)
+ # Save any state that has changed to the underlying KeyValueStore
+ instance.save()
except:
log.exception("error processing ajax call")
raise
@@ -503,17 +524,19 @@ def modx_dispatch(request, dispatch, location, course_id):
# Let the module handle the AJAX
try:
ajax_return = instance.handle_ajax(dispatch, data)
+ # Save any fields that have changed to the underlying KeyValueStore
+ instance.save()
# If we can't find the module, respond with a 404
except NotFoundError:
log.exception("Module indicating to user that request doesn't exist")
raise Http404
- # For XModule-specific errors, we respond with 400
- except ProcessingError:
- log.warning("Module encountered an error while prcessing AJAX call",
+ # For XModule-specific errors, we log the error and respond with an error message
+ except ProcessingError as err:
+ log.warning("Module encountered an error while processing AJAX call",
exc_info=True)
- return HttpResponseBadRequest()
+ return JsonResponse(object={'success': err.args[0]}, status=200)
# If any other error occurred, re-raise it to trigger a 500 response
except:
diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py
index 0abbaa02cf..31fe376d69 100644
--- a/lms/djangoapps/courseware/tests/__init__.py
+++ b/lms/djangoapps/courseware/tests/__init__.py
@@ -29,17 +29,17 @@ class BaseTestXmodule(ModuleStoreTestCase):
2. create, enrol and login users for this course;
Any xmodule should overwrite only next parameters for test:
- 1. TEMPLATE_NAME
+ 1. CATEGORY
2. DATA
3. MODEL_DATA
- This class should not contain any tests, because TEMPLATE_NAME
+ This class should not contain any tests, because CATEGORY
should be defined in child class.
"""
USER_COUNT = 2
# Data from YAML common/lib/xmodule/xmodule/templates/NAME/default.yaml
- TEMPLATE_NAME = ""
+ CATEGORY = ""
DATA = ''
MODEL_DATA = {'data': ''}
@@ -53,11 +53,11 @@ class BaseTestXmodule(ModuleStoreTestCase):
chapter = ItemFactory.create(
parent_location=self.course.location,
- template="i4x://edx/templates/sequential/Empty",
+ category="sequential",
)
section = ItemFactory.create(
parent_location=chapter.location,
- template="i4x://edx/templates/sequential/Empty"
+ category="sequential"
)
# username = robot{0}, password = 'test'
@@ -71,7 +71,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
self.item_descriptor = ItemFactory.create(
parent_location=section.location,
- template=self.TEMPLATE_NAME,
+ category=self.CATEGORY,
data=self.DATA
)
diff --git a/lms/djangoapps/courseware/tests/test_model_data.py b/lms/djangoapps/courseware/tests/test_model_data.py
index e961f80939..0368bb040b 100644
--- a/lms/djangoapps/courseware/tests/test_model_data.py
+++ b/lms/djangoapps/courseware/tests/test_model_data.py
@@ -1,5 +1,8 @@
+"""
+Test for lms courseware app, module data (runtime data storage for XBlocks)
+"""
import json
-from mock import Mock
+from mock import Mock, patch
from functools import partial
from courseware.model_data import LmsKeyValueStore, InvalidWriteError
@@ -15,6 +18,8 @@ from courseware.tests.factories import StudentPrefsFactory, StudentInfoFactory
from xblock.core import Scope, BlockScope
from xmodule.modulestore import Location
from django.test import TestCase
+from django.db import DatabaseError
+from xblock.core import KeyValueMultiSaveError
def mock_field(scope, name):
@@ -66,12 +71,17 @@ class TestDescriptorFallback(TestCase):
self.assertRaises(InvalidWriteError, self.kvs.set, settings_key('field_b'), 'foo')
self.assertEquals('settings', self.desc_md['field_b'])
+ self.assertRaises(InvalidWriteError, self.kvs.set_many, {content_key('field_a'): 'foo'})
+ self.assertEquals('content', self.desc_md['field_a'])
+
self.assertRaises(InvalidWriteError, self.kvs.delete, content_key('field_a'))
self.assertEquals('content', self.desc_md['field_a'])
self.assertRaises(InvalidWriteError, self.kvs.delete, settings_key('field_b'))
self.assertEquals('settings', self.desc_md['field_b'])
+
+
class TestInvalidScopes(TestCase):
def setUp(self):
self.desc_md = {}
@@ -83,17 +93,20 @@ class TestInvalidScopes(TestCase):
for scope in (Scope(user=True, block=BlockScope.DEFINITION),
Scope(user=False, block=BlockScope.TYPE),
Scope(user=False, block=BlockScope.ALL)):
- self.assertRaises(InvalidScopeError, self.kvs.get, LmsKeyValueStore.Key(scope, None, None, 'field'))
- self.assertRaises(InvalidScopeError, self.kvs.set, LmsKeyValueStore.Key(scope, None, None, 'field'), 'value')
- self.assertRaises(InvalidScopeError, self.kvs.delete, LmsKeyValueStore.Key(scope, None, None, 'field'))
- self.assertRaises(InvalidScopeError, self.kvs.has, LmsKeyValueStore.Key(scope, None, None, 'field'))
+ key = LmsKeyValueStore.Key(scope, None, None, 'field')
+
+ self.assertRaises(InvalidScopeError, self.kvs.get, key)
+ self.assertRaises(InvalidScopeError, self.kvs.set, key, 'value')
+ self.assertRaises(InvalidScopeError, self.kvs.delete, key)
+ self.assertRaises(InvalidScopeError, self.kvs.has, key)
+ self.assertRaises(InvalidScopeError, self.kvs.set_many, {key: 'value'})
class TestStudentModuleStorage(TestCase):
def setUp(self):
self.desc_md = {}
- student_module = StudentModuleFactory(state=json.dumps({'a_field': 'a_value'}))
+ student_module = StudentModuleFactory(state=json.dumps({'a_field': 'a_value', 'b_field': 'b_value'}))
self.user = student_module.student
self.mdc = ModelDataCache([mock_descriptor([mock_field(Scope.user_state, 'a_field')])], course_id, self.user)
self.kvs = LmsKeyValueStore(self.desc_md, self.mdc)
@@ -110,13 +123,13 @@ class TestStudentModuleStorage(TestCase):
"Test that setting an existing user_state field changes the value"
self.kvs.set(user_state_key('a_field'), 'new_value')
self.assertEquals(1, StudentModule.objects.all().count())
- self.assertEquals({'a_field': 'new_value'}, json.loads(StudentModule.objects.all()[0].state))
+ self.assertEquals({'b_field': 'b_value', 'a_field': 'new_value'}, json.loads(StudentModule.objects.all()[0].state))
def test_set_missing_field(self):
"Test that setting a new user_state field changes the value"
self.kvs.set(user_state_key('not_a_field'), 'new_value')
self.assertEquals(1, StudentModule.objects.all().count())
- self.assertEquals({'a_field': 'a_value', 'not_a_field': 'new_value'}, json.loads(StudentModule.objects.all()[0].state))
+ self.assertEquals({'b_field': 'b_value', 'a_field': 'a_value', 'not_a_field': 'new_value'}, json.loads(StudentModule.objects.all()[0].state))
def test_delete_existing_field(self):
"Test that deleting an existing field removes it from the StudentModule"
@@ -128,7 +141,7 @@ class TestStudentModuleStorage(TestCase):
"Test that deleting a missing field from an existing StudentModule raises a KeyError"
self.assertRaises(KeyError, self.kvs.delete, user_state_key('not_a_field'))
self.assertEquals(1, StudentModule.objects.all().count())
- self.assertEquals({'a_field': 'a_value'}, json.loads(StudentModule.objects.all()[0].state))
+ self.assertEquals({'b_field': 'b_value', 'a_field': 'a_value'}, json.loads(StudentModule.objects.all()[0].state))
def test_has_existing_field(self):
"Test that `has` returns True for existing fields in StudentModules"
@@ -138,6 +151,35 @@ class TestStudentModuleStorage(TestCase):
"Test that `has` returns False for missing fields in StudentModule"
self.assertFalse(self.kvs.has(user_state_key('not_a_field')))
+ def construct_kv_dict(self):
+ """Construct a kv_dict that can be passed to set_many"""
+ key1 = user_state_key('field_a')
+ key2 = user_state_key('field_b')
+ new_value = 'new value'
+ newer_value = 'newer value'
+ return {key1: new_value, key2: newer_value}
+
+ def test_set_many(self):
+ "Test setting many fields that are scoped to Scope.user_state"
+ kv_dict = self.construct_kv_dict()
+ self.kvs.set_many(kv_dict)
+
+ for key in kv_dict:
+ self.assertEquals(self.kvs.get(key), kv_dict[key])
+
+ def test_set_many_failure(self):
+ "Test failures when setting many fields that are scoped to Scope.user_state"
+ kv_dict = self.construct_kv_dict()
+ # because we're patching the underlying save, we need to ensure the
+ # fields are in the cache
+ for key in kv_dict:
+ self.kvs.set(key, 'test_value')
+
+ with patch('django.db.models.Model.save', side_effect=DatabaseError):
+ with self.assertRaises(KeyValueMultiSaveError) as exception_context:
+ self.kvs.set_many(kv_dict)
+ self.assertEquals(len(exception_context.exception.saved_field_names), 0)
+
class TestMissingStudentModule(TestCase):
def setUp(self):
@@ -176,6 +218,14 @@ class TestMissingStudentModule(TestCase):
class StorageTestBase(object):
+ """
+ A base class for that gets subclassed when testing each of the scopes.
+
+ """
+ # Disable pylint warnings that arise because of the way the child classes call
+ # this base class -- pylint's static analysis can't keep up with it.
+ # pylint: disable=E1101, E1102
+
factory = None
scope = None
key_factory = None
@@ -188,7 +238,10 @@ class StorageTestBase(object):
else:
self.user = UserFactory.create()
self.desc_md = {}
- self.mdc = ModelDataCache([mock_descriptor([mock_field(self.scope, 'existing_field')])], course_id, self.user)
+ self.mock_descriptor = mock_descriptor([
+ mock_field(self.scope, 'existing_field'),
+ mock_field(self.scope, 'other_existing_field')])
+ self.mdc = ModelDataCache([self.mock_descriptor], course_id, self.user)
self.kvs = LmsKeyValueStore(self.desc_md, self.mdc)
def test_set_and_get_existing_field(self):
@@ -234,6 +287,38 @@ class StorageTestBase(object):
"Test that `has` return False for an existing Storage Field"
self.assertFalse(self.kvs.has(self.key_factory('missing_field')))
+ def construct_kv_dict(self):
+ """Construct a kv_dict that can be passed to set_many"""
+ key1 = self.key_factory('existing_field')
+ key2 = self.key_factory('other_existing_field')
+ new_value = 'new value'
+ newer_value = 'newer value'
+ return {key1: new_value, key2: newer_value}
+
+ def test_set_many(self):
+ """Test that setting many regular fields at the same time works"""
+ kv_dict = self.construct_kv_dict()
+
+ self.kvs.set_many(kv_dict)
+ for key in kv_dict:
+ self.assertEquals(self.kvs.get(key), kv_dict[key])
+
+ def test_set_many_failure(self):
+ """Test that setting many regular fields with a DB error """
+ kv_dict = self.construct_kv_dict()
+ for key in kv_dict:
+ self.kvs.set(key, 'test value')
+
+ with patch('django.db.models.Model.save', side_effect=[None, DatabaseError]):
+ with self.assertRaises(KeyValueMultiSaveError) as exception_context:
+ self.kvs.set_many(kv_dict)
+
+ exception = exception_context.exception
+ self.assertEquals(len(exception.saved_field_names), 1)
+ self.assertEquals(exception.saved_field_names[0], 'existing_field')
+
+
+
class TestSettingsStorage(StorageTestBase, TestCase):
factory = SettingsFactory
diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py
index a9060b57e9..732758be2c 100644
--- a/lms/djangoapps/courseware/tests/test_module_render.py
+++ b/lms/djangoapps/courseware/tests/test_module_render.py
@@ -1,4 +1,7 @@
-from mock import MagicMock
+"""
+Test for lms courseware app, module render unit
+"""
+from mock import MagicMock, patch
import json
from django.http import Http404, HttpResponse
@@ -28,6 +31,20 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
self.location = ['i4x', 'edX', 'toy', 'chapter', 'Overview']
self.course_id = 'edX/toy/2012_Fall'
self.toy_course = modulestore().get_course(self.course_id)
+ self.mock_user = UserFactory()
+ self.mock_user.id = 1
+ self.request_factory = RequestFactory()
+
+ # Construct a mock module for the modulestore to return
+ self.mock_module = MagicMock()
+ self.mock_module.id = 1
+ self.dispatch = 'score_update'
+
+ # Construct a 'standard' xqueue_callback url
+ self.callback_url = reverse('xqueue_callback', kwargs=dict(course_id=self.course_id,
+ userid=str(self.mock_user.id),
+ mod_id=self.mock_module.id,
+ dispatch=self.dispatch))
def test_get_module(self):
self.assertIsNone(render.get_module('dummyuser', None,
@@ -56,7 +73,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
mock_request_3 = MagicMock()
mock_request_3.POST.copy.return_value = {'position': 1}
mock_request_3.FILES = False
- mock_request_3.user = UserFactory()
+ mock_request_3.user = self.mock_user
inputfile_2 = Stub()
inputfile_2.size = 1
inputfile_2.name = 'name'
@@ -87,6 +104,46 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
self.course_id
)
+ def test_xqueue_callback_success(self):
+ """
+ Test for happy-path xqueue_callback
+ """
+ fake_key = 'fake key'
+ xqueue_header = json.dumps({'lms_key': fake_key})
+ data = {
+ 'xqueue_header': xqueue_header,
+ 'xqueue_body': 'hello world',
+ }
+
+ # Patch getmodule to return our mock module
+ with patch('courseware.module_render.find_target_student_module') as get_fake_module:
+ get_fake_module.return_value = self.mock_module
+ # call xqueue_callback with our mocked information
+ request = self.request_factory.post(self.callback_url, data)
+ render.xqueue_callback(request, self.course_id, self.mock_user.id, self.mock_module.id, self.dispatch)
+
+ # Verify that handle ajax is called with the correct data
+ request.POST['queuekey'] = fake_key
+ self.mock_module.handle_ajax.assert_called_once_with(self.dispatch, request.POST)
+
+ def test_xqueue_callback_missing_header_info(self):
+ data = {
+ 'xqueue_header': '{}',
+ 'xqueue_body': 'hello world',
+ }
+
+ with patch('courseware.module_render.find_target_student_module') as get_fake_module:
+ get_fake_module.return_value = self.mock_module
+ # Test with missing xqueue data
+ with self.assertRaises(Http404):
+ request = self.request_factory.post(self.callback_url, {})
+ render.xqueue_callback(request, self.course_id, self.mock_user.id, self.mock_module.id, self.dispatch)
+
+ # Test with missing xqueue_header
+ with self.assertRaises(Http404):
+ request = self.request_factory.post(self.callback_url, data)
+ render.xqueue_callback(request, self.course_id, self.mock_user.id, self.mock_module.id, self.dispatch)
+
def test_get_score_bucket(self):
self.assertEquals(render.get_score_bucket(0, 10), 'incorrect')
self.assertEquals(render.get_score_bucket(1, 10), 'partial')
diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py
index 83ae7dc73e..9081a910c9 100644
--- a/lms/djangoapps/courseware/tests/test_submitting_problems.py
+++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py
@@ -59,7 +59,7 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
Returns the url of the problem given the problem's name
"""
- return "i4x://"+self.course.org+"/{}/problem/{}".format(self.COURSE_SLUG, problem_url_name)
+ return "i4x://" + self.course.org + "/{}/problem/{}".format(self.COURSE_SLUG, problem_url_name)
def modx_url(self, problem_location, dispatch):
"""
@@ -107,6 +107,15 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
resp = self.client.post(modx_url)
return resp
+ def show_question_answer(self, problem_url_name):
+ """
+ Shows the answer to the current student.
+ """
+ problem_location = self.problem_location(problem_url_name)
+ modx_url = self.modx_url(problem_location, 'problem_show')
+ resp = self.client.post(modx_url)
+ return resp
+
def add_dropdown_to_section(self, section_location, name, num_inputs=2):
"""
Create and return a dropdown problem.
@@ -119,7 +128,6 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
num_input: the number of input fields to create in the problem
"""
- problem_template = "i4x://edx/templates/problem/Blank_Common_Problem"
prob_xml = OptionResponseXMLFactory().build_xml(
question_text='The correct answer is Correct',
num_inputs=num_inputs,
@@ -130,9 +138,9 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
problem = ItemFactory.create(
parent_location=section_location,
- template=problem_template,
+ category='problem',
data=prob_xml,
- metadata={'randomize': 'always'},
+ metadata={'rerandomize': 'always'},
display_name=name
)
@@ -140,7 +148,7 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.refresh_course()
return problem
- def add_graded_section_to_course(self, name, section_format='Homework'):
+ def add_graded_section_to_course(self, name, section_format='Homework', late=False, reset=False, showanswer=False):
"""
Creates a graded homework section within a chapter and returns the section.
"""
@@ -149,15 +157,47 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
if not(hasattr(self, 'chapter')):
self.chapter = ItemFactory.create(
parent_location=self.course.location,
- template="i4x://edx/templates/chapter/Empty",
+ category='chapter'
)
- section = ItemFactory.create(
- parent_location=self.chapter.location,
- display_name=name,
- template="i4x://edx/templates/sequential/Empty",
- metadata={'graded': True, 'format': section_format}
- )
+ if late:
+ section = ItemFactory.create(
+ parent_location=self.chapter.location,
+ display_name=name,
+ category='sequential',
+ metadata={'graded': True, 'format': section_format, 'due': '2013-05-20T23:30'}
+ )
+ elif reset:
+ section = ItemFactory.create(
+ parent_location=self.chapter.location,
+ display_name=name,
+ category='sequential',
+ rerandomize='always',
+ metadata={
+ 'graded': True,
+ 'format': section_format,
+ }
+ )
+
+ elif showanswer:
+ section = ItemFactory.create(
+ parent_location=self.chapter.location,
+ display_name=name,
+ category='sequential',
+ showanswer='never',
+ metadata={
+ 'graded': True,
+ 'format': section_format,
+ }
+ )
+
+ else:
+ section = ItemFactory.create(
+ parent_location=self.chapter.location,
+ display_name=name,
+ category='sequential',
+ metadata={'graded': True, 'format': section_format}
+ )
# now that we've added the problem and section to the course
# we fetch the course from the database so the object we are
@@ -258,7 +298,7 @@ class TestCourseGrader(TestSubmittingProblems):
hw_section = next(section for section in sections_list if section.get('url_name') == hw_url_name)
return [s.earned for s in hw_section['scores']]
- def basic_setup(self):
+ def basic_setup(self, late=False, reset=False, showanswer=False):
"""
Set up a simple course for testing basic grading functionality.
"""
@@ -279,7 +319,7 @@ class TestCourseGrader(TestSubmittingProblems):
self.add_grading_policy(grading_policy)
# set up a simple course with four problems
- self.homework = self.add_graded_section_to_course('homework')
+ self.homework = self.add_graded_section_to_course('homework', late=late, reset=reset, showanswer=showanswer)
self.add_dropdown_to_section(self.homework.location, 'p1', 1)
self.add_dropdown_to_section(self.homework.location, 'p2', 1)
self.add_dropdown_to_section(self.homework.location, 'p3', 1)
@@ -347,6 +387,41 @@ class TestCourseGrader(TestSubmittingProblems):
self.add_dropdown_to_section(self.homework3.location, self.hw3_names[0], 1)
self.add_dropdown_to_section(self.homework3.location, self.hw3_names[1], 1)
+ def test_submission_late(self):
+ """Test problem for due date in the past"""
+ self.basic_setup(late=True)
+ resp = self.submit_question_answer('p1', {'2_1': 'Correct'})
+ self.assertEqual(resp.status_code, 200)
+ err_msg = (
+ "The state of this problem has changed since you loaded this page. "
+ "Please refresh your page."
+ )
+ self.assertEqual(json.loads(resp.content).get("success"), err_msg)
+
+ def test_submission_reset(self):
+ """Test problem ProcessingErrors due to resets"""
+ self.basic_setup(reset=True)
+ resp = self.submit_question_answer('p1', {'2_1': 'Correct'})
+ # submit a second time to draw NotFoundError
+ resp = self.submit_question_answer('p1', {'2_1': 'Correct'})
+ self.assertEqual(resp.status_code, 200)
+ err_msg = (
+ "The state of this problem has changed since you loaded this page. "
+ "Please refresh your page."
+ )
+ self.assertEqual(json.loads(resp.content).get("success"), err_msg)
+
+ def test_submission_show_answer(self):
+ """Test problem for ProcessingErrors due to showing answer"""
+ self.basic_setup(showanswer=True)
+ resp = self.show_question_answer('p1')
+ self.assertEqual(resp.status_code, 200)
+ err_msg = (
+ "The state of this problem has changed since you loaded this page. "
+ "Please refresh your page."
+ )
+ self.assertEqual(json.loads(resp.content).get("success"), err_msg)
+
def test_none_grade(self):
"""
Check grade is 0 to begin with.
@@ -405,7 +480,7 @@ class TestCourseGrader(TestSubmittingProblems):
# Get both parts correct
self.submit_question_answer('H1P1', {'2_1': 'Correct', '2_2': 'Correct'})
self.check_grade_percent(0.25)
- self.assertEqual(self.earned_hw_scores(), [2.0]) # Order matters
+ self.assertEqual(self.earned_hw_scores(), [2.0]) # Order matters
self.assertEqual(self.score_for_hw('homework'), [2.0])
def test_weighted_exam(self):
@@ -443,7 +518,7 @@ class TestCourseGrader(TestSubmittingProblems):
self.assertEqual(self.score_for_hw('homework1'), [1.0, 0.0])
self.assertEqual(self.score_for_hw('homework2'), [1.0, 1.0])
- self.assertEqual(self.earned_hw_scores(), [1.0, 2.0, 0]) # Order matters
+ self.assertEqual(self.earned_hw_scores(), [1.0, 2.0, 0]) # Order matters
self.check_grade_percent(0.75)
def test_dropping_nochange(self):
@@ -457,7 +532,7 @@ class TestCourseGrader(TestSubmittingProblems):
self.assertEqual(self.score_for_hw('homework1'), [1.0, 0.0])
self.assertEqual(self.score_for_hw('homework2'), [1.0, 1.0])
self.assertEqual(self.score_for_hw('homework3'), [1.0, 0.0])
- self.assertEqual(self.earned_hw_scores(), [1.0, 2.0, 1.0]) # Order matters
+ self.assertEqual(self.earned_hw_scores(), [1.0, 2.0, 1.0]) # Order matters
self.check_grade_percent(0.75)
def test_dropping_all_correct(self):
@@ -471,7 +546,7 @@ class TestCourseGrader(TestSubmittingProblems):
self.submit_question_answer(name, {'2_1': 'Correct'})
self.check_grade_percent(1.0)
- self.assertEqual(self.earned_hw_scores(), [1.0, 2.0, 2.0]) # Order matters
+ self.assertEqual(self.earned_hw_scores(), [1.0, 2.0, 2.0]) # Order matters
self.assertEqual(self.score_for_hw('homework3'), [1.0, 1.0])
@@ -579,13 +654,13 @@ class TestPythonGradedResponse(TestSubmittingProblems):
set up an example Circuit_Schematic_Builder problem
"""
- schematic_template = "i4x://edx/templates/problem/Circuit_Schematic_Builder"
script = self.SCHEMATIC_SCRIPT
xmldata = SchematicResponseXMLFactory().build_xml(answer=script)
ItemFactory.create(
parent_location=self.section.location,
- template=schematic_template,
+ category='problem',
+ boilerplate='circuitschematic.yaml',
display_name=name,
data=xmldata
)
@@ -602,14 +677,14 @@ class TestPythonGradedResponse(TestSubmittingProblems):
set up an example custom response problem using a check function
"""
- custom_template = "i4x://edx/templates/problem/Custom_Python-Evaluated_Input"
test_csv = self.CUSTOM_RESPONSE_SCRIPT
expect = self.CUSTOM_RESPONSE_CORRECT
cfn_problem_xml = CustomResponseXMLFactory().build_xml(script=test_csv, cfn='test_csv', expect=expect)
ItemFactory.create(
parent_location=self.section.location,
- template=custom_template,
+ category='problem',
+ boilerplate='customgrader.yaml',
data=cfn_problem_xml,
display_name=name
)
@@ -628,13 +703,12 @@ class TestPythonGradedResponse(TestSubmittingProblems):
script = self.COMPUTED_ANSWER_SCRIPT
- custom_template = "i4x://edx/templates/problem/Custom_Python-Evaluated_Input"
-
computed_xml = CustomResponseXMLFactory().build_xml(answer=script)
ItemFactory.create(
parent_location=self.section.location,
- template=custom_template,
+ category='problem',
+ boilerplate='customgrader.yaml',
data=computed_xml,
display_name=name
)
diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py
index a0fdecc77a..829308423c 100644
--- a/lms/djangoapps/courseware/tests/test_video_mongo.py
+++ b/lms/djangoapps/courseware/tests/test_video_mongo.py
@@ -7,7 +7,7 @@ from . import BaseTestXmodule
class TestVideo(BaseTestXmodule):
"""Integration tests: web client + mongo."""
- TEMPLATE_NAME = "i4x://edx/templates/video/default"
+ TEMPLATE_NAME = "video"
DATA = ''
def test_handle_ajax_dispatch(self):
diff --git a/lms/djangoapps/courseware/tests/test_videoalpha_mongo.py b/lms/djangoapps/courseware/tests/test_videoalpha_mongo.py
index 182cbab9e7..d5afb1a78c 100644
--- a/lms/djangoapps/courseware/tests/test_videoalpha_mongo.py
+++ b/lms/djangoapps/courseware/tests/test_videoalpha_mongo.py
@@ -9,7 +9,7 @@ from django.conf import settings
class TestVideo(BaseTestXmodule):
"""Integration tests: web client + mongo."""
- TEMPLATE_NAME = "i4x://edx/templates/videoalpha/Video_Alpha"
+ CATEGORY = "videoalpha"
DATA = SOURCE_XML
MODEL_DATA = {
'data': DATA
diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py
index a5efe744a8..07be74c98e 100644
--- a/lms/djangoapps/courseware/tests/test_views.py
+++ b/lms/djangoapps/courseware/tests/test_views.py
@@ -6,6 +6,7 @@ from django.http import Http404
from django.test.utils import override_settings
from django.contrib.auth.models import User
from django.test.client import RequestFactory
+from django.conf import settings
from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore
@@ -124,3 +125,26 @@ class ViewsTestCase(TestCase):
self.assertContains(result, expected_end_text)
else:
self.assertNotContains(result, "Classes End")
+
+ def test_chat_settings(self):
+ mock_user = MagicMock()
+ mock_user.username = "johndoe"
+
+ mock_course = MagicMock()
+ mock_course.id = "a/b/c"
+
+ # Stub this out in the case that it's not in the settings
+ domain = "jabber.edx.org"
+ settings.JABBER_DOMAIN = domain
+
+ chat_settings = views.chat_settings(mock_course, mock_user)
+
+ # Test the proper format of all chat settings
+ self.assertEquals(chat_settings['domain'], domain)
+ self.assertEquals(chat_settings['room'], "a-b-c_class")
+ self.assertEquals(chat_settings['username'], "johndoe@%s" % domain)
+
+ # TODO: this needs to be changed once we figure out how to
+ # generate/store a real password.
+ self.assertEquals(chat_settings['password'], "johndoe@%s" % domain)
+
diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py
index 17cc848ad3..fbe2c05ada 100644
--- a/lms/djangoapps/courseware/tests/tests.py
+++ b/lms/djangoapps/courseware/tests/tests.py
@@ -8,7 +8,6 @@ from django.core.urlresolvers import reverse
from django.test.utils import override_settings
import xmodule.modulestore.django
-
from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import Location
@@ -16,10 +15,11 @@ from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.xml import XMLModuleStore
from helpers import LoginEnrollmentTestCase
-from modulestore_config import TEST_DATA_DIR,\
- TEST_DATA_XML_MODULESTORE,\
- TEST_DATA_MONGO_MODULESTORE,\
+from modulestore_config import TEST_DATA_DIR, \
+ TEST_DATA_XML_MODULESTORE, \
+ TEST_DATA_MONGO_MODULESTORE, \
TEST_DATA_DRAFT_MONGO_MODULESTORE
+import xmodule
class ActivateLoginTest(LoginEnrollmentTestCase):
@@ -51,7 +51,7 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
"""
Choose a page in the course randomly, and assert that it loads.
"""
- # enroll in the course before trying to access pages
+ # enroll in the course before trying to access pages
courses = module_store.get_courses()
self.assertEqual(len(courses), 1)
course = courses[0]
@@ -134,7 +134,7 @@ class TestCoursesLoadTestCase_XmlModulestore(PageLoaderTestCase):
def setUp(self):
super(TestCoursesLoadTestCase_XmlModulestore, self).setUp()
self.setup_user()
- xmodule.modulestore.django._MODULESTORES = {}
+ xmodule.modulestore.django._MODULESTORES.clear()
def test_toy_course_loads(self):
module_class = 'xmodule.hidden_module.HiddenDescriptor'
@@ -155,7 +155,7 @@ class TestCoursesLoadTestCase_MongoModulestore(PageLoaderTestCase):
def setUp(self):
super(TestCoursesLoadTestCase_MongoModulestore, self).setUp()
self.setup_user()
- xmodule.modulestore.django._MODULESTORES = {}
+ xmodule.modulestore.django._MODULESTORES.clear()
modulestore().collection.drop()
def test_toy_course_loads(self):
diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py
index 9c5a665754..f1e1f7660c 100644
--- a/lms/djangoapps/courseware/views.py
+++ b/lms/djangoapps/courseware/views.py
@@ -40,7 +40,6 @@ log = logging.getLogger("mitx.courseware")
template_imports = {'urllib': urllib}
-
def user_groups(user):
"""
TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately.
@@ -167,6 +166,8 @@ def save_child_position(seq_module, child_name):
# Only save if position changed
if position != seq_module.position:
seq_module.position = position
+ # Save this new position to the underlying KeyValueStore
+ seq_module.save()
def check_for_active_timelimit_module(request, course_id, course):
@@ -234,6 +235,36 @@ def update_timelimit_module(user, course_id, model_data_cache, timelimit_descrip
return context
+def chat_settings(course, user):
+ """
+ Returns a dict containing the settings required to connect to a
+ Jabber chat server and room.
+ """
+ domain = getattr(settings, "JABBER_DOMAIN", None)
+ if domain is None:
+ log.warning('You must set JABBER_DOMAIN in the settings to '
+ 'enable the chat widget')
+ return None
+
+ return {
+ 'domain': domain,
+
+ # Jabber doesn't like slashes, so replace with dashes
+ 'room': "{ID}_class".format(ID=course.id.replace('/', '-')),
+
+ 'username': "{USER}@{DOMAIN}".format(
+ USER=user.username, DOMAIN=domain
+ ),
+
+ # TODO: clearly this needs to be something other than the username
+ # should also be something that's not necessarily tied to a
+ # particular course
+ 'password': "{USER}@{DOMAIN}".format(
+ USER=user.username, DOMAIN=domain
+ ),
+ }
+
+
@login_required
@ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
@@ -298,6 +329,18 @@ def index(request, course_id, chapter=None, section=None,
'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:server@content-qa.mitx.mit.edu/xqa')
}
+ # Only show the chat if it's enabled by the course and in the
+ # settings.
+ show_chat = course.show_chat and settings.MITX_FEATURES['ENABLE_CHAT']
+ if show_chat:
+ context['chat'] = chat_settings(course, user)
+ # If we couldn't load the chat settings, then don't show
+ # the widget in the courseware.
+ if context['chat'] is None:
+ show_chat = False
+
+ context['show_chat'] = show_chat
+
chapter_descriptor = course.get_child_by(lambda m: m.url_name == chapter)
if chapter_descriptor is not None:
save_child_position(course_module, chapter)
diff --git a/lms/djangoapps/foldit/models.py b/lms/djangoapps/foldit/models.py
index c0ef553d7e..d413731647 100644
--- a/lms/djangoapps/foldit/models.py
+++ b/lms/djangoapps/foldit/models.py
@@ -6,6 +6,7 @@ from django.db import models
log = logging.getLogger(__name__)
+
class Score(models.Model):
"""
This model stores the scores of different users on FoldIt problems.
@@ -35,9 +36,8 @@ class Score(models.Model):
"""
return (-score) * 10 + 8000 * sum_of
-
@staticmethod
- def get_tops_n(n, puzzles=['994559']):
+ def get_tops_n(n, puzzles=['994559'], course_list=None):
"""
Arguments:
puzzles: a list of puzzle ids that we will use. If not specified,
@@ -46,22 +46,34 @@ class Score(models.Model):
Returns:
- The top n sum of scores for puzzles in . Output is a list
- of disctionaries, sorted by display_score:
+ The top n sum of scores for puzzles in ,
+ filtered by course. If no courses is specified we default
+ the pool of students to all courses. Output is a list
+ of dictionaries, sorted by display_score:
[ {username: 'a_user',
score: 12000} ...]
"""
- if not(type(puzzles) == list):
+
+ if not isinstance(puzzles, list):
puzzles = [puzzles]
- scores = Score.objects \
- .filter(puzzle_id__in=puzzles) \
- .annotate(total_score=models.Sum('best_score')) \
- .order_by('total_score')[:n]
+ if course_list is None:
+ scores = Score.objects \
+ .filter(puzzle_id__in=puzzles) \
+ .annotate(total_score=models.Sum('best_score')) \
+ .order_by('total_score')[:n]
+ else:
+ scores = Score.objects \
+ .filter(puzzle_id__in=puzzles) \
+ .filter(user__courseenrollment__course_id__in=course_list) \
+ .annotate(total_score=models.Sum('best_score')) \
+ .order_by('total_score')[:n]
num = len(puzzles)
- return [{'username': s.user.username,
- 'score': Score.display_score(s.total_score, num)}
- for s in scores]
+ return [
+ {'username': score.user.username,
+ 'score': Score.display_score(score.total_score, num)}
+ for score in scores
+ ]
class PuzzleComplete(models.Model):
@@ -94,7 +106,6 @@ class PuzzleComplete(models.Model):
self.puzzle_set, self.puzzle_subset,
self.created)
-
@staticmethod
def completed_puzzles(anonymous_user_id):
"""
diff --git a/lms/djangoapps/foldit/tests.py b/lms/djangoapps/foldit/tests.py
index 1f354083a9..c97cd2b59d 100644
--- a/lms/djangoapps/foldit/tests.py
+++ b/lms/djangoapps/foldit/tests.py
@@ -2,14 +2,14 @@ import json
import logging
from functools import partial
-from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import RequestFactory
from django.core.urlresolvers import reverse
from foldit.views import foldit_ops, verify_code
from foldit.models import PuzzleComplete, Score
-from student.models import UserProfile, unique_id_for_user
+from student.models import unique_id_for_user
+from student.tests.factories import CourseEnrollmentFactory, UserFactory, UserProfileFactory
from datetime import datetime, timedelta
from pytz import UTC
@@ -23,17 +23,25 @@ class FolditTestCase(TestCase):
self.factory = RequestFactory()
self.url = reverse('foldit_ops')
- pwd = 'abc'
- self.user = User.objects.create_user('testuser', 'test@test.com', pwd)
- self.user2 = User.objects.create_user('testuser2', 'test2@test.com', pwd)
- self.unique_user_id = unique_id_for_user(self.user)
- self.unique_user_id2 = unique_id_for_user(self.user2)
+ self.course_id = 'course/id/1'
+ self.course_id2 = 'course/id/2'
+
+ self.user = UserFactory.create()
+ self.user2 = UserFactory.create()
+
+ self.course_enrollment = CourseEnrollmentFactory.create(
+ user=self.user, course_id=self.course_id
+ )
+ self.course_enrollment2 = CourseEnrollmentFactory.create(
+ user=self.user2, course_id=self.course_id2
+ )
+
now = datetime.now(UTC)
self.tomorrow = now + timedelta(days=1)
self.yesterday = now - timedelta(days=1)
- UserProfile.objects.create(user=self.user)
- UserProfile.objects.create(user=self.user2)
+ self.user.profile
+ self.user2.profile
def make_request(self, post_data, user=None):
request = self.factory.post(self.url, post_data)
@@ -150,6 +158,38 @@ class FolditTestCase(TestCase):
delta=0.5
)
+ def test_SetPlayerPuzzleScores_multiplecourses(self):
+ puzzle_id = "1"
+
+ player1_score = 0.05
+ player2_score = 0.06
+
+ course_list_1 = [self.course_id]
+ course_list_2 = [self.course_id2]
+
+ response1 = self.make_puzzle_score_request(
+ puzzle_id, player1_score, self.user
+ )
+ course_1_top_10 = Score.get_tops_n(10, puzzle_id, course_list_1)
+ course_2_top_10 = Score.get_tops_n(10, puzzle_id, course_list_2)
+ total_top_10 = Score.get_tops_n(10, puzzle_id)
+
+ # player1 should now be in the top 10 of course 1 and not in course 2
+ self.assertEqual(len(course_1_top_10), 1)
+ self.assertEqual(len(course_2_top_10), 0)
+ self.assertEqual(len(total_top_10), 1)
+
+ response2 = self.make_puzzle_score_request(
+ puzzle_id, player2_score, self.user2
+ )
+ course_2_top_10 = Score.get_tops_n(10, puzzle_id, course_list_2)
+ total_top_10 = Score.get_tops_n(10, puzzle_id)
+
+ # player2 should now be in the top 10 of course 2 and not in course 1
+ self.assertEqual(len(course_1_top_10), 1)
+ self.assertEqual(len(course_2_top_10), 1)
+ self.assertEqual(len(total_top_10), 2)
+
def test_SetPlayerPuzzleScores_manyplayers(self):
"""
Check that when we send scores from multiple users, the correct order
@@ -306,7 +346,7 @@ class FolditTestCase(TestCase):
self.set_puzzle_complete_response([13, 14, 15, 53524]))
is_complete = partial(
- PuzzleComplete.is_level_complete, self.unique_user_id)
+ PuzzleComplete.is_level_complete, unique_id_for_user(self.user))
self.assertTrue(is_complete(1, 1))
self.assertTrue(is_complete(1, 3))
diff --git a/lms/djangoapps/instructor/tests/test_gradebook.py b/lms/djangoapps/instructor/tests/test_gradebook.py
index 5ed0c1d1af..2677df59b2 100644
--- a/lms/djangoapps/instructor/tests/test_gradebook.py
+++ b/lms/djangoapps/instructor/tests/test_gradebook.py
@@ -34,11 +34,11 @@ class TestGradebook(ModuleStoreTestCase):
self.course = CourseFactory.create(**kwargs)
chapter = ItemFactory.create(
parent_location=self.course.location,
- template="i4x://edx/templates/sequential/Empty",
+ category="sequential",
)
section = ItemFactory.create(
parent_location=chapter.location,
- template="i4x://edx/templates/sequential/Empty",
+ category="sequential",
metadata={'graded': True, 'format': 'Homework'}
)
@@ -47,11 +47,11 @@ class TestGradebook(ModuleStoreTestCase):
for user in self.users:
CourseEnrollmentFactory.create(user=user, course_id=self.course.id)
- for i in xrange(USER_COUNT-1):
- template_name = "i4x://edx/templates/problem/Blank_Common_Problem"
+ for i in xrange(USER_COUNT - 1):
+ category = "problem"
item = ItemFactory.create(
parent_location=section.location,
- template=template_name,
+ category=category,
data=StringResponseXMLFactory().build_xml(answer='foo'),
metadata={'rerandomize': 'always'}
)
diff --git a/lms/djangoapps/instructor_task/tests/test_base.py b/lms/djangoapps/instructor_task/tests/test_base.py
index 5e51b9fdeb..b67453e997 100644
--- a/lms/djangoapps/instructor_task/tests/test_base.py
+++ b/lms/djangoapps/instructor_task/tests/test_base.py
@@ -119,7 +119,7 @@ class InstructorTaskModuleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase)
# add a sequence to the course to which the problems can be added
self.problem_section = ItemFactory.create(parent_location=chapter.location,
- template='i4x://edx/templates/sequential/Empty',
+ category='sequential',
display_name=TEST_SECTION_NAME)
@staticmethod
@@ -169,7 +169,7 @@ class InstructorTaskModuleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase)
'num_responses': 2}
problem_xml = factory.build_xml(**factory_args)
ItemFactory.create(parent_location=self.problem_section.location,
- template="i4x://edx/templates/problem/Blank_Common_Problem",
+ category="problem",
display_name=str(problem_url_name),
data=problem_xml)
diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py
index 9b56663753..fb8cd44169 100644
--- a/lms/djangoapps/instructor_task/tests/test_integration.py
+++ b/lms/djangoapps/instructor_task/tests/test_integration.py
@@ -243,7 +243,7 @@ class TestRescoringTask(TestIntegrationTask):
grader_payload=grader_payload,
num_responses=2)
ItemFactory.create(parent_location=self.problem_section.location,
- template="i4x://edx/templates/problem/Blank_Common_Problem",
+ category="problem",
display_name=str(problem_url_name),
data=problem_xml)
@@ -293,7 +293,7 @@ class TestRescoringTask(TestIntegrationTask):
# Per-student rerandomization will at least generate different seeds for different users, so
# we get a little more test coverage.
ItemFactory.create(parent_location=self.problem_section.location,
- template="i4x://edx/templates/problem/Blank_Common_Problem",
+ category="problem",
display_name=str(problem_url_name),
data=problem_xml,
metadata={"rerandomize": "per_student"})
diff --git a/lms/djangoapps/open_ended_grading/staff_grading_service.py b/lms/djangoapps/open_ended_grading/staff_grading_service.py
index 6b2b4707bb..a6a2847bc1 100644
--- a/lms/djangoapps/open_ended_grading/staff_grading_service.py
+++ b/lms/djangoapps/open_ended_grading/staff_grading_service.py
@@ -15,6 +15,7 @@ from xmodule.course_module import CourseDescriptor
from student.models import unique_id_for_user
from xmodule.x_module import ModuleSystem
from mitxmako.shortcuts import render_to_string
+from utils import does_location_exist
log = logging.getLogger(__name__)
@@ -240,7 +241,6 @@ def get_next(request, course_id):
return HttpResponse(_get_next(course_id, grader_id, location),
mimetype="application/json")
-
def get_problem_list(request, course_id):
"""
Get all the problems for the given course id
@@ -266,6 +266,20 @@ def get_problem_list(request, course_id):
_check_access(request.user, course_id)
try:
response = staff_grading_service().get_problem_list(course_id, unique_id_for_user(request.user))
+ response = json.loads(response)
+ problem_list = response['problem_list']
+ valid_problem_list = []
+ for i in xrange(0,len(problem_list)):
+ #Needed to ensure that the 'location' key can be accessed
+ try:
+ problem_list[i] = json.loads(problem_list[i])
+ except Exception:
+ pass
+ if does_location_exist(course_id, problem_list[i]['location']):
+ valid_problem_list.append(problem_list[i])
+ response['problem_list'] = valid_problem_list
+ response = json.dumps(response)
+
return HttpResponse(response,
mimetype="application/json")
except GradingServiceError:
diff --git a/lms/djangoapps/open_ended_grading/tests.py b/lms/djangoapps/open_ended_grading/tests.py
index a46b4b12fe..b2529e38db 100644
--- a/lms/djangoapps/open_ended_grading/tests.py
+++ b/lms/djangoapps/open_ended_grading/tests.py
@@ -161,7 +161,7 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
self.course_id = "edX/toy/2012_Fall"
self.toy = modulestore().get_course(self.course_id)
location = "i4x://edX/toy/peergrading/init"
- model_data = {'data': "", 'location': location}
+ model_data = {'data': "", 'location': location, 'category':'peergrading'}
self.mock_service = peer_grading_service.MockPeerGradingService()
self.system = ModuleSystem(
ajax_url=location,
diff --git a/lms/djangoapps/open_ended_grading/utils.py b/lms/djangoapps/open_ended_grading/utils.py
new file mode 100644
index 0000000000..7634977397
--- /dev/null
+++ b/lms/djangoapps/open_ended_grading/utils.py
@@ -0,0 +1,16 @@
+from xmodule.modulestore import search
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.exceptions import ItemNotFoundError
+
+def does_location_exist(course_id, location):
+ """
+ Checks to see if a valid module exists at a given location (ie has not been deleted)
+ course_id - string course id
+ location - string location
+ """
+ try:
+ search.path_to_location(modulestore(), course_id, location)
+ return True
+ except ItemNotFoundError:
+ #If the problem cannot be found at the location received from the grading controller server, it has been deleted by the course author.
+ return False
diff --git a/lms/djangoapps/open_ended_grading/views.py b/lms/djangoapps/open_ended_grading/views.py
index 7cf5aaf024..11d4765069 100644
--- a/lms/djangoapps/open_ended_grading/views.py
+++ b/lms/djangoapps/open_ended_grading/views.py
@@ -178,6 +178,7 @@ def student_problem_list(request, course_id):
error_text = ""
problem_list = []
base_course_url = reverse('courses')
+ list_to_remove = []
try:
#Get list of all open ended problems that the grading server knows about
@@ -191,7 +192,6 @@ def student_problem_list(request, course_id):
problem_list = problem_list_dict['problem_list']
#A list of problems to remove (problems that can't be found in the course)
- list_to_remove = []
for i in xrange(0, len(problem_list)):
try:
#Try to load each problem in the courseware to get links to them
diff --git a/lms/envs/common.py b/lms/envs/common.py
index 1e274a9c1f..680433620f 100644
--- a/lms/envs/common.py
+++ b/lms/envs/common.py
@@ -146,6 +146,10 @@ MITX_FEATURES = {
# for load testing
'AUTOMATIC_AUTH_FOR_LOAD_TESTING': False,
+
+ # Toggle to enable chat availability (configured on a per-course
+ # basis in Studio)
+ 'ENABLE_CHAT': False
}
# Used for A/B testing
@@ -313,6 +317,8 @@ CODE_JAIL = {
'limits': {
# How many CPU seconds can jailed code use?
'CPU': 1,
+ # How large a file can jailed code write?
+ 'FSIZE': 50000,
},
}
diff --git a/lms/static/candy_res/audioplayer.swf b/lms/static/candy_res/audioplayer.swf
new file mode 100644
index 0000000000..72390d4157
Binary files /dev/null and b/lms/static/candy_res/audioplayer.swf differ
diff --git a/lms/static/candy_res/candy_full.css b/lms/static/candy_res/candy_full.css
new file mode 100644
index 0000000000..c934881754
--- /dev/null
+++ b/lms/static/candy_res/candy_full.css
@@ -0,0 +1,606 @@
+/**
+ * Chat CSS
+ *
+ * @author Michael
+ * @author Patrick
+ * @copyright 2011 Amiado Group AG, All rights reserved.
+ */
+html, body {
+ margin: 0;
+ padding: 0;
+ font-family: Arial, Helvetica, sans-serif;
+}
+
+#candy {
+ margin: 0;
+ padding: 0;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ right: 0;
+ width: 100%;
+ background-color: #bdb7a1;
+ color: #333;
+ overflow: hidden;
+ border: 1px solid #bdb7a1;
+ border-top-right-radius: 10px;
+ box-sizing: border-box;
+}
+#candy.poppedOut {
+ border-top-left-radius: 0 !important;
+}
+
+#chatPopin {
+ position: absolute;
+ bottom: 5px;
+ right: 5px;
+ font-size: 24px;
+ height: 18px !important;
+ width: 22px;
+ color: #666;
+}
+#chatPopin:hover {
+ color: #333;
+ text-decoration: none;
+}
+
+a {
+ color: #333;
+ text-decoration: none;
+}
+ul {
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+
+#chat-tabs {
+ margin: 0 0 0 28px;
+ padding: 0;
+ overflow: auto;
+ border-left: 1px solid #bdb7a1;
+}
+
+#chat-pane.collapsed-message-pane #chat-tabs {
+ height: 100%;
+ width: 29px;
+ border-left: 0;
+ margin: 30px 0 0 0;
+}
+
+#chat-tabs #chat-expand-arrow {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 27px;
+ height: 15px;
+ padding: 5px 0;
+ cursor: pointer;
+}
+#chat-tabs #chat-expand-arrow em {
+ font-size: 18px;
+ padding: 0 10px;
+}
+
+#chat-tabs li {
+ margin: 0;
+ float: left;
+ position: relative;
+ white-space: nowrap;
+}
+
+#chat-tabs li a {
+ background-color: #e9e6df;
+ padding: 6px 20px 4px 1px;
+ display: inline-block;
+ color: #999;
+ height: 19px;
+ font-size: 22px;
+ -webkit-font-smoothing: antialiased;
+}
+
+#chat-tabs li a.label {
+ border-right: 1px solid #bdb7a1;
+ border-bottom: 1px solid #bdb7a1;
+}
+
+#chat-pane.collapsed-message-pane #chat-tabs li a.label {
+ border-bottom: 0;
+ margin-bottom: 1px;
+}
+
+#chat-tabs li.active a {
+ color: #333;
+ font-weight: bold;
+}
+
+#chat-tabs li.active a.label {
+ border-bottom: 1px solid white;
+ background-color: white;
+}
+
+#chat-tabs li a.transition {
+ display: none; /* JRBL */
+}
+
+#chat-tabs li a.close {
+ background-color: transparent;
+ position: absolute;
+ top: 2px;
+ right: 7px;
+ height: auto;
+ padding: 0;
+ margin: 0;
+ color: #999;
+}
+#chat-tabs li a.close:hover, #chat-tabs li.active a.close:hover {
+ color: #333;
+}
+
+#chat-tabs li .unread {
+ color: white;
+ background-color: #8C1515;
+ padding: 1px 2px;
+ font-weight: normal;
+ font-size: 10px;
+ position: absolute;
+ top: 12px;
+ right: 30px;
+ border-radius: 5px;
+}
+
+#chat-tabs li.offline a.label {
+ text-decoration: line-through;
+}
+
+#chat-toolbar {
+ /*
+ position: fixed;
+ bottom: 0;
+ right: 0;
+ font-size: 11px;
+ color: #666;
+ width: 200px;
+ height: 24px;
+ padding-top: 7px;
+ border-top: 1px solid #e9e6df;
+ background-color: #d3cec0;
+ */
+ display: none !important;
+}
+#chat-toolbar li {
+ width: 16px;
+ height: 16px;
+ margin-left: 5px;
+ float: left;
+ display: inline-block;
+ cursor: pointer;
+ background-position: top left;
+ background-repeat: no-repeat;
+}
+#chat-toolbar #emoticons-icon {
+ background-image: url(img/action/emoticons.png);
+}
+#chat-toolbar .context {
+ background-image: url(img/action/settings.png);
+ display: none;
+}
+.role-moderator #chat-toolbar .context, .affiliation-owner #chat-toolbar .context {
+ display: inline-block;
+}
+#chat-sound-control {
+ background-image: url(img/action/sound-off.png);
+}
+#chat-sound-control.checked {
+ background-image: url(img/action/sound-on.png);
+}
+#chat-autoscroll-control {
+ background-image: url(img/action/autoscroll-off.png);
+}
+#chat-autoscroll-control.checked {
+ background-image: url(img/action/autoscroll-on.png);
+}
+#chat-statusmessage-control {
+ background: url(img/action/statusmessage-off.png);
+}
+#chat-statusmessage-control.checked {
+ background: url(img/action/statusmessage-on.png);
+}
+#chat-toolbar .usercount {
+ background-image: url(img/action/usercount.png);
+ cursor: default;
+ padding-left: 20px;
+ width: auto;
+ margin-right: 5px;
+ float: right;
+}
+.usercount span {
+ display: inline-block;
+ padding: 1px 3px;
+ background-color: #ccc;
+ font-weight: bold;
+ border-radius: 3px;
+}
+
+.room-pane {
+ /* display: none; */
+}
+.roster-pane {
+ position: absolute;
+ overflow: auto;
+ top: 30px;
+ right: 0;
+ bottom: 30px;
+ width: 198px;
+ margin: 0;
+}
+.roster-pane .user {
+ cursor: pointer;
+ width: 90%;
+ padding: 6px 5%;
+ font-size: 14px;
+ margin: 0;
+ /* display: none; */
+ color: #666;
+ float: left;
+ clear: both;
+ height: 17px;
+ background-color: #d3cec0;
+ border-bottom: 1px solid #bdb7a1;
+}
+.roster-pane .user.me {
+ font-weight: bold;
+ cursor: default;
+}
+.roster-pane .user:hover,
+.roster-pane .user.me:hover {
+ background-color: #e9e6df;
+}
+.roster-pane .user.status-ignored {
+ cursor: default;
+ color: #999;
+ opacity: .5 !important;
+}
+.roster-pane .label {
+ float: left;
+ width: 125px;
+ overflow: hidden;
+ white-space: nowrap;
+}
+.roster-pane li {
+ width: 16px;
+ height: 16px;
+ float: right;
+ display: block;
+ margin-left: 3px;
+ background-repeat: no-repeat;
+ background-position: center;
+}
+.roster-pane li.role {
+ cursor: default;
+ display: none;
+}
+.roster-pane li.role-moderator {
+ background-image: url(img/roster/role-moderator.png);
+ display: block;
+}
+.roster-pane li.affiliation-owner {
+ background-image: url(img/roster/affiliation-owner.png);
+ display: block;
+}
+.roster-pane li.ignore {
+ background-image: url(img/roster/ignore.png);
+ display: none;
+}
+.roster-pane .status-ignored li.ignore {
+ display: block;
+}
+.roster-pane .me li.context {
+ display: none;
+}
+.roster-pane li.context {
+ background-image: url(img/action/menu.png);
+ cursor: pointer;
+}
+.roster-pane li.context:hover {
+ background-color: #ccc;
+ border-radius: 4px;
+}
+
+.message-pane-wrapper {
+ clear: both;
+ overflow: auto;
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ height: auto;
+ width: auto;
+ margin: 30px 199px 32px 0;
+ background-color: white;
+ font-size: 13px;
+}
+.message-pane {
+ margin: 0;
+ padding: 5px 10px 2px 10px;
+}
+.message-pane dt {
+ width: 55px;
+ float: left;
+ color: #888;
+ font-size: 10px;
+ text-align: right;
+ padding-top: 4px;
+}
+
+.message-pane dd {
+ overflow: auto;
+ padding: 2px 0 1px 100px;
+ margin: 0 0 2px 0;
+ white-space: -o-pre-wrap; /* Opera */
+ word-wrap: break-word; /* Internet Explorer 5.5+ */
+}
+
+.message-pane dd .label {
+ font-weight: bold;
+ white-space: nowrap;
+ display: block;
+ margin-left: -90px;
+ width: 90px;
+ float: left;
+ overflow: hidden;
+}
+
+.message-pane .subject {
+ color: #a00;
+ font-weight: bold;
+}
+
+.message-pane .adminmessage {
+ color: #a00;
+ font-weight: bold;
+}
+
+.message-pane .infomessage {
+ color: #888;
+ font-style: italic;
+ padding-left: 5px;
+}
+
+.message-pane .emoticon {
+ vertical-align: text-bottom;
+ height: 15px;
+ width: 15px;
+}
+
+.message-form-wrapper {
+ position: absolute;
+ bottom: 1px;
+ left: 0;
+ right: 0;
+ width: auto;
+ margin-right: 199px;
+ background-color: #e9e6df;
+ height: 30px;
+}
+
+.message-form {
+ position: absolute;
+ bottom: 1px;
+ left: 0;
+ right: 0;
+ margin: 0 199px 0 0;
+ padding: 0;
+ height: 30px;
+}
+
+.message-form input {
+ border: 0 none;
+ font-size: 14px;
+ width: 100%;
+ height: 100%;
+ display: block;
+ outline-width: 0;
+ padding: 0 50px 0 5px;
+ background-color: transparent;
+}
+.message-form input:focus {
+ background-color: white;
+}
+
+.message-form input.submit {
+ cursor: pointer;
+ background-color: #333;
+ color: #e9e6df;
+ position: absolute;
+ bottom: 0;
+ right: 0;
+ margin: 3px;
+ padding: 5px;
+ width: 40px;
+ font-size: 12px;
+ line-height: 12px;
+ height: 24px;
+ font-weight: bold;
+}
+
+#tooltip {
+ position: absolute;
+ z-index: 10;
+ display: none;
+ margin: 18px -18px 2px -2px;
+ color: white;
+ font-size: 11px;
+ padding: 5px 0;
+ background: url(img/tooltip-arrows.gif) no-repeat left bottom;
+}
+
+#tooltip div {
+ background-color: black;
+ padding: 2px 5px;
+ zoom: 1;
+}
+
+#context-menu {
+ position: absolute;
+ z-index: 10;
+ display: none;
+ padding: 15px 10px;
+ margin: 8px -28px -8px -12px;
+ background: url(img/context-arrows.gif) no-repeat left bottom;
+}
+
+#context-menu ul {
+ background-color: black;
+ color: white;
+ font-size: 12px;
+ padding: 2px;
+ zoom: 1;
+}
+
+#context-menu li {
+ padding: 3px 5px 3px 20px;
+ line-height: 12px;
+ cursor: pointer;
+ margin-bottom: 2px;
+ background: 1px no-repeat;
+ white-space: nowrap;
+}
+
+#context-menu li:hover {
+ background-color: #666;
+}
+
+#context-menu li:last-child {
+ margin-bottom: 0;
+}
+
+#context-menu .private {
+ background-image: url(img/action/private.png);
+}
+
+#context-menu .ignore {
+ background-image: url(img/action/ignore.png);
+}
+
+#context-menu .unignore {
+ background-image: url(img/action/unignore.png);
+}
+
+#context-menu .kick {
+ background-image: url(img/action/kick.png);
+}
+
+#context-menu .ban {
+ background-image: url(img/action/ban.png);
+}
+
+#context-menu .subject {
+ background-image: url(img/action/subject.png);
+}
+
+#context-menu .emoticons {
+ padding-left: 5px;
+ width: 85px;
+ white-space: normal;
+}
+
+#context-menu .emoticons:hover {
+ background-color: transparent;
+}
+
+#context-menu .emoticons img {
+ cursor: pointer;
+ margin: 3px;
+ height: 15px;
+ width: 15px;
+}
+
+#chat-modal {
+ background: url(img/modal-bg.png);
+ width: 300px;
+ padding: 20px 5px;
+ color: white;
+ font-size: 16px;
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ margin-left: -155px;
+ margin-top: -45px;
+ text-align: center;
+ display: none;
+ z-index: 100;
+ border-radius: 5px;
+}
+
+#chat-modal-overlay {
+ position: absolute;
+ left: 0;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ z-index: 90;
+ background-image: url(img/overlay.png);
+ border-top-left-radius: 8px;
+}
+
+#chat-modal.modal-login {
+ display: block;
+ margin-top: -100px;
+}
+
+#chat-modal-spinner {
+ display: none;
+ margin-left: 15px;
+}
+
+#chat-modal form {
+ margin: 15px 0;
+}
+
+#chat-modal label, #chat-modal input, #chat-modal select {
+ display: block;
+ float: left;
+ line-height: 26px;
+ font-size: 16px;
+ margin: 5px 0;
+}
+
+#chat-modal input, #chat-modal select {
+ padding: 2px;
+ line-height: 16px;
+ width: 150px;
+}
+
+#chat-modal label {
+ text-align: right;
+ padding-right: 1em;
+ clear: both;
+ width: 100px;
+}
+
+#chat-modal input.button {
+ float: none;
+ display: block;
+ margin: 5px auto;
+ clear: both;
+ position: relative;
+ top: 10px;
+ /* width: 200px; */
+ width: 120px; /* JRBL */
+}
+
+#chat-modal .close {
+ position: absolute;
+ right: 0;
+ display: none;
+ padding: 0 5px;
+ margin: -17px 3px 0 0;
+ color: white;
+ border-radius: 3px;
+}
+
+#chat-modal .close:hover {
+ background-color: #333;
+}
diff --git a/lms/static/candy_res/img/action/autoscroll-off.png b/lms/static/candy_res/img/action/autoscroll-off.png
new file mode 100644
index 0000000000..a0b8aa6940
Binary files /dev/null and b/lms/static/candy_res/img/action/autoscroll-off.png differ
diff --git a/lms/static/candy_res/img/action/autoscroll-on.png b/lms/static/candy_res/img/action/autoscroll-on.png
new file mode 100644
index 0000000000..3f55052b0f
Binary files /dev/null and b/lms/static/candy_res/img/action/autoscroll-on.png differ
diff --git a/lms/static/candy_res/img/action/ban.png b/lms/static/candy_res/img/action/ban.png
new file mode 100644
index 0000000000..b335cb11c4
Binary files /dev/null and b/lms/static/candy_res/img/action/ban.png differ
diff --git a/lms/static/candy_res/img/action/emoticons.png b/lms/static/candy_res/img/action/emoticons.png
new file mode 100755
index 0000000000..ade431851b
Binary files /dev/null and b/lms/static/candy_res/img/action/emoticons.png differ
diff --git a/lms/static/candy_res/img/action/ignore.png b/lms/static/candy_res/img/action/ignore.png
new file mode 100644
index 0000000000..08f249365a
Binary files /dev/null and b/lms/static/candy_res/img/action/ignore.png differ
diff --git a/lms/static/candy_res/img/action/kick.png b/lms/static/candy_res/img/action/kick.png
new file mode 100644
index 0000000000..bce1c97686
Binary files /dev/null and b/lms/static/candy_res/img/action/kick.png differ
diff --git a/lms/static/candy_res/img/action/menu.png b/lms/static/candy_res/img/action/menu.png
new file mode 100644
index 0000000000..be4540c436
Binary files /dev/null and b/lms/static/candy_res/img/action/menu.png differ
diff --git a/lms/static/candy_res/img/action/private.png b/lms/static/candy_res/img/action/private.png
new file mode 100644
index 0000000000..39433cf78a
Binary files /dev/null and b/lms/static/candy_res/img/action/private.png differ
diff --git a/lms/static/candy_res/img/action/settings.png b/lms/static/candy_res/img/action/settings.png
new file mode 100755
index 0000000000..327fdf4963
Binary files /dev/null and b/lms/static/candy_res/img/action/settings.png differ
diff --git a/lms/static/candy_res/img/action/sound-off.png b/lms/static/candy_res/img/action/sound-off.png
new file mode 100644
index 0000000000..7ba81fefa5
Binary files /dev/null and b/lms/static/candy_res/img/action/sound-off.png differ
diff --git a/lms/static/candy_res/img/action/sound-on.png b/lms/static/candy_res/img/action/sound-on.png
new file mode 100644
index 0000000000..b4351604a7
Binary files /dev/null and b/lms/static/candy_res/img/action/sound-on.png differ
diff --git a/lms/static/candy_res/img/action/statusmessage-off.png b/lms/static/candy_res/img/action/statusmessage-off.png
new file mode 100644
index 0000000000..03eb01d771
Binary files /dev/null and b/lms/static/candy_res/img/action/statusmessage-off.png differ
diff --git a/lms/static/candy_res/img/action/statusmessage-on.png b/lms/static/candy_res/img/action/statusmessage-on.png
new file mode 100644
index 0000000000..063e8dc3fe
Binary files /dev/null and b/lms/static/candy_res/img/action/statusmessage-on.png differ
diff --git a/lms/static/candy_res/img/action/subject.png b/lms/static/candy_res/img/action/subject.png
new file mode 100644
index 0000000000..7bc9233ea6
Binary files /dev/null and b/lms/static/candy_res/img/action/subject.png differ
diff --git a/lms/static/candy_res/img/action/unignore.png b/lms/static/candy_res/img/action/unignore.png
new file mode 100644
index 0000000000..89c8129a49
Binary files /dev/null and b/lms/static/candy_res/img/action/unignore.png differ
diff --git a/lms/static/candy_res/img/action/usercount.png b/lms/static/candy_res/img/action/usercount.png
new file mode 100755
index 0000000000..7fb4e1f1e1
Binary files /dev/null and b/lms/static/candy_res/img/action/usercount.png differ
diff --git a/lms/static/candy_res/img/context-arrows.gif b/lms/static/candy_res/img/context-arrows.gif
new file mode 100644
index 0000000000..d02df8c43f
Binary files /dev/null and b/lms/static/candy_res/img/context-arrows.gif differ
diff --git a/lms/static/candy_res/img/emoticons/Angel.png b/lms/static/candy_res/img/emoticons/Angel.png
new file mode 100755
index 0000000000..0cf707b7de
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Angel.png differ
diff --git a/lms/static/candy_res/img/emoticons/Angry.png b/lms/static/candy_res/img/emoticons/Angry.png
new file mode 100755
index 0000000000..9ae5d1822f
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Angry.png differ
diff --git a/lms/static/candy_res/img/emoticons/Aww.png b/lms/static/candy_res/img/emoticons/Aww.png
new file mode 100755
index 0000000000..3512863987
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Aww.png differ
diff --git a/lms/static/candy_res/img/emoticons/Aww_2.png b/lms/static/candy_res/img/emoticons/Aww_2.png
new file mode 100755
index 0000000000..60510bb23d
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Aww_2.png differ
diff --git a/lms/static/candy_res/img/emoticons/Blushing.png b/lms/static/candy_res/img/emoticons/Blushing.png
new file mode 100755
index 0000000000..ab03ee8c5d
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Blushing.png differ
diff --git a/lms/static/candy_res/img/emoticons/Childish.png b/lms/static/candy_res/img/emoticons/Childish.png
new file mode 100755
index 0000000000..1a31c5068e
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Childish.png differ
diff --git a/lms/static/candy_res/img/emoticons/Confused.png b/lms/static/candy_res/img/emoticons/Confused.png
new file mode 100755
index 0000000000..08ba7d3f10
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Confused.png differ
diff --git a/lms/static/candy_res/img/emoticons/Creepy.png b/lms/static/candy_res/img/emoticons/Creepy.png
new file mode 100755
index 0000000000..561505895f
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Creepy.png differ
diff --git a/lms/static/candy_res/img/emoticons/Crying.png b/lms/static/candy_res/img/emoticons/Crying.png
new file mode 100755
index 0000000000..2532976871
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Crying.png differ
diff --git a/lms/static/candy_res/img/emoticons/Cthulhu.png b/lms/static/candy_res/img/emoticons/Cthulhu.png
new file mode 100755
index 0000000000..fafc4b3eb8
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Cthulhu.png differ
diff --git a/lms/static/candy_res/img/emoticons/Cute.png b/lms/static/candy_res/img/emoticons/Cute.png
new file mode 100755
index 0000000000..a883ac321b
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Cute.png differ
diff --git a/lms/static/candy_res/img/emoticons/Cute_Winking.png b/lms/static/candy_res/img/emoticons/Cute_Winking.png
new file mode 100755
index 0000000000..ad3383df51
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Cute_Winking.png differ
diff --git a/lms/static/candy_res/img/emoticons/Devil.png b/lms/static/candy_res/img/emoticons/Devil.png
new file mode 100755
index 0000000000..afc5c2cde5
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Devil.png differ
diff --git a/lms/static/candy_res/img/emoticons/Gah.png b/lms/static/candy_res/img/emoticons/Gah.png
new file mode 100755
index 0000000000..b03ee1b163
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Gah.png differ
diff --git a/lms/static/candy_res/img/emoticons/Gah_2.png b/lms/static/candy_res/img/emoticons/Gah_2.png
new file mode 100755
index 0000000000..b682458ece
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Gah_2.png differ
diff --git a/lms/static/candy_res/img/emoticons/Gasping.png b/lms/static/candy_res/img/emoticons/Gasping.png
new file mode 100755
index 0000000000..b6655ced50
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Gasping.png differ
diff --git a/lms/static/candy_res/img/emoticons/Greedy.png b/lms/static/candy_res/img/emoticons/Greedy.png
new file mode 100755
index 0000000000..a179638dde
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Greedy.png differ
diff --git a/lms/static/candy_res/img/emoticons/Grinning.png b/lms/static/candy_res/img/emoticons/Grinning.png
new file mode 100755
index 0000000000..85ff9154cb
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Grinning.png differ
diff --git a/lms/static/candy_res/img/emoticons/Grinning_Winking.png b/lms/static/candy_res/img/emoticons/Grinning_Winking.png
new file mode 100755
index 0000000000..5b1d5b71b9
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Grinning_Winking.png differ
diff --git a/lms/static/candy_res/img/emoticons/Happy.png b/lms/static/candy_res/img/emoticons/Happy.png
new file mode 100755
index 0000000000..51cf1a2331
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Happy.png differ
diff --git a/lms/static/candy_res/img/emoticons/Happy_2.png b/lms/static/candy_res/img/emoticons/Happy_2.png
new file mode 100755
index 0000000000..13326863b5
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Happy_2.png differ
diff --git a/lms/static/candy_res/img/emoticons/Happy_3.png b/lms/static/candy_res/img/emoticons/Happy_3.png
new file mode 100755
index 0000000000..be79df0823
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Happy_3.png differ
diff --git a/lms/static/candy_res/img/emoticons/Heart.png b/lms/static/candy_res/img/emoticons/Heart.png
new file mode 100755
index 0000000000..dcd28b9655
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Heart.png differ
diff --git a/lms/static/candy_res/img/emoticons/Huh.png b/lms/static/candy_res/img/emoticons/Huh.png
new file mode 100755
index 0000000000..241f50f4f7
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Huh.png differ
diff --git a/lms/static/candy_res/img/emoticons/Huh_2.png b/lms/static/candy_res/img/emoticons/Huh_2.png
new file mode 100755
index 0000000000..a1a54e4b1a
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Huh_2.png differ
diff --git a/lms/static/candy_res/img/emoticons/Laughing.png b/lms/static/candy_res/img/emoticons/Laughing.png
new file mode 100755
index 0000000000..edefc957a6
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Laughing.png differ
diff --git a/lms/static/candy_res/img/emoticons/Lips_Sealed.png b/lms/static/candy_res/img/emoticons/Lips_Sealed.png
new file mode 100755
index 0000000000..46e470179b
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Lips_Sealed.png differ
diff --git a/lms/static/candy_res/img/emoticons/Madness.png b/lms/static/candy_res/img/emoticons/Madness.png
new file mode 100755
index 0000000000..1c0946c3e8
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Madness.png differ
diff --git a/lms/static/candy_res/img/emoticons/Malicious.png b/lms/static/candy_res/img/emoticons/Malicious.png
new file mode 100755
index 0000000000..23f25792f1
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Malicious.png differ
diff --git a/lms/static/candy_res/img/emoticons/README b/lms/static/candy_res/img/emoticons/README
new file mode 100644
index 0000000000..208db2c2f0
--- /dev/null
+++ b/lms/static/candy_res/img/emoticons/README
@@ -0,0 +1,2 @@
+Simple Smileys is a set of 49 clean, free as in freedom, Public Domain smileys.
+For more packages or older versions, visit http://simplesmileys.org
diff --git a/lms/static/candy_res/img/emoticons/Sick.png b/lms/static/candy_res/img/emoticons/Sick.png
new file mode 100755
index 0000000000..6f73e2f096
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Sick.png differ
diff --git a/lms/static/candy_res/img/emoticons/Smiling.png b/lms/static/candy_res/img/emoticons/Smiling.png
new file mode 100755
index 0000000000..725eef526d
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Smiling.png differ
diff --git a/lms/static/candy_res/img/emoticons/Speechless.png b/lms/static/candy_res/img/emoticons/Speechless.png
new file mode 100755
index 0000000000..4fc424602e
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Speechless.png differ
diff --git a/lms/static/candy_res/img/emoticons/Spiteful.png b/lms/static/candy_res/img/emoticons/Spiteful.png
new file mode 100755
index 0000000000..195ced852f
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Spiteful.png differ
diff --git a/lms/static/candy_res/img/emoticons/Stupid.png b/lms/static/candy_res/img/emoticons/Stupid.png
new file mode 100755
index 0000000000..3fcea491a5
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Stupid.png differ
diff --git a/lms/static/candy_res/img/emoticons/Sunglasses.png b/lms/static/candy_res/img/emoticons/Sunglasses.png
new file mode 100755
index 0000000000..cad8379742
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Sunglasses.png differ
diff --git a/lms/static/candy_res/img/emoticons/Terrified.png b/lms/static/candy_res/img/emoticons/Terrified.png
new file mode 100755
index 0000000000..fad2e06524
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Terrified.png differ
diff --git a/lms/static/candy_res/img/emoticons/Thumb_Down.png b/lms/static/candy_res/img/emoticons/Thumb_Down.png
new file mode 100755
index 0000000000..4f70696dd8
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Thumb_Down.png differ
diff --git a/lms/static/candy_res/img/emoticons/Thumb_Up.png b/lms/static/candy_res/img/emoticons/Thumb_Up.png
new file mode 100755
index 0000000000..2ca0e0d087
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Thumb_Up.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tired.png b/lms/static/candy_res/img/emoticons/Tired.png
new file mode 100755
index 0000000000..13f7d1207a
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tired.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tongue_Out.png b/lms/static/candy_res/img/emoticons/Tongue_Out.png
new file mode 100755
index 0000000000..3d154f9081
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tongue_Out.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tongue_Out_Laughing.png b/lms/static/candy_res/img/emoticons/Tongue_Out_Laughing.png
new file mode 100755
index 0000000000..fba5d75148
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tongue_Out_Laughing.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tongue_Out_Left.png b/lms/static/candy_res/img/emoticons/Tongue_Out_Left.png
new file mode 100755
index 0000000000..8015de7f12
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tongue_Out_Left.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tongue_Out_Up.png b/lms/static/candy_res/img/emoticons/Tongue_Out_Up.png
new file mode 100755
index 0000000000..46328fbbee
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tongue_Out_Up.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tongue_Out_Up_Left.png b/lms/static/candy_res/img/emoticons/Tongue_Out_Up_Left.png
new file mode 100755
index 0000000000..b67b69fb7a
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tongue_Out_Up_Left.png differ
diff --git a/lms/static/candy_res/img/emoticons/Tongue_Out_Winking.png b/lms/static/candy_res/img/emoticons/Tongue_Out_Winking.png
new file mode 100755
index 0000000000..2a22cf6a9f
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Tongue_Out_Winking.png differ
diff --git a/lms/static/candy_res/img/emoticons/Uncertain.png b/lms/static/candy_res/img/emoticons/Uncertain.png
new file mode 100755
index 0000000000..717685684f
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Uncertain.png differ
diff --git a/lms/static/candy_res/img/emoticons/Uncertain_2.png b/lms/static/candy_res/img/emoticons/Uncertain_2.png
new file mode 100755
index 0000000000..a7f5370d2c
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Uncertain_2.png differ
diff --git a/lms/static/candy_res/img/emoticons/Unhappy.png b/lms/static/candy_res/img/emoticons/Unhappy.png
new file mode 100755
index 0000000000..79fc0c00ff
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Unhappy.png differ
diff --git a/lms/static/candy_res/img/emoticons/Winking.png b/lms/static/candy_res/img/emoticons/Winking.png
new file mode 100755
index 0000000000..1e01f943e6
Binary files /dev/null and b/lms/static/candy_res/img/emoticons/Winking.png differ
diff --git a/lms/static/candy_res/img/favicon.png b/lms/static/candy_res/img/favicon.png
new file mode 100644
index 0000000000..d384cc4b22
Binary files /dev/null and b/lms/static/candy_res/img/favicon.png differ
diff --git a/lms/static/candy_res/img/modal-bg.png b/lms/static/candy_res/img/modal-bg.png
new file mode 100644
index 0000000000..9fef73a742
Binary files /dev/null and b/lms/static/candy_res/img/modal-bg.png differ
diff --git a/lms/static/candy_res/img/modal-spinner.gif b/lms/static/candy_res/img/modal-spinner.gif
new file mode 100644
index 0000000000..f8593d57bf
Binary files /dev/null and b/lms/static/candy_res/img/modal-spinner.gif differ
diff --git a/lms/static/candy_res/img/overlay.png b/lms/static/candy_res/img/overlay.png
new file mode 100644
index 0000000000..0593fcf0b6
Binary files /dev/null and b/lms/static/candy_res/img/overlay.png differ
diff --git a/lms/static/candy_res/img/roster/affiliation-owner.png b/lms/static/candy_res/img/roster/affiliation-owner.png
new file mode 100644
index 0000000000..b88c857895
Binary files /dev/null and b/lms/static/candy_res/img/roster/affiliation-owner.png differ
diff --git a/lms/static/candy_res/img/roster/ignore.png b/lms/static/candy_res/img/roster/ignore.png
new file mode 100644
index 0000000000..08f249365a
Binary files /dev/null and b/lms/static/candy_res/img/roster/ignore.png differ
diff --git a/lms/static/candy_res/img/roster/role-moderator.png b/lms/static/candy_res/img/roster/role-moderator.png
new file mode 100644
index 0000000000..0d064d1140
Binary files /dev/null and b/lms/static/candy_res/img/roster/role-moderator.png differ
diff --git a/lms/static/candy_res/img/tab-transitions.png b/lms/static/candy_res/img/tab-transitions.png
new file mode 100644
index 0000000000..1a361e4d47
Binary files /dev/null and b/lms/static/candy_res/img/tab-transitions.png differ
diff --git a/lms/static/candy_res/img/tooltip-arrows.gif b/lms/static/candy_res/img/tooltip-arrows.gif
new file mode 100644
index 0000000000..ef4b05c6ff
Binary files /dev/null and b/lms/static/candy_res/img/tooltip-arrows.gif differ
diff --git a/lms/static/candy_res/notify.mp3 b/lms/static/candy_res/notify.mp3
new file mode 100644
index 0000000000..c00d997622
Binary files /dev/null and b/lms/static/candy_res/notify.mp3 differ
diff --git a/lms/static/js/vendor/candy.min.js b/lms/static/js/vendor/candy.min.js
new file mode 100644
index 0000000000..91923ccf68
--- /dev/null
+++ b/lms/static/js/vendor/candy.min.js
@@ -0,0 +1 @@
+var Candy=(function(a,b){a.about={name:"Candy",version:"1.0.9"};a.init=function(c,d){a.View.init(b("#candy"),d.view);a.Core.init(c,d.core)};return a}(Candy||{},jQuery));Candy.Core=(function(l,e,f){var d=null,j=null,a=null,g={},c=false,k={autojoin:true,debug:false},b=function(m,n){e.addNamespace(m,n)},h=function(){b("PRIVATE","jabber:iq:private");b("BOOKMARKS","storage:bookmarks");b("PRIVACY","jabber:iq:privacy");b("DELAY","jabber:x:delay")},i=function(){l.addHandler(l.Event.Jabber.Version,e.NS.VERSION,"iq");l.addHandler(l.Event.Jabber.Presence,null,"presence");l.addHandler(l.Event.Jabber.Message,null,"message");l.addHandler(l.Event.Jabber.Bookmarks,e.NS.PRIVATE,"iq");l.addHandler(l.Event.Jabber.Room.Disco,e.NS.DISCO_INFO,"iq");l.addHandler(l.Event.Jabber.PrivacyList,e.NS.PRIVACY,"iq","result");l.addHandler(l.Event.Jabber.PrivacyListError,e.NS.PRIVACY,"iq","error")};l.init=function(m,n){j=m;f.extend(true,k,n);if(k.debug){l.log=function(p){try{if(typeof window.console!==undefined&&typeof window.console.log!==undefined){console.log(p)}}catch(o){}};l.log("[Init] Debugging enabled")}h();d=new e.Connection(j);d.rawInput=l.rawInput.bind(l);d.rawOutput=l.rawOutput.bind(l);window.onbeforeunload=l.onWindowUnload;if(f.browser.mozilla){f(document).keydown(function(o){if(o.which===27){o.preventDefault()}})}};l.connect=function(o,n,m){d.reset();i();c=!c?o&&o.indexOf("@")<0:true;if(o&&n){d.connect(_getEscapedJidFromJid(o)+"/"+Candy.about.name,n,Candy.Core.Event.Strophe.Connect);a=new l.ChatUser(o,e.getNodeFromJid(o))}else{if(o&&m){d.connect(_getEscapedJidFromJid(o)+"/"+Candy.about.name,null,Candy.Core.Event.Strophe.Connect);a=new l.ChatUser(null,m)}else{if(o){Candy.Core.Event.Login(o)}else{Candy.Core.Event.Login()}}}};_getEscapedJidFromJid=function(m){var n=e.getNodeFromJid(m),o=e.getDomainFromJid(m);return n?e.escapeNode(n)+"@"+o:o};l.attach=function(n,m,o){a=new l.ChatUser(n,e.getNodeFromJid(n));i();d.attach(n,m,o,Candy.Core.Event.Strophe.Connect)};l.disconnect=function(){if(d.connected){f.each(l.getRooms(),function(){Candy.Core.Action.Jabber.Room.Leave(this.getJid())});d.disconnect()}};l.addHandler=function(q,p,n,o,s,r,m){return d.addHandler(q,p,n,o,s,r,m)};l.getUser=function(){return a};l.setUser=function(m){a=m};l.getConnection=function(){return d};l.getRooms=function(){return g};l.isAnonymousConnection=function(){return c};l.getOptions=function(){return k};l.getRoom=function(m){if(g[m]){return g[m]}return null};l.onWindowUnload=function(){d.sync=true;l.disconnect();d.flush()};l.rawInput=function(m){this.log("RECV: "+m)};l.rawOutput=function(m){this.log("SENT: "+m)};l.log=function(){};return l}(Candy.Core||{},Strophe,jQuery));Candy.View=(function(i,b){var d={container:null,roomJid:null},h={language:"en",resources:"res/",messages:{limit:2000,remove:500},crop:{message:{nickname:15,body:1000},roster:{nickname:15}}},a=function(j){b.i18n.setDictionary(i.Translation[j])},g=function(){Candy.Core.Event.addObserver(Candy.Core.Event.KEYS.CHAT,i.Observer.Chat);Candy.Core.Event.addObserver(Candy.Core.Event.KEYS.PRESENCE,i.Observer.Presence);Candy.Core.Event.addObserver(Candy.Core.Event.KEYS.PRESENCE_ERROR,i.Observer.PresenceError);Candy.Core.Event.addObserver(Candy.Core.Event.KEYS.MESSAGE,i.Observer.Message);Candy.Core.Event.addObserver(Candy.Core.Event.KEYS.LOGIN,i.Observer.Login)},e=function(){if(b.browser.msie&&!b.browser.version.match("^9")){b(document).focusin(Candy.View.Pane.Window.onFocus).focusout(Candy.View.Pane.Window.onBlur)}else{b(window).focus(Candy.View.Pane.Window.onFocus).blur(Candy.View.Pane.Window.onBlur)}b(window).resize(Candy.View.Pane.Chat.fitTabs)},f=function(){b("#emoticons-icon").click(function(j){i.Pane.Chat.Context.showEmoticonsMenu(j.currentTarget);j.stopPropagation()});b("#chat-autoscroll-control").click(Candy.View.Pane.Chat.Toolbar.onAutoscrollControlClick);b("#chat-sound-control").click(Candy.View.Pane.Chat.Toolbar.onSoundControlClick);if(Candy.Util.cookieExists("candy-nosound")){b("#chat-sound-control").click()}b("#chat-statusmessage-control").click(Candy.View.Pane.Chat.Toolbar.onStatusMessageControlClick);if(Candy.Util.cookieExists("candy-nostatusmessages")){b("#chat-statusmessage-control").click()}},c=function(){b("body").delegate("li[data-tooltip]","mouseenter",Candy.View.Pane.Chat.Tooltip.show)};i.init=function(j,k){b.extend(true,h,k);a(h.language);Candy.Util.Parser.setEmoticonPath(this.getOptions().resources+"img/emoticons/");d.container=j;d.container.html(Mustache.to_html(Candy.View.Template.Chat.pane,{tooltipEmoticons:b.i18n._("tooltipEmoticons"),tooltipSound:b.i18n._("tooltipSound"),tooltipAutoscroll:b.i18n._("tooltipAutoscroll"),tooltipStatusmessage:b.i18n._("tooltipStatusmessage"),tooltipAdministration:b.i18n._("tooltipAdministration"),tooltipUsercount:b.i18n._("tooltipUsercount"),resourcesPath:this.getOptions().resources},{tabs:Candy.View.Template.Chat.tabs,rooms:Candy.View.Template.Chat.rooms,modal:Candy.View.Template.Chat.modal,toolbar:Candy.View.Template.Chat.toolbar,soundcontrol:Candy.View.Template.Chat.soundcontrol}));e();f();g();c()};i.getCurrent=function(){return d};i.getOptions=function(){return h};return i}(Candy.View||{},jQuery));Candy.Util=(function(a,b){a.jidToId=function(c){return MD5.hexdigest(c)};a.escapeJid=function(c){var d=Strophe.escapeNode(Strophe.getNodeFromJid(c)),f=Strophe.getDomainFromJid(c),e=Strophe.getResourceFromJid(c);c=d+"@"+f;if(e){c+="/"+Strophe.escapeNode(e)}return c};a.unescapeJid=function(c){var d=Strophe.unescapeNode(Strophe.getNodeFromJid(c)),f=Strophe.getDomainFromJid(c),e=Strophe.getResourceFromJid(c);c=d+"@"+f;if(e){c+="/"+Strophe.unescapeNode(e)}return c};a.crop=function(d,c){if(d.length>c){d=d.substr(0,c-3)+"..."}return d};a.setCookie=function(c,e,d){var f=new Date();f.setDate(new Date().getDate()+d);document.cookie=c+"="+e+";expires="+f.toUTCString()+";path=/"};a.cookieExists=function(c){return document.cookie.indexOf(c)>-1};a.getCookie=function(c){if(document.cookie){var d=new RegExp(escape(c)+"=([^;]*)","gm"),e=d.exec(document.cookie);if(e){return e[1]}}};a.deleteCookie=function(c){document.cookie=c+"=;expires=Thu, 01-Jan-70 00:00:01 GMT;path=/"};a.getPosLeftAccordingToWindowBounds=function(e,h){var d=b(document).width(),c=e.outerWidth(),f=c-e.outerWidth(true),g="left";if(h+c>=d){h-=c-f;g="right"}return{px:h,backgroundPositionAlignment:g}};a.getPosTopAccordingToWindowBounds=function(d,h){var g=b(document).height(),c=d.outerHeight(),e=c-d.outerHeight(true),f="top";if(h+c>=g){h-=c-e;f="bottom"}return{px:h,backgroundPositionAlignment:f}};a.localizedTime=function(d){if(d===undefined){return undefined}var c=a.iso8601toDate(d);if(c.toDateString()===new Date().toDateString()){return c.format(b.i18n._("timeFormat"))}else{return c.format(b.i18n._("dateFormat"))}};a.iso8601toDate=function(c){var e=Date.parse(c),d=0;if(isNaN(e)){var f=/^(\d{4}|[+\-]\d{6})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3,}))?)?(?:(Z)|([+\-])(\d{2})(?::?(\d{2}))?))?/.exec(c);if(f){if(f[8]!=="Z"){d=+f[10]*60+(+f[11]);if(f[9]==="+"){d=-d}}return new Date(+f[1],+f[2]-1,+f[3],+f[4],+f[5]+d,+f[6],f[7]?+f[7].substr(0,3):0)}else{e=Date.parse(c.replace(/^(\d{4})(\d{2})(\d{2})/,"$1-$2-$3")+"Z")}}return new Date(e)};a.isEmptyObject=function(c){var d;for(d in c){if(c.hasOwnProperty(d)){return false}}return true};a.forceRedraw=function(c){c.css({display:"none"});setTimeout(function(){this.css({display:"block"})}.bind(c),1)};a.Parser={_emoticonPath:"",setEmoticonPath:function(c){this._emoticonPath=c},emoticons:[{plain:":)",regex:/((\s):-?\)|:-?\)(\s|$))/gm,image:"Smiling.png"},{plain:";)",regex:/((\s);-?\)|;-?\)(\s|$))/gm,image:"Winking.png"},{plain:":D",regex:/((\s):-?D|:-?D(\s|$))/gm,image:"Grinning.png"},{plain:";D",regex:/((\s);-?D|;-?D(\s|$))/gm,image:"Grinning_Winking.png"},{plain:":(",regex:/((\s):-?\(|:-?\((\s|$))/gm,image:"Unhappy.png"},{plain:"^^",regex:/((\s)\^\^|\^\^(\s|$))/gm,image:"Happy_3.png"},{plain:":P",regex:/((\s):-?P|:-?P(\s|$))/igm,image:"Tongue_Out.png"},{plain:";P",regex:/((\s);-?P|;-?P(\s|$))/igm,image:"Tongue_Out_Winking.png"},{plain:":S",regex:/((\s):-?S|:-?S(\s|$))/igm,image:"Confused.png"},{plain:":/",regex:/((\s):-?\/|:-?\/(\s|$))/gm,image:"Uncertain.png"},{plain:"8)",regex:/((\s)8-?\)|8-?\)(\s|$))/gm,image:"Sunglasses.png"},{plain:"$)",regex:/((\s)\$-?\)|\$-?\)(\s|$))/gm,image:"Greedy.png"},{plain:"oO",regex:/((\s)oO|oO(\s|$))/gm,image:"Huh.png"},{plain:":x",regex:/((\s):x|:x(\s|$))/gm,image:"Lips_Sealed.png"},{plain:":666:",regex:/((\s):666:|:666:(\s|$))/gm,image:"Devil.png"},{plain:"<3",regex:/((\s)<3|<3(\s|$))/gm,image:"Heart.png"}],emotify:function(d){var c;for(c=this.emoticons.length-1;c>=0;c--){d=d.replace(this.emoticons[c].regex,'$2$3')}return d},linkify:function(c){c=c.replace(/(^|[^\/])(www\.[^\.]+\.[\S]+(\b|$))/gi,"$1http://$2");return c.replace(/(\b(https?|ftp|file):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/ig,'$1')},escape:function(c){return b("").text(c).html()},all:function(c){if(c){c=this.escape(c);c=this.linkify(c);c=this.emotify(c)}return c}};return a}(Candy.Util||{},jQuery));Candy.Util.Observable=(function(a){var b={};a.addObserver=function(c,d){if(b[c]===undefined){b[c]=[]}b[c].push(d)};a.deleteObserver=function(c,d){delete b[c][d]};a.clearObservers=function(c){if(c!==undefined){b[c]=[]}else{b={}}};a.notifyObservers=function(f,c){var d=b[f],e;for(e=d.length-1;e>=0;e--){d[e].update(a,c)}};return a}(Candy.Util.Observable||{}));Candy.Core.Action=(function(a,c,b){a.Jabber={Version:function(d){Candy.Core.getConnection().send($iq({type:"result",to:d.attr("from"),from:d.attr("to"),id:d.attr("id")}).c("query",{name:Candy.about.name,version:Candy.about.version,os:navigator.userAgent}))},Roster:function(){Candy.Core.getConnection().send($iq({type:"get",xmlns:c.NS.CLIENT}).c("query",{xmlns:c.NS.ROSTER}).tree())},Presence:function(d){Candy.Core.getConnection().send($pres(d).tree())},Services:function(){Candy.Core.getConnection().send($iq({type:"get",xmlns:c.NS.CLIENT}).c("query",{xmlns:c.NS.DISCO_ITEMS}).tree())},Autojoin:function(){if(Candy.Core.getOptions().autojoin===true){Candy.Core.getConnection().send($iq({type:"get",xmlns:c.NS.CLIENT}).c("query",{xmlns:c.NS.PRIVATE}).c("storage",{xmlns:c.NS.BOOKMARKS}).tree())}else{if(b.isArray(Candy.Core.getOptions().autojoin)){b.each(Candy.Core.getOptions().autojoin,function(){a.Jabber.Room.Join(this.valueOf())})}}},ResetIgnoreList:function(){Candy.Core.getConnection().send($iq({type:"set",from:Candy.Core.getUser().getJid(),id:"set1"}).c("query",{xmlns:c.NS.PRIVACY}).c("list",{name:"ignore"}).c("item",{action:"allow",order:"0"}).tree())},RemoveIgnoreList:function(){Candy.Core.getConnection().send($iq({type:"set",from:Candy.Core.getUser().getJid(),id:"remove1"}).c("query",{xmlns:c.NS.PRIVACY}).c("list",{name:"ignore"}).tree())},GetIgnoreList:function(){Candy.Core.getConnection().send($iq({type:"get",from:Candy.Core.getUser().getJid(),id:"get1"}).c("query",{xmlns:c.NS.PRIVACY}).c("list",{name:"ignore"}).tree())},SetIgnoreListActive:function(){Candy.Core.getConnection().send($iq({type:"set",from:Candy.Core.getUser().getJid(),id:"set2"}).c("query",{xmlns:c.NS.PRIVACY}).c("active",{name:"ignore"}).tree())},GetJidIfAnonymous:function(){if(!Candy.Core.getUser().getJid()){Candy.Core.log("[Jabber] Anonymous login");Candy.Core.getUser().data.jid=Candy.Core.getConnection().jid}},Room:{Join:function(d,e){a.Jabber.Room.Disco(d);Candy.Core.getConnection().muc.join(d,Candy.Core.getUser().getNick(),null,null,e)},Leave:function(d){Candy.Core.getConnection().muc.leave(d,Candy.Core.getRoom(d).getUser().getNick(),function(){})},Disco:function(d){Candy.Core.getConnection().send($iq({type:"get",from:Candy.Core.getUser().getJid(),to:d,id:"disco3"}).c("query",{xmlns:c.NS.DISCO_INFO}).tree())},Message:function(d,f,e){f=b.trim(f);if(f===""){return false}Candy.Core.getConnection().muc.message(Candy.Util.escapeJid(d),undefined,f,e);return true},IgnoreUnignore:function(d){Candy.Core.getUser().addToOrRemoveFromPrivacyList("ignore",d);Candy.Core.Action.Jabber.Room.UpdatePrivacyList()},UpdatePrivacyList:function(){var d=Candy.Core.getUser(),f=$iq({type:"set",from:d.getJid(),id:"edit1"}).c("query",{xmlns:"jabber:iq:privacy"}).c("list",{name:"ignore"}),e=d.getPrivacyList("ignore");if(e.length>0){b.each(e,function(g,h){f.c("item",{type:"jid",value:Candy.Util.escapeJid(h),action:"deny",order:g}).c("message").up().up()})}else{f.c("item",{action:"allow",order:"0"})}Candy.Core.getConnection().send(f.tree())},Admin:{UserAction:function(d,i,g,h){var f,e={nick:c.escapeNode(c.getResourceFromJid(i))};switch(g){case"kick":f="kick1";e.role="none";break;case"ban":f="ban1";e.affiliation="outcast";break;default:return false}Candy.Core.getConnection().send($iq({type:"set",from:Candy.Core.getUser().getJid(),to:d,id:f}).c("query",{xmlns:c.NS.MUC_ADMIN}).c("item",e).c("reason").t(h).tree());return true},SetSubject:function(d,e){Candy.Core.getConnection().muc.setTopic(d,e)}}}};return a}(Candy.Core.Action||{},Strophe,jQuery));Candy.Core.ChatRoom=function(a){this.room={jid:a,name:null};this.user=null;this.roster=new Candy.Core.ChatRoster();this.setUser=function(b){this.user=b};this.getUser=function(){return this.user};this.getJid=function(){return this.room.jid};this.setName=function(b){this.room.name=b};this.getName=function(){return this.room.name};this.setRoster=function(b){this.roster=b};this.getRoster=function(){return this.roster}};Candy.Core.ChatRoster=function(){this.items={};this.add=function(a){this.items[a.getJid()]=a};this.remove=function(a){delete this.items[a]};this.get=function(a){return this.items[a]};this.getAll=function(){return this.items}};Candy.Core.ChatUser=function(b,a,c,d){this.ROLE_MODERATOR="moderator";this.AFFILIATION_OWNER="owner";this.data={jid:b,nick:Strophe.unescapeNode(a),affiliation:c,role:d,privacyLists:{},customData:{}};this.getJid=function(){if(this.data.jid){return Candy.Util.unescapeJid(this.data.jid)}return};this.getEscapedJid=function(){return Candy.Util.escapeJid(this.data.jid)};this.getNick=function(){return Strophe.unescapeNode(this.data.nick)};this.getRole=function(){return this.data.role};this.getAffiliation=function(){return this.data.affiliation};this.isModerator=function(){return this.getRole()===this.ROLE_MODERATOR||this.getAffiliation()===this.AFFILIATION_OWNER};this.addToOrRemoveFromPrivacyList=function(g,f){if(!this.data.privacyLists[g]){this.data.privacyLists[g]=[]}var e=-1;if((e=this.data.privacyLists[g].indexOf(f))!==-1){this.data.privacyLists[g].splice(e,1)}else{this.data.privacyLists[g].push(f)}return this.data.privacyLists[g]};this.getPrivacyList=function(e){if(!this.data.privacyLists[e]){this.data.privacyLists[e]=[]}return this.data.privacyLists[e]};this.isInPrivacyList=function(f,e){if(!this.data.privacyLists[f]){return false}return this.data.privacyLists[f].indexOf(e)!==-1};this.setCustomData=function(e){this.data.customData=e};this.getCustomData=function(){return this.data.customData}};Candy.Core.Event=(function(a,e,c,d){var b;for(b in d){if(d.hasOwnProperty(b)){a[b]=d[b]}}a.KEYS={CHAT:1,PRESENCE:2,MESSAGE:3,LOGIN:4,PRESENCE_ERROR:5};a.Strophe={Connect:function(f){switch(f){case e.Status.CONNECTED:Candy.Core.log("[Connection] Connected");Candy.Core.Action.Jabber.GetJidIfAnonymous();case e.Status.ATTACHED:Candy.Core.log("[Connection] Attached");Candy.Core.Action.Jabber.Presence();Candy.Core.Action.Jabber.Autojoin();Candy.Core.Action.Jabber.GetIgnoreList();break;case e.Status.DISCONNECTED:Candy.Core.log("[Connection] Disconnected");break;case e.Status.AUTHFAIL:Candy.Core.log("[Connection] Authentication failed");break;case e.Status.CONNECTING:Candy.Core.log("[Connection] Connecting");break;case e.Status.DISCONNECTING:Candy.Core.log("[Connection] Disconnecting");break;case e.Status.AUTHENTICATING:Candy.Core.log("[Connection] Authenticating");break;case e.Status.ERROR:case e.Status.CONNFAIL:Candy.Core.log("[Connection] Failed ("+f+")");break;default:Candy.Core.log("[Connection] What?!");break}a.notifyObservers(a.KEYS.CHAT,{type:"connection",status:f})}};a.Login=function(f){a.notifyObservers(a.KEYS.LOGIN,{presetJid:f})};a.Jabber={Version:function(f){Candy.Core.log("[Jabber] Version");Candy.Core.Action.Jabber.Version(c(f));return true},Presence:function(f){Candy.Core.log("[Jabber] Presence");f=c(f);if(f.children('x[xmlns^="'+e.NS.MUC+'"]').length>0){if(f.attr("type")==="error"){a.Jabber.Room.PresenceError(f)}else{a.Jabber.Room.Presence(f)}}return true},Bookmarks:function(f){Candy.Core.log("[Jabber] Bookmarks");c("conference",f).each(function(){var g=c(this);if(g.attr("autojoin")){Candy.Core.Action.Jabber.Room.Join(g.attr("jid"))}});return true},PrivacyList:function(g){Candy.Core.log("[Jabber] PrivacyList");var f=Candy.Core.getUser();c('list[name="ignore"] item',g).each(function(){var h=c(this);if(h.attr("action")==="deny"){f.addToOrRemoveFromPrivacyList("ignore",h.attr("value"))}});Candy.Core.Action.Jabber.SetIgnoreListActive();return false},PrivacyListError:function(f){Candy.Core.log("[Jabber] PrivacyListError");if(c('error[code="404"][type="cancel"] item-not-found',f)){Candy.Core.Action.Jabber.ResetIgnoreList();Candy.Core.Action.Jabber.SetIgnoreListActive()}return false},Message:function(i){Candy.Core.log("[Jabber] Message");var i=c(i),h=i.attr("from"),g=i.attr("type"),f=i.attr("to");if(h!==e.getDomainFromJid(h)&&(g==="groupchat"||g==="chat"||g==="error")){a.Jabber.Room.Message(i)}else{if(!f&&h===e.getDomainFromJid(h)){a.notifyObservers(a.KEYS.CHAT,{type:(g||"message"),message:i.children("body").text()})}else{if(f&&h===e.getDomainFromJid(h)){a.notifyObservers(a.KEYS.CHAT,{type:(g||"message"),subject:i.children("subject").text(),message:i.children("body").text()})}}}return true},Room:{Leave:function(f){Candy.Core.log("[Jabber:Room] Leave");var f=c(f),l=f.attr("from"),n=e.getBareJidFromJid(l);if(!Candy.Core.getRoom(n)){return false}var j=Candy.Core.getRoom(n).getName(),m=f.find("item"),k="leave",i,h;delete Candy.Core.getRooms()[n];if(m.attr("role")==="none"){if(f.find("status").attr("code")==="307"){k="kick"}else{if(f.find("status").attr("code")==="301"){k="ban"}}i=m.find("reason").text();h=m.find("actor").attr("jid")}var g=new Candy.Core.ChatUser(l,e.getResourceFromJid(l),m.attr("affiliation"),m.attr("role"));a.notifyObservers(a.KEYS.PRESENCE,{roomJid:n,roomName:j,type:k,reason:i,actor:h,user:g});return true},Disco:function(i){Candy.Core.log("[Jabber:Room] Disco");var i=c(i),g=e.getBareJidFromJid(i.attr("from"));if(!Candy.Core.getRooms()[g]){Candy.Core.getRooms()[g]=new Candy.Core.ChatRoom(g)}var f=i.find("identity").attr("name"),h=Candy.Core.getRoom(g);if(h.getName()===null){h.setName(f)}return true},Presence:function(h){Candy.Core.log("[Jabber:Room] Presence");var l=Candy.Util.unescapeJid(h.attr("from")),o=e.getBareJidFromJid(l),m=h.attr("type");if(e.getResourceFromJid(l)===Candy.Core.getUser().getNick()&&m==="unavailable"){a.Jabber.Room.Leave(h);return true}var g=Candy.Core.getRoom(o);if(!g){Candy.Core.getRooms()[o]=new Candy.Core.ChatRoom(o);g=Candy.Core.getRoom(o)}var k=g.getRoster(),i,j,n=h.find("item");if(m!=="unavailable"){var f=e.getResourceFromJid(l);j=new Candy.Core.ChatUser(l,f,n.attr("affiliation"),n.attr("role"));if(g.getUser()===null&&Candy.Core.getUser().getNick()===f){g.setUser(j)}k.add(j);i="join"}else{i="leave";if(n.attr("role")==="none"){if(h.find("status").attr("code")==="307"){i="kick"}else{if(h.find("status").attr("code")==="301"){i="ban"}}}j=k.get(l);k.remove(l)}a.notifyObservers(a.KEYS.PRESENCE,{roomJid:o,roomName:g.getName(),user:j,action:i,currentUser:Candy.Core.getUser()});return true},PresenceError:function(i){Candy.Core.log("[Jabber:Room] Presence Error");var j=Candy.Util.unescapeJid(i.attr("from")),g=e.getBareJidFromJid(j),h=Candy.Core.getRooms()[g],f=h.getName();delete h;a.notifyObservers(a.KEYS.PRESENCE_ERROR,{msg:i,type:i.children("error").children()[0].tagName.toLowerCase(),roomJid:g,roomName:f})},Message:function(h){Candy.Core.log("[Jabber:Room] Message");var o,n;if(h.children("subject").length>0){o=Candy.Util.unescapeJid(e.getBareJidFromJid(h.attr("from")));n={name:e.getNodeFromJid(o),body:h.children("subject").text(),type:"subject"}}else{if(h.attr("type")==="error"){var m=h.children("error");if(m.attr("code")==="500"&&m.children("text").length>0){o=h.attr("from");n={type:"info",body:m.children("text").text()}}}else{if(h.children("body").length>0){if(h.attr("type")==="chat"){o=Candy.Util.unescapeJid(h.attr("from"));var f=e.getBareJidFromJid(o),i=!Candy.Core.getRoom(f),g=i?e.getNodeFromJid(o):e.getResourceFromJid(o);n={name:g,body:h.children("body").text(),type:h.attr("type"),isNoConferenceRoomJid:i}}else{o=Candy.Util.unescapeJid(e.getBareJidFromJid(h.attr("from")));var j=e.getResourceFromJid(h.attr("from"));if(j){j=e.unescapeNode(j);n={name:j,body:h.children("body").text(),type:h.attr("type")}}else{n={name:"",body:h.children("body").text(),type:"info"}}}}else{return true}}}var k=h.children("delay")?h.children("delay"):h.children('x[xmlns="'+e.NS.DELAY+'"]'),l=k!==undefined?k.attr("stamp"):null;a.notifyObservers(a.KEYS.MESSAGE,{roomJid:o,message:n,timestamp:l});return true}}};return a}(Candy.Core.Event||{},Strophe,jQuery,Candy.Util.Observable));Candy.View.Event=(function(a,b){a.Chat={onAdminMessage:function(c){return},onDisconnect:function(){return},onAuthfail:function(){return}};a.Room={onAdd:function(c){return},onShow:function(c){return},onHide:function(c){return},onSubjectChange:function(c){return},onClose:function(c){return},onPresenceChange:function(c){return}};a.Roster={onUpdate:function(c){return},onContextMenu:function(c){return{}},afterContextMenu:function(c){return}};a.Message={beforeShow:function(c){return c.message},onShow:function(c){return},beforeSend:function(c){return c}};return a}(Candy.View.Event||{},jQuery));Candy.View.Observer=(function(a,b){a.Chat={update:function(e,d){if(d.type==="connection"){switch(d.status){case Strophe.Status.CONNECTING:case Strophe.Status.AUTHENTICATING:Candy.View.Pane.Chat.Modal.show(b.i18n._("statusConnecting"),false,true);break;case Strophe.Status.ATTACHED:case Strophe.Status.CONNECTED:Candy.View.Pane.Chat.Modal.show(b.i18n._("statusConnected"));Candy.View.Pane.Chat.Modal.hide();break;case Strophe.Status.DISCONNECTING:Candy.View.Pane.Chat.Modal.show(b.i18n._("statusDisconnecting"),false,true);break;case Strophe.Status.DISCONNECTED:var c=Candy.Core.isAnonymousConnection()?Strophe.getDomainFromJid(Candy.Core.getUser().getJid()):null;Candy.View.Pane.Chat.Modal.showLoginForm(b.i18n._("statusDisconnected"),c);Candy.View.Event.Chat.onDisconnect();break;case Strophe.Status.AUTHFAIL:Candy.View.Pane.Chat.Modal.showLoginForm(b.i18n._("statusAuthfail"));Candy.View.Event.Chat.onAuthfail();break;default:Candy.View.Pane.Chat.Modal.show(b.i18n._("status",d.status));break}}else{if(d.type==="message"){Candy.View.Pane.Chat.adminMessage((d.subject||""),d.message)}else{if(d.type==="chat"||d.type==="groupchat"){Candy.View.Pane.Chat.onInfoMessage(Candy.View.getCurrent().roomJid,(d.subject||""),d.message)}}}}};a.Presence={update:function(h,e){if(e.type==="leave"){var c=Candy.View.Pane.Room.getUser(e.roomJid);Candy.View.Pane.Room.close(e.roomJid);a.Presence.notifyPrivateChats(c,e.type)}else{if(e.type==="kick"||e.type==="ban"){var g=e.actor?Strophe.getNodeFromJid(e.actor):null,f,d=[e.roomName];if(g){d.push(g)}switch(e.type){case"kick":f=b.i18n._((g?"youHaveBeenKickedBy":"youHaveBeenKicked"),d);break;case"ban":f=b.i18n._((g?"youHaveBeenBannedBy":"youHaveBeenBanned"),d);break}Candy.View.Pane.Chat.Modal.show(Mustache.to_html(Candy.View.Template.Chat.Context.adminMessageReason,{reason:e.reason,_action:f,_reason:b.i18n._("reasonWas",[e.reason])}));setTimeout(function(){Candy.View.Pane.Chat.Modal.hide(function(){Candy.View.Pane.Room.close(e.roomJid);a.Presence.notifyPrivateChats(e.user,e.type)})},5000);Candy.View.Event.Room.onPresenceChange({type:e.type,reason:e.reason,roomJid:e.roomJid,user:e.user})}else{if(!Candy.View.Pane.Chat.rooms[e.roomJid]){Candy.View.Pane.Room.init(e.roomJid,e.roomName);Candy.View.Pane.Room.show(e.roomJid)}Candy.View.Pane.Roster.update(e.roomJid,e.user,e.action,e.currentUser);if(Candy.View.Pane.Chat.rooms[e.user.getJid()]){Candy.View.Pane.Roster.update(e.user.getJid(),e.user,e.action,e.currentUser);Candy.View.Pane.PrivateRoom.setStatus(e.user.getJid(),e.action)}}}},notifyPrivateChats:function(d,e){Candy.Core.log("[View:Observer] notify Private Chats");var c;for(c in Candy.View.Pane.Chat.rooms){if(Candy.View.Pane.Chat.rooms.hasOwnProperty(c)&&Candy.View.Pane.Room.getUser(c)&&d.getJid()===Candy.View.Pane.Room.getUser(c).getJid()){Candy.View.Pane.Roster.update(c,d,e,d);Candy.View.Pane.PrivateRoom.setStatus(c,e)}}}};a.PresenceError={update:function(e,c){switch(c.type){case"not-authorized":var d;if(c.msg.children("x").children("password").length>0){d=b.i18n._("passwordEnteredInvalid",[c.roomName])}Candy.View.Pane.Chat.Modal.showEnterPasswordForm(c.roomJid,c.roomName,d);break;case"conflict":Candy.View.Pane.Chat.Modal.showNicknameConflictForm(c.roomJid);break;case"registration-required":Candy.View.Pane.Chat.Modal.showError("errorMembersOnly",[c.roomName]);break;case"service-unavailable":Candy.View.Pane.Chat.Modal.showError("errorMaxOccupantsReached",[c.roomName]);break}}};a.Message={update:function(d,c){if(c.message.type==="subject"){if(!Candy.View.Pane.Chat.rooms[c.roomJid]){Candy.View.Pane.Room.init(c.roomJid,c.message.name);Candy.View.Pane.Room.show(c.roomJid)}Candy.View.Pane.Room.setSubject(c.roomJid,c.message.body)}else{if(c.message.type==="info"){Candy.View.Pane.Chat.infoMessage(c.roomJid,c.message.body)}else{if(c.message.type==="chat"&&!Candy.View.Pane.Chat.rooms[c.roomJid]){Candy.View.Pane.PrivateRoom.open(c.roomJid,c.message.name,false,c.message.isNoConferenceRoomJid)}Candy.View.Pane.Message.show(c.roomJid,c.message.name,c.message.body,c.timestamp)}}}};a.Login={update:function(d,c){Candy.View.Pane.Chat.Modal.showLoginForm(null,c.presetJid)}};return a}(Candy.View.Observer||{},jQuery));Candy.View.Pane=(function(a,b){a.Window={_hasFocus:true,_plainTitle:document.title,_unreadMessagesCount:0,autoscroll:true,hasFocus:function(){return a.Window._hasFocus},increaseUnreadMessages:function(){a.Window.renderUnreadMessages(++a.Window._unreadMessagesCount)},reduceUnreadMessages:function(c){a.Window._unreadMessagesCount-=c;if(a.Window._unreadMessagesCount<=0){a.Window.clearUnreadMessages()}else{a.Window.renderUnreadMessages(a.Window._unreadMessagesCount)}},clearUnreadMessages:function(){a.Window._unreadMessagesCount=0;document.title=a.Window._plainTitle},renderUnreadMessages:function(c){document.title=Candy.View.Template.Window.unreadmessages.replace("{{count}}",c).replace("{{title}}",a.Window._plainTitle)},onFocus:function(){a.Window._hasFocus=true;if(Candy.View.getCurrent().roomJid){a.Room.setFocusToForm(Candy.View.getCurrent().roomJid);a.Chat.clearUnreadMessages(Candy.View.getCurrent().roomJid)}},onBlur:function(){a.Window._hasFocus=false}};a.Chat={rooms:[],addTab:function(d,c,e){var h=Candy.Util.jidToId(d),f=Mustache.to_html(Candy.View.Template.Chat.tab,{roomJid:d,roomId:h,name:c||Strophe.getNodeFromJid(d),privateUserChat:function(){return e==="chat"},roomType:e}),g=b(f).appendTo("#chat-tabs");g.click(a.Chat.tabClick);b("a.close",g).click(a.Chat.tabClose);a.Chat.fitTabs()},getTab:function(c){return b("#chat-tabs").children('li[data-roomjid="'+c+'"]')},removeTab:function(c){a.Chat.getTab(c).remove();a.Chat.fitTabs()},setActiveTab:function(c){b("#chat-tabs").children().each(function(){var d=b(this);if(d.attr("data-roomjid")===c){d.addClass("active")}else{d.removeClass("active")}})},increaseUnreadMessages:function(d){var c=this.getTab(d).find(".unread");c.show().text(c.text()!==""?parseInt(c.text(),10)+1:1);if(a.Chat.rooms[d].type==="chat"){a.Window.increaseUnreadMessages()}},clearUnreadMessages:function(d){var c=a.Chat.getTab(d).find(".unread");a.Window.reduceUnreadMessages(c.text());c.hide().text("")},tabClick:function(d){var c=Candy.View.getCurrent().roomJid;a.Chat.rooms[c].scrollPosition=a.Room.getPane(c,".message-pane-wrapper").scrollTop();a.Room.show(b(this).attr("data-roomjid"));d.preventDefault()},tabClose:function(d){var c=b(this).parent().attr("data-roomjid");if(a.Chat.rooms[c].type==="chat"){a.Room.close(c)}else{Candy.Core.Action.Jabber.Room.Leave(c)}return false},allTabsClosed:function(){Candy.Core.disconnect();a.Chat.Toolbar.hide();return},fitTabs:function(){var g=b("#chat-tabs").innerWidth(),f=0,e=b("#chat-tabs").children();e.each(function(){f+=b(this).css({width:"auto",overflow:"visible"}).outerWidth(true)});if(f>g){var c=e.outerWidth(true)-e.width(),d=Math.floor((g)/e.length)-c;e.css({width:d,overflow:"hidden"})}},updateToolbar:function(c){b("#chat-toolbar").find(".context").click(function(d){a.Chat.Context.show(d.currentTarget,c);d.stopPropagation()});Candy.View.Pane.Chat.Toolbar.updateUsercount(Candy.View.Pane.Chat.rooms[c].usercount)},adminMessage:function(d,e){if(Candy.View.getCurrent().roomJid){var c=Mustache.to_html(Candy.View.Template.Chat.adminMessage,{subject:d,message:e,sender:b.i18n._("administratorMessageSubject"),time:Candy.Util.localizedTime(new Date().toGMTString())});b("#chat-rooms").children().each(function(){a.Room.appendToMessagePane(b(this).attr("data-roomjid"),c)});a.Room.scrollToBottom(Candy.View.getCurrent().roomJid);Candy.View.Event.Chat.onAdminMessage({subject:d,message:e})}},infoMessage:function(c,d,e){a.Chat.onInfoMessage(c,d,e)},onInfoMessage:function(c,e,f){if(Candy.View.getCurrent().roomJid){var d=Mustache.to_html(Candy.View.Template.Chat.infoMessage,{subject:e,message:b.i18n._(f),time:Candy.Util.localizedTime(new Date().toGMTString())});a.Room.appendToMessagePane(c,d);if(Candy.View.getCurrent().roomJid===c){a.Room.scrollToBottom(Candy.View.getCurrent().roomJid)}}},Toolbar:{show:function(){b("#chat-toolbar").show()},hide:function(){b("#chat-toolbar").hide()},playSound:function(){a.Chat.Toolbar.onPlaySound()},onPlaySound:function(){var c=document.getElementById("chat-sound-player");c.SetVariable("method:stop","");c.SetVariable("method:play","")},onSoundControlClick:function(){var c=b("#chat-sound-control");if(c.hasClass("checked")){a.Chat.Toolbar.playSound=function(){};Candy.Util.setCookie("candy-nosound","1",365)}else{a.Chat.Toolbar.playSound=function(){a.Chat.Toolbar.onPlaySound()};Candy.Util.deleteCookie("candy-nosound")}c.toggleClass("checked")},onAutoscrollControlClick:function(){var c=b("#chat-autoscroll-control");if(c.hasClass("checked")){a.Room.scrollToBottom=function(d){a.Room.onScrollToStoredPosition(d)};a.Window.autoscroll=false}else{a.Room.scrollToBottom=function(d){a.Room.onScrollToBottom(d)};a.Room.scrollToBottom(Candy.View.getCurrent().roomJid);a.Window.autoscroll=true}c.toggleClass("checked")},onStatusMessageControlClick:function(){var c=b("#chat-statusmessage-control");if(c.hasClass("checked")){a.Chat.infoMessage=function(){};Candy.Util.setCookie("candy-nostatusmessages","1",365)}else{a.Chat.infoMessage=function(d,e,f){a.Chat.onInfoMessage(d,e,f)};Candy.Util.deleteCookie("candy-nostatusmessages")}c.toggleClass("checked")},updateUsercount:function(c){b("#chat-usercount").text(c)}},Modal:{show:function(d,e,c){if(e){a.Chat.Modal.showCloseControl()}else{a.Chat.Modal.hideCloseControl()}if(c){a.Chat.Modal.showSpinner()}else{a.Chat.Modal.hideSpinner()}b("#chat-modal").stop(false,true);b("#chat-modal-body").html(d);b("#chat-modal").fadeIn("fast");b("#chat-modal-overlay").show()},hide:function(c){b("#chat-modal").fadeOut("fast",function(){b("#chat-modal-body").text("");b("#chat-modal-overlay").hide()});b(document).keydown(function(d){if(d.which===27){d.preventDefault()}});if(c){c()}},showSpinner:function(){b("#chat-modal-spinner").show()},hideSpinner:function(){b("#chat-modal-spinner").hide()},showCloseControl:function(){b("#admin-message-cancel").show().click(function(c){a.Chat.Modal.hide();c.preventDefault()});b(document).keydown(function(c){if(c.which===27){a.Chat.Modal.hide();c.preventDefault()}})},hideCloseControl:function(){b("#admin-message-cancel").hide().click(function(){})},showLoginForm:function(d,c){a.Chat.Modal.show((d?d:"")+Mustache.to_html(Candy.View.Template.Login.form,{_labelUsername:b.i18n._("labelUsername"),_labelPassword:b.i18n._("labelPassword"),_loginSubmit:b.i18n._("loginSubmit"),displayPassword:!Candy.Core.isAnonymousConnection(),displayUsername:Candy.Core.isAnonymousConnection()||!c,presetJid:c?c:false}));b("#login-form").children()[0].focus();b("#login-form").submit(function(g){var h=b("#username").val(),e=b("#password").val();if(!Candy.Core.isAnonymousConnection()){var f=Candy.Core.getUser()&&h.indexOf("@")<0?h+"@"+Strophe.getDomainFromJid(Candy.Core.getUser().getJid()):h;if(f.indexOf("@")<0&&!Candy.Core.getUser()){Candy.View.Pane.Chat.Modal.showLoginForm(b.i18n._("loginInvalid"))}else{Candy.Core.connect(f,e)}}else{Candy.Core.connect(c,null,h)}return false})},showEnterPasswordForm:function(d,c,e){a.Chat.Modal.show(Mustache.to_html(Candy.View.Template.PresenceError.enterPasswordForm,{roomName:c,_labelPassword:b.i18n._("labelPassword"),_label:(e?e:b.i18n._("enterRoomPassword",[c])),_joinSubmit:b.i18n._("enterRoomPasswordSubmit")}),true);b("#password").focus();b("#enter-password-form").submit(function(){var f=b("#password").val();a.Chat.Modal.hide(function(){Candy.Core.Action.Jabber.Room.Join(d,f)});return false})},showNicknameConflictForm:function(c){a.Chat.Modal.show(Mustache.to_html(Candy.View.Template.PresenceError.nicknameConflictForm,{_labelNickname:b.i18n._("labelUsername"),_label:b.i18n._("nicknameConflict"),_loginSubmit:b.i18n._("loginSubmit")}));b("#nickname").focus();b("#nickname-conflict-form").submit(function(){var d=b("#nickname").val();a.Chat.Modal.hide(function(){Candy.Core.getUser().data.nick=d;Candy.Core.Action.Jabber.Room.Join(c)});return false})},showError:function(d,c){a.Chat.Modal.show(Mustache.to_html(Candy.View.Template.PresenceError.displayError,{_error:b.i18n._(d,c)}),true)}},Tooltip:{show:function(g,f){var h=b("#tooltip"),i=b(g.currentTarget);if(!f){f=i.attr("data-tooltip")}if(h.length===0){var d=Mustache.to_html(Candy.View.Template.Chat.tooltip);b("#chat-pane").append(d);h=b("#tooltip")}b("#context-menu").hide();h.stop(false,true);h.children("div").html(f);var j=i.offset(),c=Candy.Util.getPosLeftAccordingToWindowBounds(h,j.left),e=Candy.Util.getPosTopAccordingToWindowBounds(h,j.top);h.css({left:c.px,top:e.px,backgroundPosition:c.backgroundPositionAlignment+" "+e.backgroundPositionAlignment}).fadeIn("fast");i.mouseleave(function(k){k.stopPropagation();b("#tooltip").stop(false,true).fadeOut("fast",function(){b(this).css({top:0,left:0})})})}},Context:{init:function(){if(b("#context-menu").length===0){var c=Mustache.to_html(Candy.View.Template.Chat.Context.menu);b("#chat-pane").append(c);b("#context-menu").mouseleave(function(){b(this).fadeOut("fast")})}},show:function(e,p,h){e=b(e);var f=a.Chat.rooms[p].id,d=b("#context-menu"),o=b("ul li",d);b("#tooltip").hide();if(!h){h=Candy.Core.getUser()}o.remove();var k=this.getMenuLinks(p,h,e),c,l=function(r,q){return function(s){s.data.callback(s,r,q);b("#context-menu").hide()}};for(c in k){if(k.hasOwnProperty(c)){var n=k[c],j=Mustache.to_html(Candy.View.Template.Chat.Context.menulinks,{roomId:f,"class":n["class"],id:c,label:n.label});b("ul",d).append(j);b("#context-menu-"+c).bind("click",n,l(p,h))}}if(c){var m=e.offset(),g=Candy.Util.getPosLeftAccordingToWindowBounds(d,m.left),i=Candy.Util.getPosTopAccordingToWindowBounds(d,m.top);d.css({left:g.px,top:i.px,backgroundPosition:g.backgroundPositionAlignment+" "+i.backgroundPositionAlignment});d.fadeIn("fast");Candy.View.Event.Roster.afterContextMenu({roomJid:p,user:h,element:d});return true}},getMenuLinks:function(d,c,e){var f=b.extend(this.initialMenuLinks(e),Candy.View.Event.Roster.onContextMenu({roomJid:d,user:c,elem:e})),g;for(g in f){if(f.hasOwnProperty(g)&&f[g].requiredPermission!==undefined&&!f[g].requiredPermission(c,a.Room.getUser(d),e)){delete f[g]}}return f},initialMenuLinks:function(){return{"private":{requiredPermission:function(c,d){return d.getNick()!==c.getNick()&&Candy.Core.getRoom(Candy.View.getCurrent().roomJid)&&!Candy.Core.getUser().isInPrivacyList("ignore",c.getJid())},"class":"private",label:b.i18n._("privateActionLabel"),callback:function(f,d,c){b("#user-"+Candy.Util.jidToId(d)+"-"+Candy.Util.jidToId(c.getJid())).click()}},ignore:{requiredPermission:function(c,d){return d.getNick()!==c.getNick()&&!Candy.Core.getUser().isInPrivacyList("ignore",c.getJid())},"class":"ignore",label:b.i18n._("ignoreActionLabel"),callback:function(f,d,c){Candy.View.Pane.Room.ignoreUser(d,c.getJid())}},unignore:{requiredPermission:function(c,d){return d.getNick()!==c.getNick()&&Candy.Core.getUser().isInPrivacyList("ignore",c.getJid())},"class":"unignore",label:b.i18n._("unignoreActionLabel"),callback:function(f,d,c){Candy.View.Pane.Room.unignoreUser(d,c.getJid())}},kick:{requiredPermission:function(c,d){return d.getNick()!==c.getNick()&&d.isModerator()&&!c.isModerator()},"class":"kick",label:b.i18n._("kickActionLabel"),callback:function(f,d,c){a.Chat.Modal.show(Mustache.to_html(Candy.View.Template.Chat.Context.contextModalForm,{_label:b.i18n._("reason"),_submit:b.i18n._("kickActionLabel")}),true);b("#context-modal-field").focus();b("#context-modal-form").submit(function(e){Candy.Core.Action.Jabber.Room.Admin.UserAction(d,c.getJid(),"kick",b("#context-modal-field").val());a.Chat.Modal.hide();return false})}},ban:{requiredPermission:function(c,d){return d.getNick()!==c.getNick()&&d.isModerator()&&!c.isModerator()},"class":"ban",label:b.i18n._("banActionLabel"),callback:function(f,d,c){a.Chat.Modal.show(Mustache.to_html(Candy.View.Template.Chat.Context.contextModalForm,{_label:b.i18n._("reason"),_submit:b.i18n._("banActionLabel")}),true);b("#context-modal-field").focus();b("#context-modal-form").submit(function(g){Candy.Core.Action.Jabber.Room.Admin.UserAction(d,c.getJid(),"ban",b("#context-modal-field").val());a.Chat.Modal.hide();return false})}},subject:{requiredPermission:function(c,d){return d.getNick()===c.getNick()&&d.isModerator()},"class":"subject",label:b.i18n._("setSubjectActionLabel"),callback:function(f,d,c){a.Chat.Modal.show(Mustache.to_html(Candy.View.Template.Chat.Context.contextModalForm,{_label:b.i18n._("subject"),_submit:b.i18n._("setSubjectActionLabel")}),true);b("#context-modal-field").focus();b("#context-modal-form").submit(function(g){Candy.Core.Action.Jabber.Room.Admin.SetSubject(d,b("#context-modal-field").val());a.Chat.Modal.hide();g.preventDefault()})}}}},showEmoticonsMenu:function(h){h=b(h);var k=h.offset(),j=b("#context-menu"),g=b("ul",j),e="",d;b("#tooltip").hide();for(d=Candy.Util.Parser.emoticons.length-1;d>=0;d--){e=''+e}g.html('
diff --git a/lms/xmodule_namespace.py b/lms/xmodule_namespace.py
index aaef0b76db..d57ad9ce52 100644
--- a/lms/xmodule_namespace.py
+++ b/lms/xmodule_namespace.py
@@ -3,6 +3,8 @@ Namespace that defines fields common to all blocks used in the LMS
"""
from xblock.core import Namespace, Boolean, Scope, String, Float
from xmodule.fields import Date, Timedelta
+from datetime import datetime
+from pytz import UTC
class LmsNamespace(Namespace):
@@ -25,7 +27,11 @@ class LmsNamespace(Namespace):
scope=Scope.settings,
)
- start = Date(help="Start time when this module is visible", scope=Scope.settings)
+ start = Date(
+ help="Start time when this module is visible",
+ default=datetime.fromtimestamp(0, UTC),
+ scope=Scope.settings
+ )
due = Date(help="Date that this problem is due by", scope=Scope.settings)
source_file = String(help="source file name (eg for latex)", scope=Scope.settings)
giturl = String(help="url root for course data git repository", scope=Scope.settings)
@@ -35,8 +41,16 @@ class LmsNamespace(Namespace):
help="Amount of time after the due date that submissions will be accepted",
scope=Scope.settings
)
- showanswer = String(help="When to show the problem answer to the student", scope=Scope.settings, default="closed")
- rerandomize = String(help="When to rerandomize the problem", default="always", scope=Scope.settings)
+ showanswer = String(
+ help="When to show the problem answer to the student",
+ scope=Scope.settings,
+ default="finished"
+ )
+ rerandomize = String(
+ help="When to rerandomize the problem",
+ default="never",
+ scope=Scope.settings
+ )
days_early_for_beta = Float(
help="Number of days early to show content to beta users",
default=None,
diff --git a/rakelib/django.rake b/rakelib/django.rake
index eeb8135d4d..53c299ac9f 100644
--- a/rakelib/django.rake
+++ b/rakelib/django.rake
@@ -111,11 +111,6 @@ namespace :cms do
end
end
- desc "Imports all the templates from the code pack"
- task :update_templates do
- sh(django_admin(:cms, :dev, :update_templates))
- end
-
desc "Import course data within the given DATA_DIR variable"
task :xlint do
if ENV['DATA_DIR'] and ENV['COURSE_DIR']
diff --git a/rakelib/helpers.rb b/rakelib/helpers.rb
index 3373214a19..925b7e1b28 100644
--- a/rakelib/helpers.rb
+++ b/rakelib/helpers.rb
@@ -52,8 +52,14 @@ end
# Runs Process.spawn, and kills the process at the end of the rake process
# Expects the same arguments as Process.spawn
-def background_process(*command)
- pid = Process.spawn({}, *command, {:pgroup => true})
+def background_process(command, logfile=nil)
+ spawn_opts = {:pgroup => true}
+ if !logfile.nil?
+ puts "Running '#{command.join(' ')}', redirecting output to #{logfile}".red
+ spawn_opts[[:err, :out]] = [logfile, 'a']
+ end
+ pid = Process.spawn({}, *command, spawn_opts)
+ command = [*command]
at_exit do
puts "Ending process and children"
@@ -88,9 +94,10 @@ end
# Runs a command as a background process, as long as no other processes
# tagged with the same tag are running
-def singleton_process(*command)
+def singleton_process(command, logfile=nil)
+ command = [*command]
if Sys::ProcTable.ps.select {|proc| proc.cmdline.include?(command.join(' '))}.empty?
- background_process(*command)
+ background_process(command, logfile)
else
puts "Process '#{command.join(' ')} already running, skipping".blue
end
diff --git a/rakelib/jasmine.rake b/rakelib/jasmine.rake
index ff72161937..5a0c4acedc 100644
--- a/rakelib/jasmine.rake
+++ b/rakelib/jasmine.rake
@@ -8,6 +8,11 @@ PREFERRED_METHOD = PHANTOMJS_PATH.nil? ? 'browser' : 'phantomjs'
if PHANTOMJS_PATH.nil?
puts("phantomjs not found on path. Set $PHANTOMJS_PATH. Using browser for jasmine tests".blue)
end
+LOGDIR = 'logs/jasmine'
+
+CLOBBER.include(LOGDIR)
+
+directory LOGDIR
def django_for_jasmine(system, django_reload)
if !django_reload
@@ -17,7 +22,7 @@ def django_for_jasmine(system, django_reload)
port = 10000 + rand(40000)
jasmine_url = "http://localhost:#{port}/_jasmine/"
- background_process(*django_admin(system, 'jasmine', 'runserver', '-v', '0', port.to_s, reload_arg).split(' '))
+ background_process(django_admin(system, 'jasmine', 'runserver', '-v', '0', port.to_s, reload_arg).split(' '), "#{LOGDIR}/django.log")
up = false
start_time = Time.now
@@ -80,7 +85,7 @@ end
namespace :jasmine do
namespace system do
desc "Open jasmine tests for #{system} in your default browser"
- task :browser => [:clean_reports_dir] do
+ task :browser => [:clean_reports_dir, LOGDIR] do
Rake::Task[:assets].invoke(system, 'jasmine')
django_for_jasmine(system, true) do |jasmine_url|
jasmine_browser(jasmine_url)
@@ -88,7 +93,7 @@ end
end
desc "Open jasmine tests for #{system} in your default browser, and dynamically recompile coffeescript"
- task :'browser:watch' => [:clean_reports_dir, :'assets:coffee:_watch'] do
+ task :'browser:watch' => [:clean_reports_dir, :'assets:coffee:_watch', LOGDIR] do
django_for_jasmine(system, true) do |jasmine_url|
jasmine_browser(jasmine_url, jitter=0, wait=0)
end
@@ -97,7 +102,7 @@ end
end
desc "Use phantomjs to run jasmine tests for #{system} from the console"
- task :phantomjs => [:clean_reports_dir] do
+ task :phantomjs => [:clean_reports_dir, LOGDIR] do
Rake::Task[:assets].invoke(system, 'jasmine')
phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs'
django_for_jasmine(system, false) do |jasmine_url|
diff --git a/requirements/edx/github.txt b/requirements/edx/github.txt
index f64568dc10..15bb98814b 100644
--- a/requirements/edx/github.txt
+++ b/requirements/edx/github.txt
@@ -3,11 +3,11 @@
# Third-party:
-e git://github.com/edx/django-staticfiles.git@6d2504e5c8#egg=django-staticfiles
-e git://github.com/edx/django-pipeline.git#egg=django-pipeline
--e git://github.com/edx/django-wiki.git@ac906abe#egg=django-wiki
+-e git://github.com/edx/django-wiki.git@41815e2ef1b0323f92900f8e60711b0f0c37766b#egg=django-wiki
-e git://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev
-e git://github.com/eventbrite/zendesk.git@d53fe0e81b623f084e91776bcf6369f8b7b63879#egg=zendesk
# Our libraries:
--e git+https://github.com/edx/XBlock.git@4d8735e883#egg=XBlock
--e git+https://github.com/edx/codejail.git@0a1b468#egg=codejail
+-e git+https://github.com/edx/XBlock.git@3974e999fe853a37dfa6fadf0611289434349409#egg=XBlock
+-e git+https://github.com/edx/codejail.git@c08967fb44d1bcdb259d3ec58812e3ac592539c2#egg=codejail
-e git+https://github.com/edx/diff-cover.git@v0.1.3#egg=diff_cover
diff --git a/requirements/edx/local.txt b/requirements/edx/local.txt
index f5ba60e21b..04a1f7f2c6 100644
--- a/requirements/edx/local.txt
+++ b/requirements/edx/local.txt
@@ -2,6 +2,7 @@
-e common/lib/calc
-e common/lib/capa
-e common/lib/chem
+-e common/lib/sandbox-packages
-e common/lib/symmath
-e common/lib/xmodule
-e .
diff --git a/scripts/create-dev-env.sh b/scripts/create-dev-env.sh
index a28ee1a8b4..8699cc7656 100755
--- a/scripts/create-dev-env.sh
+++ b/scripts/create-dev-env.sh
@@ -497,7 +497,7 @@ mkdir -p "$BASE/data"
rake django-admin[syncdb,lms,dev,--noinput]
rake django-admin[migrate]
-rake cms:update_templates
+
# Configure Git
output "Fixing your git default settings"