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: self._session.add(content) self.save(content, ActionDescription.CREATION) return content
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))
def delete(self, content: Content): content.owner = self._user content.is_deleted = True # TODO - G.M - 12-03-2018 - Inspect possible label conflict problem # INFO - G.M - 12-03-2018 - Set label name to avoid trouble when # un-deleting file. content.label = '{label}-{action}-{date}'.format( label=content.label, action='deleted', date=current_date_for_filename()) content.revision_type = ActionDescription.DELETION
def update_content(self, item: Content, new_label: str, new_content: str = None) -> Content: if item.label == new_label and item.description == new_content: # TODO - G.M - 20-03-2018 - Fix internatization for webdav access. # Internatization disabled in libcontent for now. 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
def update_file_data(self, item: Content, new_filename: str, new_mimetype: str, new_content: bytes) -> Content: if new_mimetype == item.file_mimetype and \ new_content == item.depot_file.file.read(): raise SameValueError('The content did not changed') 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
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
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
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. self._session.add(content) self._session.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)
def undelete(self, content: Content): content.owner = self._user content.is_deleted = False content.revision_type = ActionDescription.UNDELETION
def unarchive(self, content: Content): content.owner = self._user content.is_archived = False content.revision_type = ActionDescription.UNARCHIVING