def set_assessment_content(self, unit, assessment_content, errors=None):
        """Updates the content of an assessment."""
        if errors is None:
            errors = []

        path = self._app_context.fs.impl.physical_to_logical(
            self.get_assessment_filename(unit.unit_id))
        root_name = 'assessment'

        try:
            content, noverify_text = verify.convert_javascript_to_python(
                assessment_content, root_name)
            assessment = verify.evaluate_python_expression_from_text(
                content, root_name, verify.Assessment().scope, noverify_text)
        except Exception:  # pylint: disable-msg=broad-except
            errors.append('Unable to parse %s:\n%s' % (
                root_name,
                str(sys.exc_info()[1])))
            return

        verifier = verify.Verifier()
        try:
            verifier.verify_assessment_instance(assessment, path)
        except verify.SchemaException:
            errors.append('Error validating %s\n' % root_name)
            return

        fs = self.app_context.fs
        fs.put(
            path, vfs.string_to_stream(assessment_content),
            is_draft=not unit.now_available)
Example #2
0
    def set_assessment_content(self, unit, assessment_content, errors=None):
        """Updates the content of an assessment."""
        if errors is None:
            errors = []

        path = self._app_context.fs.impl.physical_to_logical(
            self.get_assessment_filename(unit.unit_id))
        root_name = 'assessment'

        try:
            content, noverify_text = verify.convert_javascript_to_python(
                assessment_content, root_name)
            assessment = verify.evaluate_python_expression_from_text(
                content, root_name, verify.Assessment().scope, noverify_text)
        except Exception:  # pylint: disable-msg=broad-except
            errors.append('Unable to parse %s:\n%s' % (
                root_name,
                str(sys.exc_info()[1])))
            return

        verifier = verify.Verifier()
        try:
            verifier.verify_assessment_instance(assessment, path)
        except verify.SchemaException:
            errors.append('Error validating %s\n' % root_name)
            return

        fs = self.app_context.fs
        fs.put(
            path, vfs.string_to_stream(assessment_content),
            is_draft=not unit.now_available)
 def get_activity_as_python(self, unit_id, lesson_id):
     """Gets the corresponding activity as a Python object."""
     root_name = 'activity'
     course = self._get_course()
     activity_text = course.app_context.fs.get(
         os.path.join(course.app_context.get_home(),
                      course.get_activity_filename(unit_id, lesson_id)))
     content, noverify_text = verify.convert_javascript_to_python(
         activity_text, root_name)
     activity = verify.evaluate_python_expression_from_text(
         content, root_name, verify.Activity().scope, noverify_text)
     return activity