• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python data.Content类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tracim.model.data.Content的典型用法代码示例。如果您正苦于以下问题:Python Content类的具体用法?Python Content怎么用?Python Content使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Content类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: compare_content_for_sorting_by_type_and_name

def compare_content_for_sorting_by_type_and_name(content1: Content,
                                                 content2: Content):
    """
    :param content1:
    :param content2:
    :return:    1 if content1 > content2
                -1 if content1 < content2
                0 if content1 = content2
    """

    if content1.type==content2.type:
        if content1.get_label().lower()>content2.get_label().lower():
            return 1
        elif content1.get_label().lower()<content2.get_label().lower():
            return -1
        return 0
    else:
        # TODO - D.A. - 2014-12-02 - Manage Content Types Dynamically
        content_type_order = [ContentType.Folder, ContentType.Page, ContentType.Thread, ContentType.File]
        result = content_type_order.index(content1.type)-content_type_order.index(content2.type)
        if result<0:
            return -1
        elif result>0:
            return 1
        else:
            return 0
开发者ID:buxx,项目名称:tracim,代码行数:26,代码来源:content.py


示例2: test_serializer_content__menui_api_context__children

    def test_serializer_content__menui_api_context__children(self):
        folder_without_child = Content()
        folder_without_child.type = ContentType.Folder
        res = Context(CTX.MENU_API).toDict(folder_without_child)
        eq_(False, res['children'])

        folder_with_child = Content()
        folder_with_child.type = ContentType.Folder
        folder_without_child.parent = folder_with_child
        DBSession.add(folder_with_child)
        DBSession.add(folder_without_child)
        DBSession.flush()

        res = Context(CTX.MENU_API).toDict(folder_with_child)
        eq_(True, res['children'])

        for curtype in ContentType.all():
            if curtype not in (ContentType.Folder, ContentType.Comment):
                item = Content()
                item.type = curtype

                fake_child = Content()
                fake_child.type = curtype
                fake_child.parent = item

                DBSession.add(item)
                DBSession.add(fake_child)
                DBSession.flush()

                res = Context(CTX.MENU_API).toDict(item)
                eq_(False, res['children'])
开发者ID:DarkDare,项目名称:tracim,代码行数:31,代码来源:test_serializers.py


示例3: serialize_content_for_general_list

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})
    )
开发者ID:lebouquetin,项目名称:tracim,代码行数:27,代码来源:serializers.py


示例4: update_file_data

 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
开发者ID:buxx,项目名称:tracim,代码行数:7,代码来源:content.py


示例5: serialize_node_for_page_list

def serialize_node_for_page_list(content: Content, context: Context):

    if content.type==ContentType.Page:
        if not content.parent:
            folder = None
        else:
            folder = Context(CTX.DEFAULT).toDict(content.parent)

        result = DictLikeClass(
            id = content.content_id,
            label = content.label,
            status = context.toDict(content.get_status()),
            folder = folder
        )
        return result

    if content.type==ContentType.File:
        result = DictLikeClass(
            id = content.content_id,
            label = content.label if content.label else content.file_name,
            status = context.toDict(content.get_status()),
            folder = Context(CTX.DEFAULT).toDict(content.parent)
        )
        return result


    # TODO - DA - 2014-10-16 - THE FOLLOWING CODE SHOULD BE REMOVED
    #
    # if content.type==ContentType.Folder:
    #     return DictLikeClass(
    #         id = content.content_id,
    #         label = content.label,
    #     )

    raise NotImplementedError('node type / context not implemented: {} {}'. format(content.type, context.context_string))
开发者ID:DarkDare,项目名称:tracim,代码行数:35,代码来源:serializers.py


示例6: update_content

 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
开发者ID:buxx,项目名称:tracim,代码行数:8,代码来源:content.py


示例7: serialize_node_for_page

def serialize_node_for_page(content: Content, context: Context):

    if content.type in (ContentType.Page, ContentType.File) :
        data_container = content

        # The following properties are overriden by revision values
        if content.revision_to_serialize>0:
            for revision in content.revisions:
                if revision.revision_id==content.revision_to_serialize:
                    data_container = revision
                    break

        result = DictLikeClass(
            id=content.content_id,
            parent=context.toDict(content.parent),
            workspace=context.toDict(content.workspace),
            type=content.type,
            is_new=content.has_new_information_for(context.get_user()),
            content=data_container.description,
            created=data_container.created,
            updated=content.last_revision.updated,
            label=data_container.label,
            icon=ContentType.get_icon(content.type),
            owner=context.toDict(content.first_revision.owner),
            last_modification_author=context.toDict(content.last_revision.owner),
            status=context.toDict(data_container.get_status()),
            links=[],
            revision_nb = len(content.revisions),
            selected_revision='latest' if content.revision_to_serialize<=0 else content.revision_to_serialize,
            history=Context(CTX.CONTENT_HISTORY).toDict(content.get_history()),
            is_editable=content.is_editable,
            is_deleted=content.is_deleted,
            is_archived=content.is_archived,
            urls = context.toDict({
                'mark_read': context.url(Content.format_path('/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_read', content)),
                'mark_unread': context.url(Content.format_path('/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_unread', content))
            })
        )

        if content.type == ContentType.File:
            depot = DepotManager.get()
            depot_stored_file = depot.get(data_container.depot_file)
            result.label = content.label
            result['file'] = DictLikeClass(
                name=data_container.file_name,
                size=depot_stored_file.content_length,
                mimetype=data_container.file_mimetype)
        return result

    if content.type==ContentType.Folder:
        value = DictLikeClass(
            id=content.content_id,
            label=content.label,
            is_new=content.has_new_information_for(context.get_user()),
        )
        return value

    raise NotImplementedError
开发者ID:lebouquetin,项目名称:tracim,代码行数:58,代码来源:serializers.py


示例8: create

    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
开发者ID:lebouquetin,项目名称:tracim,代码行数:25,代码来源:content.py


示例9: update_file_data

 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
开发者ID:lebouquetin,项目名称:tracim,代码行数:11,代码来源:content.py


示例10: new_revision

def new_revision(content: Content) -> Content:
    """
    Prepare context to update a Content. It will add a new updatable revision to the content.
    :param content: Content instance to update
    :return:
    """
    with DBSession.no_autoflush:
        try:
            if inspect(content.revision).has_identity:
                content.new_revision()
            RevisionsIntegrity.add_to_updatable(content.revision)
            yield content
        finally:
            RevisionsIntegrity.remove_from_updatable(content.revision)
开发者ID:Nonolost,项目名称:tracim,代码行数:14,代码来源:__init__.py


示例11: move

    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
开发者ID:buxx,项目名称:tracim,代码行数:15,代码来源:content.py


示例12: serialize_node_for_thread_list

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
开发者ID:DarkDare,项目名称:tracim,代码行数:16,代码来源:serializers.py


示例13: serialize_content_for_workspace

def serialize_content_for_workspace(content: Content, context: Context):
    thread_nb_all  = content.get_child_nb(ContentType.Thread)
    thread_nb_open = content.get_child_nb(ContentType.Thread)
    file_nb_all  = content.get_child_nb(ContentType.File)
    file_nb_open = content.get_child_nb(ContentType.File)
    folder_nb_all  = content.get_child_nb(ContentType.Folder)
    folder_nb_open = content.get_child_nb(ContentType.Folder)
    page_nb_all  = content.get_child_nb(ContentType.Page)
    page_nb_open = content.get_child_nb(ContentType.Page)

    content_nb_all = thread_nb_all +\
                     thread_nb_open +\
                     file_nb_all +\
                     file_nb_open +\
                     folder_nb_all +\
                     folder_nb_open +\
                     page_nb_all +\
                     page_nb_open


    result = None
    if content.type==ContentType.Folder:
        result = DictLikeClass(
            id = content.content_id,
            label = content.label,
            thread_nb = DictLikeClass(
                all = thread_nb_all,
                open = thread_nb_open,
            ),
            file_nb = DictLikeClass(
                all = file_nb_all,
                open = file_nb_open,
            ),
            folder_nb = DictLikeClass(
                all = folder_nb_all,
                open = folder_nb_open,
            ),
            page_nb = DictLikeClass(
                all = page_nb_all,
                open = page_nb_open,
            ),
            content_nb = DictLikeClass(all = content_nb_all)
        )

    return result
开发者ID:DarkDare,项目名称:tracim,代码行数:45,代码来源:serializers.py


示例14: serialize_item

def serialize_item(content: Content, context: Context):
    if ContentType.Comment==content.type:
        content = content.parent

    result = DictLikeClass(
        id = content.content_id,
        label = content.label if content.label else content.file_name,
        icon = ContentType.get_icon(content.type),
        status = context.toDict(content.get_status()),
        folder = context.toDict(DictLikeClass(id = content.parent.content_id if content.parent else None)),
        workspace = context.toDict(content.workspace),
        is_deleted = content.is_deleted,
        is_archived = content.is_archived,
        url = context.url('/workspaces/{wid}/folders/{fid}/{ctype}/{cid}'.format(wid = content.workspace_id, fid=content.parent_id, ctype=content.type+'s', cid=content.content_id)),
        last_action = context.toDict(content.get_last_action())
    )

    return result
开发者ID:DarkDare,项目名称:tracim,代码行数:18,代码来源:serializers.py


示例15: serialize_content_for_menu_api

def serialize_content_for_menu_api(content: Content, context: Context):
    content_id = content.content_id
    workspace_id = content.workspace_id

    has_children = False
    if content.type == ContentType.Folder:
        has_children = content.get_child_nb(ContentType.Any) > 0

    result = DictLikeClass(
        id = CST.TREEVIEW_MENU.ID_TEMPLATE__FULL.format(workspace_id, content_id),
        children = has_children,
        text = content.get_label(),
        a_attr = { 'href' : context.url(ContentType.fill_url(content))},
        li_attr = { 'title': content.get_label(), 'class': 'tracim-tree-item-is-a-folder' },
        type = content.type,
        state = { 'opened': True if ContentType.Folder!=content.type else False, 'selected': False }
    )
    return result
开发者ID:DarkDare,项目名称:tracim,代码行数:18,代码来源:serializers.py


示例16: test_sort_by_label_or_filename

    def test_sort_by_label_or_filename(self):
        c1 = Content()
        c1.label = 'ABCD'
        c1.type = 'file'

        c2 = Content()
        c2.label = ''
        c2.type = 'file'
        c2.file_name = 'AABC'

        c3 = Content()
        c3.label = 'BCDE'
        c3.type = 'file'

        items = [c1, c2, c3]
        sorteds = ContentApi.sort_content(items)

        eq_(sorteds[0], c2)
        eq_(sorteds[1], c1)
        eq_(sorteds[2], c3)
开发者ID:buxx,项目名称:tracim,代码行数:20,代码来源:test_content_api.py


示例17: validate_new_content

 def validate_new_content(self, content: Content) -> bool:
     """
     :param content: Content with label to test
     :return: True if content label is not in conflict with existing
     resource
     """
     return self.content_label_is_free(
         content_label_as_file=content.get_label_as_file(),
         workspace=content.workspace,
         parent=content.parent,
         exclude_content_id=content.content_id,
     )
开发者ID:buxx,项目名称:tracim,代码行数:12,代码来源:integrity.py


示例18: test_serialize_Content_DEFAULT

    def test_serialize_Content_DEFAULT(self):
        self.app.get('/_test_vars')  # Allow to create fake context

        obj = Content()
        obj.content_id = 132
        obj.label = 'Some label'
        obj.description = 'Some Description'

        res = Context(CTX.DEFAULT).toDict(obj)
        eq_(res.__class__, DictLikeClass, res)
        eq_(obj.content_id, res.id, res)
        eq_(obj.label, res.label, res)

        ok_('folder' in res.keys())
        ok_('id' in res.folder.keys())
        eq_(None, res.folder.id)
        eq_(1, len(res.folder.keys()))

        ok_('workspace' in res.keys())
        eq_(None, res.workspace, res)
        eq_(4, len(res.keys()), res)
开发者ID:Nonolost,项目名称:tracim,代码行数:21,代码来源:test_serializers.py


示例19: create_comment

    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
开发者ID:buxx,项目名称:tracim,代码行数:14,代码来源:content.py


示例20: serialize_content_for_workspace_and_folder

def serialize_content_for_workspace_and_folder(content: Content, context: Context):
    thread_nb_all  = content.get_child_nb(ContentType.Thread)
    thread_nb_open = content.get_child_nb(ContentType.Thread)
    file_nb_all  = content.get_child_nb(ContentType.File)
    file_nb_open = content.get_child_nb(ContentType.File)
    folder_nb_all  = content.get_child_nb(ContentType.Folder)
    folder_nb_open = content.get_child_nb(ContentType.Folder)
    page_nb_all  = content.get_child_nb(ContentType.Page)
    page_nb_open = content.get_child_nb(ContentType.Page)

    content_nb_all = thread_nb_all +\
                     thread_nb_open +\
                     file_nb_all +\
                     file_nb_open +\
                     folder_nb_all +\
                     folder_nb_open +\
                     page_nb_all +\
                     page_nb_open


    result = None
    if content.type==ContentType.Folder:
        allowed_content = DictLikeClass(content.properties['allowed_content']),

        result = DictLikeClass(
            id=content.content_id,
            label=content.label,
            created=content.created,
            workspace=context.toDict(content.workspace),
            allowed_content=DictLikeClass(content.properties['allowed_content']),
            allowed_content_types=context.toDict(content.get_allowed_content_types()),
            selected_revision='latest',
            status=context.toDict(content.get_status()),
            owner=context.toDict(content.owner),
            thread_nb=DictLikeClass(all=thread_nb_all,
                                    open=thread_nb_open),
            file_nb=DictLikeClass(all=file_nb_all,
                                  open=file_nb_open),
            folder_nb=DictLikeClass(all=folder_nb_all,
                                    open=folder_nb_open),
            page_nb=DictLikeClass(all=page_nb_all,
                                  open=page_nb_open),
            content_nb=DictLikeClass(all = content_nb_all)
        )

    elif content.type==ContentType.Page:
        result = DictLikeClass(
            id = content.content_id,
            label = content.label,
            created = content.created,
            workspace = context.toDict(content.workspace),
            owner = DictLikeClass(
                id = content.owner.user_id,
                name = content.owner.get_display_name()
            ),
            status = DictLikeClass(id='', label=''), #FIXME - EXPORT DATA
        )

    return result
开发者ID:DarkDare,项目名称:tracim,代码行数:59,代码来源:serializers.py



注:本文中的tracim.model.data.Content类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python content.ContentApi类代码示例发布时间:2022-05-27
下一篇:
Python model.DBSession类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap