Ejemplo n.º 1
0
    def create(self,
               content_type: str,
               workspace: Workspace,
               parent: Content = None,
               label: str = '',
               do_save=False,
               is_temporary: bool = False) -> Content:
        assert content_type in ContentType.allowed_types()

        if content_type == ContentType.Folder and not label:
            label = self.generate_folder_label(workspace, parent)

        content = Content()
        content.owner = self._user
        content.parent = parent
        content.workspace = workspace
        content.type = content_type
        content.label = label
        content.is_temporary = is_temporary
        content.revision_type = ActionDescription.CREATION

        if content.type in (
                ContentType.Page,
                ContentType.Thread,
        ):
            content.file_extension = '.html'

        if do_save:
            DBSession.add(content)
            self.save(content, ActionDescription.CREATION)
        return content
Ejemplo n.º 2
0
 def set_status(self, content: Content, new_status: str):
     if new_status in ContentStatus.allowed_values():
         content.status = new_status
         content.revision_type = ActionDescription.STATUS_UPDATE
     else:
         raise ValueError(
             'The given value {} is not allowed'.format(new_status))
Ejemplo n.º 3
0
 def update_file_data(self, item: Content, new_filename: str, new_mimetype: str, new_file_content) -> Content:
     item.owner = self._user
     item.file_name = new_filename
     item.file_mimetype = new_mimetype
     item.file_content = new_file_content
     item.revision_type = ActionDescription.REVISION
     return item
Ejemplo n.º 4
0
    def create(self, content_type: str, workspace: Workspace, parent: Content=None, label:str ='', do_save=False, is_temporary: bool=False) -> Content:
        assert content_type in ContentType.allowed_types()

        if content_type == ContentType.Folder and not label:
            label = self.generate_folder_label(workspace, parent)

        content = Content()
        content.owner = self._user
        content.parent = parent
        content.workspace = workspace
        content.type = content_type
        content.label = label
        content.is_temporary = is_temporary
        content.revision_type = ActionDescription.CREATION

        if content.type in (
                ContentType.Page,
                ContentType.Thread,
        ):
            content.file_extension = '.html'

        if do_save:
            DBSession.add(content)
            self.save(content, ActionDescription.CREATION)
        return content
Ejemplo n.º 5
0
 def update_file_data(self, item: Content, new_filename: str,
                      new_mimetype: str, new_file_content) -> Content:
     item.owner = self._user
     item.file_name = new_filename
     item.file_mimetype = new_mimetype
     item.file_content = new_file_content
     item.revision_type = ActionDescription.REVISION
     return item
Ejemplo n.º 6
0
 def update_content(self, item: Content, new_label: str, new_content: str=None) -> Content:
     if item.label==new_label and item.description==new_content:
         raise SameValueError(_('The content did not changed'))
     item.owner = self._user
     item.label = new_label
     item.description = new_content if new_content else item.description # TODO: convert urls into links
     item.revision_type = ActionDescription.EDITION
     return item
Ejemplo n.º 7
0
 def update_file_data(self, item: Content, new_filename: str, new_mimetype: str, new_content: bytes) -> Content:
     item.owner = self._user
     item.file_name = new_filename
     item.file_mimetype = new_mimetype
     item.depot_file = FileIntent(
         new_content,
         new_filename,
         new_mimetype,
     )
     item.revision_type = ActionDescription.REVISION
     return item
Ejemplo n.º 8
0
    def create_comment(self, workspace: Workspace=None, parent: Content=None, content:str ='', do_save=False) -> Content:
        assert parent  and parent.type!=ContentType.Folder
        item = Content()
        item.owner = self._user
        item.parent = parent
        item.workspace = workspace
        item.type = ContentType.Comment
        item.description = content
        item.label = ''
        item.revision_type = ActionDescription.COMMENT

        if do_save:
            self.save(item, ActionDescription.COMMENT)
        return item
Ejemplo n.º 9
0
    def move(self, item: Content,
             new_parent: Content,
             must_stay_in_same_workspace:bool=True,
             new_workspace:Workspace=None):
        if must_stay_in_same_workspace:
            if new_parent and new_parent.workspace_id != item.workspace_id:
                raise ValueError('the item should stay in the same workspace')

        item.parent = new_parent
        if new_parent:
            item.workspace = new_parent.workspace
        elif new_workspace:
            item.workspace = new_workspace

        item.revision_type = ActionDescription.MOVE
Ejemplo n.º 10
0
    def save(self,
             content: Content,
             action_description: str = None,
             do_flush=True,
             do_notify=True):
        """
        Save an object, flush the session and set the revision_type property
        :param content:
        :param action_description:
        :return:
        """
        assert action_description is None or action_description in ActionDescription.allowed_values(
        )

        if not action_description:
            # See if the last action has been modified
            if content.revision_type == None or len(
                    get_history(content.revision, 'revision_type')) <= 0:
                # The action has not been modified, so we set it to default edition
                action_description = ActionDescription.EDITION

        if action_description:
            content.revision_type = action_description

        if do_flush:
            # INFO - 2015-09-03 - D.A.
            # There are 2 flush because of the use
            # of triggers for content creation
            #
            # (when creating a content, actually this is an insert of a new
            # revision in content_revisions ; so the mark_read operation need
            # to get full real data from database before to be prepared.

            DBSession.add(content)
            DBSession.flush()

            # TODO - 2015-09-03 - D.A. - Do not use triggers
            # We should create a new ContentRevisionRO object instead of Content
            # This would help managing view/not viewed status
            self.mark_read(content, do_flush=True)

        if do_notify:
            self.do_notify(content)
Ejemplo n.º 11
0
    def create(self,
               content_type: str,
               workspace: Workspace,
               parent: Content = None,
               label: str = '',
               is_temporary: bool = False,
               do_save=False) -> Content:
        assert content_type in ContentType.allowed_types()
        content = Content()
        content.owner = self._user
        content.parent = parent
        content.workspace = workspace
        content.type = content_type
        content.label = label
        content.is_temporary = is_temporary
        content.revision_type = ActionDescription.CREATION

        if do_save:
            DBSession.add(content)
            self.save(content, ActionDescription.CREATION)
        return content
Ejemplo n.º 12
0
 def undelete(self, content: Content):
     content.owner = self._user
     content.is_deleted = False
     content.revision_type = ActionDescription.UNDELETION
Ejemplo n.º 13
0
 def delete(self, content: Content):
     content.owner = self._user
     content.is_deleted = True
     content.revision_type = ActionDescription.DELETION
Ejemplo n.º 14
0
 def unarchive(self, content: Content):
     content.owner = self._user
     content.is_archived = False
     content.revision_type = ActionDescription.UNARCHIVING
Ejemplo n.º 15
0
 def archive(self, content: Content):
     content.owner = self._user
     content.is_archived = True
     content.revision_type = ActionDescription.ARCHIVING