def get_all_types(self) -> [ContentType]: labels = ContentType.all() content_types = [] for label in labels: content_types.append(ContentType(label)) return ContentType.sorted(content_types)
def serialize_content_for_general_list(content: Content, context: Context): content_type = ContentType(content.type) last_activity_date = content.get_last_activity_date() last_activity_date_formatted = format_datetime(last_activity_date, locale=tg.i18n.get_lang()[0]) last_activity_label = format_timedelta( datetime.utcnow() - last_activity_date, locale=tg.i18n.get_lang()[0], ) last_activity_label = last_activity_label.replace(' ', '\u00A0') # espace insécable return DictLikeClass( id=content.content_id, folder = DictLikeClass({'id': content.parent_id}) if content.parent else None, workspace=context.toDict(content.workspace) if content.workspace else None, label=content.get_label(), url=ContentType.fill_url(content), type=DictLikeClass(content_type.toDict()), status=context.toDict(content.get_status()), is_deleted=content.is_deleted, is_archived=content.is_archived, is_editable=content.is_editable, last_activity = DictLikeClass({'date': last_activity_date, 'label': last_activity_date_formatted, 'delta': last_activity_label}) )
def serialize_it(): nonlocal content if content.type == ContentType.Comment: logger.info( 'serialize_content_for_search_result', 'Serializing parent class {} instead of {} [content #{}]'. format(content.parent.type, content.type, content.content_id)) content = content.parent data_container = content if content.revision_to_serialize > 0: for revision in content.revisions: if revision.revision_id == content.revision_to_serialize: data_container = revision break # FIXME - D.A. - 2015-02-23 - This import should not be there... from tracim.lib.content import ContentApi breadcrumbs = ContentApi(None).build_breadcrumb( data_container.workspace, data_container.content_id, skip_root=True) last_comment_datetime = data_container.updated comments = data_container.get_comments() if comments: last_comment_datetime = max( last_comment_datetime, max(comment.updated for comment in comments)) content_type = ContentType(content.type) result = DictLikeClass( id=content.content_id, type=DictLikeClass(content_type.toDict()), parent=context.toDict(content.parent), workspace=context.toDict(content.workspace), content=data_container.description, content_raw=data_container.description_as_raw_text(), created=data_container.created, created_as_delta=data_container.created_as_delta(), label=data_container.label, icon=ContentType.get_icon(content.type), owner=context.toDict(data_container.owner), status=context.toDict(data_container.get_status()), breadcrumb=context.toDict(breadcrumbs), last_activity=last_comment_datetime, last_activity_as_delta=content.datetime_as_delta( last_comment_datetime)) if content.type == ContentType.File: result.label = content.label.__str__() if not result.label or '' == result.label: result.label = 'No title' return result
def serialize_content_for_folder_content_list(content: Content, context: Context): content_type = ContentType(content.type) last_activity_date = content.get_last_activity_date() last_activity_date_formatted = format_datetime(last_activity_date, locale=tg.i18n.get_lang()[0]) last_activity_label = format_timedelta(datetime.utcnow() - last_activity_date, locale=tg.i18n.get_lang()[0]) last_activity_label = last_activity_label.replace(' ', '\u00A0') # espace insécable item = None if ContentType.Thread == content.type: item = Context(CTX.THREADS).toDict(content) item.type = context.toDict(content_type) item.folder = DictLikeClass({'id': content.parent_id}) if content.parent else None item.workspace = DictLikeClass({'id': content.workspace.workspace_id}) if content.workspace else None item.last_activity = DictLikeClass({'date': last_activity_date, 'label': last_activity_date_formatted, 'delta': last_activity_label}) comments = content.get_comments() if len(comments)>1: item.notes = _('{nb} messages').format(nb=len(comments)) else: item.notes = _('1 message') elif ContentType.File == content.type: item = Context(CTX.CONTENT_LIST).toDict(content) if len(content.revisions)>1: item.notes = _('{nb} revisions').format(nb=len(content.revisions)) else: item.notes = _('1 revision') elif ContentType.Folder == content.type: item = Context(CTX.CONTENT_LIST).toDict(content) item.notes = '' folder_nb = content.get_child_nb(ContentType.Folder) if folder_nb == 1: item.notes += _('1 subfolder<br/>\n') elif folder_nb > 1: item.notes += _('{} subfolders<br/>').format(folder_nb) file_nb = content.get_child_nb(ContentType.File, ContentStatus.OPEN) if file_nb == 1: item.notes += _('1 open file<br/>\n') elif file_nb > 1: item.notes += _('{} open files<br/>').format(file_nb) thread_nb = content.get_child_nb(ContentType.Thread, ContentStatus.OPEN) if thread_nb == 1: item.notes += _('1 open thread<br/>\n') elif thread_nb > 1: item.notes += _('{} open threads<br/>').format(thread_nb) page_nb = content.get_child_nb(ContentType.Page, ContentStatus.OPEN) if page_nb == 1: item.notes += _('1 open page<br/>\n') elif page_nb > 1: item.notes += _('{} open pages<br/>').format(page_nb) else: item = Context(CTX.CONTENT_LIST).toDict(content) item.notes = '' item.is_deleted = content.is_deleted item.is_archived = content.is_archived item.is_editable = content.is_editable return item