示例#1
0
 def put(self, exploration_id):
     """Handles PUT requests for draft updation."""
     # Raise an Exception if the draft change list fails non-strict
     # validation.
     try:
         change_list_dict = self.payload.get('change_list')
         change_list = [
             exp_domain.ExplorationChange(change)
             for change in change_list_dict
         ]
         version = self.payload.get('version')
         exp_services.create_or_update_draft(exploration_id, self.user_id,
                                             change_list, version,
                                             datetime.datetime.utcnow())
     except utils.ValidationError as e:
         # We leave any pre-existing draft changes in the datastore.
         raise self.InvalidInputException(e)
     exp_user_data = user_models.ExplorationUserDataModel.get(
         self.user_id, exploration_id)
     draft_change_list_id = exp_user_data.draft_change_list_id
     # If the draft_change_list_id is False, have the user discard the draft
     # changes. We save the draft to the datastore even if the version is
     # invalid, so that it is available for recovery later.
     self.render_json({
         'draft_change_list_id':
         draft_change_list_id,
         'is_version_of_draft_valid':
         exp_services.is_version_of_draft_valid(exploration_id, version)
     })
示例#2
0
    def put(self, exploration_id):
        """Handles PUT requests for draft updation."""
        # Raise an Exception if the draft change list fails non-strict
        # validation.
        try:
            change_list_dict = self.payload.get('change_list')
            change_list = [
                exp_domain.ExplorationChange(change)
                for change in change_list_dict
            ]
        except utils.ValidationError as e:
            # We leave any pre-existing draft changes in the datastore.
            raise self.InvalidInputException(e)

        version = self.payload.get('version')
        exploration_rights = rights_manager.get_exploration_rights(
            exploration_id)
        can_edit = rights_manager.check_can_edit_activity(
            self.user, exploration_rights)
        can_voiceover = rights_manager.check_can_voiceover_activity(
            self.user, exploration_rights)

        try:
            if can_edit:
                exp_services.create_or_update_draft(exploration_id,
                                                    self.user_id, change_list,
                                                    version,
                                                    datetime.datetime.utcnow())
            elif can_voiceover:
                exp_services.create_or_update_draft(exploration_id,
                                                    self.user_id,
                                                    change_list,
                                                    version,
                                                    datetime.datetime.utcnow(),
                                                    is_by_voice_artist=True)
        except utils.ValidationError as e:
            # We leave any pre-existing draft changes in the datastore.
            raise self.InvalidInputException(e)

        exp_user_data = exp_services.get_user_exploration_data(
            self.user_id, exploration_id)
        # If the draft_change_list_id is False, have the user discard the draft
        # changes. We save the draft to the datastore even if the version is
        # invalid, so that it is available for recovery later.
        self.render_json({
            'draft_change_list_id':
            exp_user_data['draft_change_list_id'],
            'is_version_of_draft_valid':
            exp_services.is_version_of_draft_valid(exploration_id, version)
        })
示例#3
0
文件: editor.py 项目: MinhHuong/oppia
    def put(self, exploration_id):
        """Handles PUT requests for draft updation."""
        # Raise an Exception if the draft change list fails non-strict
        # validation.
        try:
            change_list = self.payload.get('change_list')
            version = self.payload.get('version')
            exp_services.create_or_update_draft(
                exploration_id, self.user_id, change_list, version,
                datetime.datetime.utcnow())
        except utils.ValidationError as e:
            # We leave any pre-existing draft changes in the datastore.
            raise self.InvalidInputException(e)

        # If the value passed here is False, have the user discard the draft
        # changes. We save the draft to the datastore even if the version is
        # invalid, so that it is available for recovery later.
        self.render_json({
            'is_version_of_draft_valid': exp_services.is_version_of_draft_valid(
                exploration_id, version)})
示例#4
0
    def put(self, exploration_id):
        """Handles PUT requests for draft updation."""
        # Raise an Exception if the draft change list fails non-strict
        # validation.
        try:
            change_list = self.payload.get('change_list')
            version = self.payload.get('version')
            exp_services.create_or_update_draft(
                exploration_id, self.user_id, change_list, version,
                datetime.datetime.utcnow())
        except utils.ValidationError as e:
            # We leave any pre-existing draft changes in the datastore.
            raise self.InvalidInputException(e)

        # If the value passed here is False, have the user discard the draft
        # changes. We save the draft to the datastore even if the version is
        # invalid, so that it is available for recovery later.
        self.render_json({
            'is_version_of_draft_valid': exp_services.is_version_of_draft_valid(
                exploration_id, version)})