예제 #1
0
    def __init__(self, runtime, descriptor, model_data):
        '''
        Construct a new xmodule

        runtime: An XBlock runtime allowing access to external resources

        descriptor: the XModuleDescriptor that this module is an instance of.

        model_data: A dictionary-like object that maps field names to values
            for those fields.
        '''
        super(XModule, self).__init__(runtime, model_data)
        self._model_data = model_data
        self.system = runtime
        self.descriptor = descriptor
        # 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 getattr(self, 'category', None) is None:
                self.category = self.location.category
        elif isinstance(self.location, BlockUsageLocator):
            self.url_name = self.location.usage_id
            if getattr(self, 'category', None) is None:
                raise InsufficientSpecificationError()
        else:
            raise InsufficientSpecificationError()
        self._loaded_children = None
예제 #2
0
 def url_name(self):
     if isinstance(self.location, Location):
         return self.location.name
     elif isinstance(self.location, BlockUsageLocator):
         return self.location.usage_id
     else:
         raise InsufficientSpecificationError()
예제 #3
0
 def version(self):
     """
     Returns the ObjectId referencing this specific location.
     Raises InsufficientSpecificationError if the instance
     doesn't have a complete enough specification.
     """
     raise InsufficientSpecificationError()
예제 #4
0
 def url(self):
     """
     Return a string containing the URL for this location. Raises
     InsufficientSpecificationError if the instance doesn't have a
     complete enough specification to generate a url
     """
     raise InsufficientSpecificationError()
예제 #5
0
 def _validate_args(self, url, version_guid, package_id):
     """
     Validate provided arguments. Internal use only which is why it checks for each
     arg and doesn't use keyword
     """
     if not any((url, version_guid, package_id)):
         raise InsufficientSpecificationError("Must provide one of url, version_guid, package_id")
예제 #6
0
 def validate_args(self, url, version_guid, course_id, branch):
     """
     Validate provided arguments.
     """
     need_oneof = set(('url', 'version_guid', 'course_id'))
     args, _, _, values = inspect.getargvalues(inspect.currentframe())
     provided_args = [a for a in args if a != 'self' and values[a] is not None]
     if len(need_oneof.intersection(provided_args)) == 0:
         raise InsufficientSpecificationError("Must provide one of these args: %s " %
                                              list(need_oneof))
예제 #7
0
 def get_courses(self, **kwargs):
     """
     Returns all the courses on the Draft or Published branch depending on the branch setting.
     """
     branch_setting = self.get_branch_setting()
     if branch_setting == ModuleStoreEnum.Branch.draft_preferred:
         return super(DraftVersioningModuleStore, self).get_courses(ModuleStoreEnum.BranchName.draft, **kwargs)
     elif branch_setting == ModuleStoreEnum.Branch.published_only:
         return super(DraftVersioningModuleStore, self).get_courses(ModuleStoreEnum.BranchName.published, **kwargs)
     else:
         raise InsufficientSpecificationError()
예제 #8
0
 def get_courses(self, **kwargs):  # lint-amnesty, pylint: disable=arguments-differ
     """
     Returns all the courses on the Draft or Published branch depending on the branch setting.
     """
     branch_setting = self.get_branch_setting()
     if branch_setting == ModuleStoreEnum.Branch.draft_preferred:
         return super().get_courses(ModuleStoreEnum.BranchName.draft, **kwargs)
     elif branch_setting == ModuleStoreEnum.Branch.published_only:
         return super().get_courses(ModuleStoreEnum.BranchName.published, **kwargs)
     else:
         raise InsufficientSpecificationError()
예제 #9
0
    def __init__(self, *args, **kwargs):
        """
        Construct a new XModuleDescriptor. The only required arguments are the
        system, used for interaction with external resources, and the
        definition, which specifies all the data needed to edit and display the
        problem (but none of the associated metadata that handles recordkeeping
        around the problem).

        This allows for maximal flexibility to add to the interface while
        preserving backwards compatibility.

        runtime: A DescriptorSystem for interacting with external resources

        model_data: A dictionary-like object that maps field names to values
            for those fields.

        XModuleDescriptor.__init__ takes the same arguments as xblock.core:XBlock.__init__
        """
        super(XModuleDescriptor, self).__init__(*args, **kwargs)
        self.system = self.runtime
        if isinstance(self.location, Location):
            self.url_name = self.location.name
            if getattr(self, 'category', None) is None:
                self.category = self.location.category
        elif isinstance(self.location, BlockUsageLocator):
            self.url_name = self.location.usage_id
            if getattr(self, 'category', None) is None:
                raise InsufficientSpecificationError()
        else:
            raise InsufficientSpecificationError()
        # update_version is the version which last updated this xblock v prev being the penultimate updater
        # leaving off original_version since it complicates creation w/o any obv value yet and is computable
        # by following previous until None
        # definition_locator is only used by mongostores which separate definitions from blocks
        self.edited_by = self.edited_on = self.previous_version = self.update_version = self.definition_locator = None
        self._child_instances = None
예제 #10
0
 def _lookup_course(self, course_locator):
     """
     overrides the implementation of _lookup_course in SplitMongoModuleStore in order to
     use the configured branch_setting in the course_locator
     """
     if course_locator.org and course_locator.course and course_locator.run:
         if course_locator.branch is None:
             # default it based on branch_setting
             branch_setting = self.get_branch_setting()
             if branch_setting == ModuleStoreEnum.Branch.draft_preferred:
                 course_locator = course_locator.for_branch(
                     ModuleStoreEnum.BranchName.draft)
             elif branch_setting == ModuleStoreEnum.Branch.published_only:
                 course_locator = course_locator.for_branch(
                     ModuleStoreEnum.BranchName.published)
             else:
                 raise InsufficientSpecificationError(course_locator)
     return super(DraftVersioningModuleStore,
                  self)._lookup_course(course_locator)