예제 #1
0
def serialize_node_for_page(item: Content, context: Context):
    if item.type == ContentType.Thread:
        return DictLikeClass(
            content=item.description,
            created=item.created,
            icon=ContentType.get_icon(item.type),
            id=item.content_id,
            label=item.label,
            links=[],
            owner=context.toDict(item.owner),
            parent=context.toDict(item.parent),
            selected_revision='latest',
            status=context.toDict(item.get_status()),
            type=item.type,
            workspace=context.toDict(item.workspace),
            comments=reversed(context.toDict(item.get_comments())),
            is_new=item.has_new_information_for(context.get_user()),
            history=Context(CTX.CONTENT_HISTORY).toDict(item.get_history()),
            urls=context.toDict({
                'mark_read':
                context.url(
                    Content.format_path(
                        '/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_read',
                        item)),
                'mark_unread':
                context.url(
                    Content.format_path(
                        '/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_unread',
                        item))
            }),
        )

    if item.type == ContentType.Comment:
        return DictLikeClass(
            is_new=item.has_new_information_for(context.get_user()),
            content=item.description,
            created=item.created,
            created_as_delta=item.created_as_delta(),
            icon=ContentType.get_icon(item.type),
            id=item.content_id,
            label=item.label,
            owner=context.toDict(item.owner),
            # REMOVE parent = context.toDict(item.parent),
            type=item.type,
            urls=context.toDict({
                'delete':
                context.url(
                    '/workspaces/{wid}/folders/{fid}/{ctype}/{cid}/comments/{commentid}/put_delete'
                    .format(wid=item.workspace_id,
                            fid=item.parent.parent_id,
                            ctype=item.parent.type + 's',
                            cid=item.parent.content_id,
                            commentid=item.content_id))
            }))

    if item.type == ContentType.Folder:
        return Context(CTX.DEFAULT).toDict(item)
예제 #2
0
def serialize_node_for_thread(item: Content, context: Context):
    if item.type in (ContentType.Thread, ContentType.Task, ContentType.Ticket):
        return DictLikeClass(
            content = item.description,
            created = item.created,
            updated = item.last_revision.updated,
            revision_nb = len(item.revisions),
            icon = ContentType.get_icon(item.type),
            id = item.content_id,
            label = item.label,
            links=[],
            owner = context.toDict(item.owner),
            last_modification_author=context.toDict(item.last_revision.owner),
            parent = context.toDict(item.parent),
            selected_revision = 'latest',
            status = context.toDict(item.get_status()),
            type = item.type,
            workspace = context.toDict(item.workspace),
            comments = reversed(context.toDict(item.get_comments())),
            is_new=item.has_new_information_for(context.get_user()),
            history = Context(CTX.CONTENT_HISTORY).toDict(item.get_history()),
            is_editable=item.is_editable,
            is_deleted=item.is_deleted,
            is_archived=item.is_archived,
            urls = context.toDict({
                'mark_read': context.url(Content.format_path('/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_read', item)),
                'mark_unread': context.url(Content.format_path('/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_unread', item))
            }),
        )

    if item.type == ContentType.Comment:
        return DictLikeClass(
            is_new=item.has_new_information_for(context.get_user()),
            content = item.description,
            created = item.created,
            created_as_delta = item.created_as_delta(),
            icon = ContentType.get_icon(item.type),
            id = item.content_id,
            label = item.label,
            owner = context.toDict(item.owner),
            # REMOVE parent = context.toDict(item.parent),
            type = item.type,
            urls = context.toDict({
                'delete': context.url('/workspaces/{wid}/folders/{fid}/{ctype}/{cid}/comments/{commentid}/put_delete'.format(wid = item.workspace_id, fid=item.parent.parent_id, ctype=item.parent.type+'s', cid=item.parent.content_id, commentid=item.content_id))
            })
        )

    if item.type==ContentType.Folder:
        return Context(CTX.DEFAULT).toDict(item)
예제 #3
0
def serialize_node_for_thread_list(content: Content, context: Context):
    if content.type == ContentType.Thread:
        return DictLikeClass(id=content.content_id,
                             url=ContentType.fill_url(content),
                             label=content.get_label(),
                             status=context.toDict(content.get_status()),
                             folder=context.toDict(content.parent),
                             workspace=context.toDict(content.workspace)
                             if content.workspace else None,
                             comment_nb=len(content.get_comments()))

    if content.type == ContentType.Folder:
        return Context(CTX.DEFAULT).toDict(content)

    raise NotImplementedError
예제 #4
0
def serialize_node_for_thread_list(content: Content, context: Context):
    if content.type==ContentType.Thread:
        return DictLikeClass(
            id = content.content_id,
            url=ContentType.fill_url(content),
            label=content.get_label(),
            status=context.toDict(content.get_status()),
            folder=context.toDict(content.parent),
            workspace=context.toDict(content.workspace) if content.workspace else None,
            comment_nb=len(content.get_comments())
        )

    if content.type==ContentType.Folder:
        return Context(CTX.DEFAULT).toDict(content)

    raise NotImplementedError
예제 #5
0
파일: serializers.py 프로젝트: qyqx/tracim
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
예제 #6
0
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.now() - 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 = ''

    return item