-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Proxy to XModule on demand #1088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
|
|
||
| from xmodule.modulestore import Location | ||
| from xmodule.x_module import XModuleDescriptor | ||
| from xmodule.course_module import CourseDescriptor | ||
|
|
||
|
|
||
| class Dummy(object): | ||
|
|
@@ -124,38 +123,49 @@ def _create(cls, target_class, **kwargs): | |
| :target_class: is ignored | ||
| """ | ||
|
|
||
| # All class attributes (from this class and base classes) are | ||
| # passed in via **kwargs. However, some of those aren't actual field values, | ||
| # so pop those off for use separately | ||
|
|
||
| DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info'] | ||
| # catch any old style users before they get into trouble | ||
| assert not 'template' in kwargs | ||
| data = kwargs.get('data') | ||
| category = kwargs.get('category') | ||
| display_name = kwargs.get('display_name') | ||
| metadata = kwargs.get('metadata', {}) | ||
| location = kwargs.get('location') | ||
| if kwargs.get('boilerplate') is not None: | ||
| template_id = kwargs.get('boilerplate') | ||
| assert 'template' not in kwargs | ||
| parent_location = Location(kwargs.pop('parent_location', None)) | ||
| data = kwargs.pop('data', None) | ||
| category = kwargs.pop('category', None) | ||
| display_name = kwargs.pop('display_name', None) | ||
| metadata = kwargs.pop('metadata', {}) | ||
| location = kwargs.pop('location') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume we desire things to error out if 'location' isn't present in kwargs?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| assert location != parent_location | ||
|
|
||
| store = kwargs.pop('modulestore') | ||
|
|
||
| # This code was based off that in cms/djangoapps/contentstore/views.py | ||
| parent = kwargs.pop('parent', None) or store.get_item(parent_location) | ||
|
|
||
| if 'boilerplate' in kwargs: | ||
| template_id = kwargs.pop('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 = kwargs.get('modulestore') | ||
|
|
||
| # replace the display name with an optional parameter passed in from the caller | ||
| if display_name is not None: | ||
| metadata['display_name'] = display_name | ||
| store.create_and_save_xmodule(location, metadata=metadata, definition_data=data) | ||
| module = store.create_and_save_xmodule(location, metadata=metadata, definition_data=data) | ||
|
|
||
| if location.category not in DETACHED_CATEGORIES: | ||
| module = store.get_item(location) | ||
|
|
||
| parent_location = Location(kwargs.get('parent_location')) | ||
| assert location != parent_location | ||
| for attr, val in kwargs.items(): | ||
| setattr(module, attr, val) | ||
| module.save() | ||
|
|
||
| # This code was based off that in cms/djangoapps/contentstore/views.py | ||
| parent = kwargs.get('parent') or store.get_item(parent_location) | ||
| store.save_xmodule(module) | ||
|
|
||
| if location.category not in DETACHED_CATEGORIES: | ||
| parent.children.append(location.url()) | ||
| store.update_children(parent_location, parent.children) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did the try/except go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Into the
_xmoduleproperty ofXModuleDescriptor. We're lazily creating theXModulewhen it's needed, rather than on load.