Commit d1ed6fbc by Don Mitchell

More xblock.save() calls to handle fields set during inits

parent b143de1f
...@@ -225,6 +225,8 @@ class CachingDescriptorSystem(MakoDescriptorSystem): ...@@ -225,6 +225,8 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
non_draft_loc = location.replace(revision=None) non_draft_loc = location.replace(revision=None)
metadata_to_inherit = self.cached_metadata.get(non_draft_loc.url(), {}) metadata_to_inherit = self.cached_metadata.get(non_draft_loc.url(), {})
inherit_metadata(module, metadata_to_inherit) inherit_metadata(module, metadata_to_inherit)
# decache any computed pending field settings
module.save()
return module return module
except: except:
log.warning("Failed to load descriptor", exc_info=True) log.warning("Failed to load descriptor", exc_info=True)
...@@ -630,6 +632,8 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -630,6 +632,8 @@ class MongoModuleStore(ModuleStoreBase):
definition_data = {} definition_data = {}
dbmodel = self._create_new_model_data(location.category, location, definition_data, metadata) dbmodel = self._create_new_model_data(location.category, location, definition_data, metadata)
xmodule = xblock_class(system, dbmodel) xmodule = xblock_class(system, dbmodel)
# decache any pending field settings from init
xmodule.save()
return xmodule return xmodule
def save_xmodule(self, xmodule): def save_xmodule(self, xmodule):
......
...@@ -116,4 +116,6 @@ class CachingDescriptorSystem(MakoDescriptorSystem): ...@@ -116,4 +116,6 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
module.previous_version = json_data.get('previous_version') module.previous_version = json_data.get('previous_version')
module.update_version = json_data.get('update_version') module.update_version = json_data.get('update_version')
module.definition_locator = self.modulestore.definition_locator(definition) module.definition_locator = self.modulestore.definition_locator(definition)
# decache any pending field settings
module.save()
return module return module
...@@ -537,11 +537,14 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock): ...@@ -537,11 +537,14 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
system: Module system system: Module system
""" """
return self.module_class( # save any field changes
module = self.module_class(
system, system,
self, self,
system.xblock_model_data(self), system.xblock_model_data(self),
) )
module.save()
return module
def has_dynamic_children(self): def has_dynamic_children(self):
""" """
...@@ -614,6 +617,9 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock): ...@@ -614,6 +617,9 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
new_block = system.xblock_from_json(cls, usage_id, json_data) new_block = system.xblock_from_json(cls, usage_id, json_data)
if parent_xblock is not None: if parent_xblock is not None:
parent_xblock.children.append(new_block) parent_xblock.children.append(new_block)
# decache pending children field settings (Note, truly persisting at this point would break b/c
# persistence assumes children is a list of ids not actual xblocks)
parent_xblock.save()
return new_block return new_block
@classmethod @classmethod
......
import json import json
import logging import logging
import re
import sys import sys
from functools import partial from functools import partial
...@@ -13,7 +12,6 @@ from django.http import Http404 ...@@ -13,7 +12,6 @@ from django.http import Http404
from django.http import HttpResponse from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
import pyparsing
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from statsd import statsd from statsd import statsd
...@@ -599,14 +597,14 @@ def _check_files_limits(files): ...@@ -599,14 +597,14 @@ def _check_files_limits(files):
# Check number of files submitted # Check number of files submitted
if len(inputfiles) > settings.MAX_FILEUPLOADS_PER_INPUT: if len(inputfiles) > settings.MAX_FILEUPLOADS_PER_INPUT:
msg = 'Submission aborted! Maximum %d files may be submitted at once' %\ msg = 'Submission aborted! Maximum %d files may be submitted at once' % \
settings.MAX_FILEUPLOADS_PER_INPUT settings.MAX_FILEUPLOADS_PER_INPUT
return msg return msg
# Check file sizes # Check file sizes
for inputfile in inputfiles: for inputfile in inputfiles:
if inputfile.size > settings.STUDENT_FILEUPLOAD_MAX_SIZE: # Bytes if inputfile.size > settings.STUDENT_FILEUPLOAD_MAX_SIZE: # Bytes
msg = 'Submission aborted! Your file "%s" is too large (max size: %d MB)' %\ msg = 'Submission aborted! Your file "%s" is too large (max size: %d MB)' % \
(inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE / (1000 ** 2)) (inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE / (1000 ** 2))
return msg return msg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment