def create_submission(self, student_item_dict, student_sub_data):

        # Store the student's response text in a JSON-encodable dict
        # so that later we can add additional response fields.
        student_sub_dict = prepare_submission_for_serialization(student_sub_data)

        if self.file_upload_type:
            student_sub_dict["file_key"] = self._get_student_item_key()
        submission = api.create_submission(student_item_dict, student_sub_dict)
        self.create_workflow(submission["uuid"])
        self.submission_uuid = submission["uuid"]

        # Emit analytics event...
        self.runtime.publish(
            self,
            "openassessmentblock.create_submission",
            {
                "submission_uuid": submission["uuid"],
                "attempt_number": submission["attempt_number"],
                "created_at": submission["created_at"],
                "submitted_at": submission["submitted_at"],
                "answer": submission["answer"],
            },
        )

        return submission
    def save_submission(self, data, suffix=""):
        """
        Save the current student's response submission.
        If the student already has a response saved, this will overwrite it.

        Args:
            data (dict): Data should have a single key 'submission' that contains
                the text of the student's response. Optionally, the data could
                have a 'file_url' key that is the path to an associated file for
                this submission.
            suffix (str): Not used.

        Returns:
            dict: Contains a bool 'success' and unicode string 'msg'.
        """
        if "submission" in data:
            student_sub_data = data["submission"]
            success, msg = validate_submission(student_sub_data, self.prompts, self._)
            if not success:
                return {"success": False, "msg": msg}
            try:
                self.saved_response = json.dumps(prepare_submission_for_serialization(student_sub_data))
                self.has_saved = True

                # Emit analytics event...
                self.runtime.publish(
                    self, "openassessmentblock.save_submission", {"saved_response": self.saved_response}
                )
            except:
                return {"success": False, "msg": self._(u"This response could not be saved.")}
            else:
                return {"success": True, "msg": u""}
        else:
            return {"success": False, "msg": self._(u"This response was not submitted.")}
Exemple #3
0
    def create_submission(self, student_item_dict, student_sub_data):

        # Store the student's response text in a JSON-encodable dict
        # so that later we can add additional response fields.
        student_sub_dict = prepare_submission_for_serialization(student_sub_data)

        if self.file_upload_type:
            student_sub_dict['file_key'] = self._get_student_item_key()
        submission = api.create_submission(student_item_dict, student_sub_dict)
        self.create_workflow(submission["uuid"])
        self.submission_uuid = submission["uuid"]

        # Emit analytics event...
        self.runtime.publish(
            self,
            "openassessmentblock.create_submission",
            {
                "submission_uuid": submission["uuid"],
                "attempt_number": submission["attempt_number"],
                "created_at": submission["created_at"],
                "submitted_at": submission["submitted_at"],
                "answer": submission["answer"],
            }
        )

        return submission
    def create_submission(self,
                          student_item_dict,
                          student_sub_data,
                          files_descriptions=None):
        # Import is placed here to avoid model import at project startup.
        from submissions import api

        # Store the student's response text in a JSON-encodable dict
        # so that later we can add additional response fields.
        files_descriptions = files_descriptions if files_descriptions else []
        student_sub_dict = prepare_submission_for_serialization(
            student_sub_data)

        if self.file_upload_type:
            student_sub_dict['file_keys'] = []
            student_sub_dict['files_descriptions'] = []
            for i in range(self.MAX_FILES_COUNT):
                key_to_save = ''
                file_description = ''
                item_key = self._get_student_item_key(i)
                try:
                    url = file_upload_api.get_download_url(item_key)
                    if url:
                        key_to_save = item_key
                        try:
                            file_description = files_descriptions[i]
                        except IndexError:
                            pass
                except FileUploadError:
                    logger.exception(
                        u"FileUploadError for student_item: {student_item_dict}"
                        u" and submission data: {student_sub_data} with file"
                        "descriptions {files_descriptions}".format(
                            student_item_dict=student_item_dict,
                            student_sub_data=student_sub_data,
                            files_descriptions=files_descriptions))
                if key_to_save:
                    student_sub_dict['file_keys'].append(key_to_save)
                    student_sub_dict['files_descriptions'].append(
                        file_description)
                else:
                    break

        submission = api.create_submission(student_item_dict, student_sub_dict)
        self.create_workflow(submission["uuid"])
        self.submission_uuid = submission["uuid"]

        # Emit analytics event...
        self.runtime.publish(
            self, "openassessmentblock.create_submission", {
                "submission_uuid": submission["uuid"],
                "attempt_number": submission["attempt_number"],
                "created_at": submission["created_at"],
                "submitted_at": submission["submitted_at"],
                "answer": submission["answer"],
            })

        return submission
Exemple #5
0
    def create_submission(self, student_item_dict, student_sub_data, files_descriptions=None):
        # Import is placed here to avoid model import at project startup.
        from submissions import api

        # Store the student's response text in a JSON-encodable dict
        # so that later we can add additional response fields.
        files_descriptions = files_descriptions if files_descriptions else []
        student_sub_dict = prepare_submission_for_serialization(student_sub_data)

        if self.file_upload_type:
            student_sub_dict['file_keys'] = []
            student_sub_dict['files_descriptions'] = []
            for i in range(self.MAX_FILES_COUNT):
                key_to_save = ''
                file_description = ''
                item_key = self._get_student_item_key(i)
                try:
                    url = file_upload_api.get_download_url(item_key)
                    if url:
                        key_to_save = item_key
                        try:
                            file_description = files_descriptions[i]
                        except IndexError:
                            pass
                except FileUploadError:
                    pass
                if key_to_save:
                    student_sub_dict['file_keys'].append(key_to_save)
                    student_sub_dict['files_descriptions'].append(file_description)
                else:
                    break

        submission = api.create_submission(student_item_dict, student_sub_dict)
        self.create_workflow(submission["uuid"])
        self.submission_uuid = submission["uuid"]

        # Emit analytics event...
        self.runtime.publish(
            self,
            "openassessmentblock.create_submission",
            {
                "submission_uuid": submission["uuid"],
                "attempt_number": submission["attempt_number"],
                "created_at": submission["created_at"],
                "submitted_at": submission["submitted_at"],
                "answer": submission["answer"],
            }
        )

        return submission
    def save_submission(self, data, suffix=''):
        """
        Save the current student's response submission.
        If the student already has a response saved, this will overwrite it.

        Args:
            data (dict): Data should have a single key 'submission' that contains
                the text of the student's response. Optionally, the data could
                have a 'file_urls' key that is the path to an associated file for
                this submission.
            suffix (str): Not used.

        Returns:
            dict: Contains a bool 'success' and unicode string 'msg'.
        """
        if 'submission' in data:
            student_sub_data = data['submission']
            success, msg = validate_submission(student_sub_data, self.prompts,
                                               self._, self.text_response)
            if not success:
                return {'success': False, 'msg': msg}
            try:
                self.saved_response = json.dumps(
                    prepare_submission_for_serialization(student_sub_data))
                self.has_saved = True

                # Emit analytics event...
                self.runtime.publish(self,
                                     "openassessmentblock.save_submission",
                                     {"saved_response": self.saved_response})
            except:
                return {
                    'success': False,
                    'msg': self._(u"This response could not be saved.")
                }
            else:
                return {'success': True, 'msg': u''}
        else:
            return {
                'success': False,
                'msg': self._(u"This response was not submitted.")
            }