当前位置: 首页>>代码示例>>Python>>正文


Python ContentApi.create_comment方法代码示例

本文整理汇总了Python中tracim.lib.content.ContentApi.create_comment方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.create_comment方法的具体用法?Python ContentApi.create_comment怎么用?Python ContentApi.create_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tracim.lib.content.ContentApi的用法示例。


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

示例1: put

# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import create_comment [as 别名]
    def put(self, item_id, file_data=None, comment=None, label=''):
        # TODO - SECURE THIS
        workspace = tmpl_context.workspace

        try:
            item_saved = False
            api = ContentApi(tmpl_context.current_user)
            item = api.get_one(int(item_id), self._item_type, workspace)

            # TODO - D.A. - 2015-03-19
            # refactor this method in order to make code easier to understand

            if comment and label:
                updated_item = api.update_content(
                    item, label if label else item.label,
                    comment if comment else ''
                )
                api.save(updated_item, ActionDescription.EDITION)

                # This case is the default "file title and description update"
                # In this case the file itself is not revisionned

            else:
                # So, now we may have a comment and/or a file revision
                if comment and ''==label:
                    comment_item = api.create_comment(workspace,
                                                      item, comment,
                                                      do_save=False)

                    if not isinstance(file_data, FieldStorage):
                        api.save(comment_item, ActionDescription.COMMENT)
                    else:
                        # The notification is only sent
                        # if the file is NOT updated
                        #
                        #  If the file is also updated,
                        #  then a 'file revision' notification will be sent.
                        api.save(comment_item,
                                 ActionDescription.COMMENT,
                                 do_notify=False)

                if isinstance(file_data, FieldStorage):
                    api.update_file_data(item, file_data.filename, file_data.type, file_data.file.read())
                    api.save(item, ActionDescription.REVISION)

            msg = _('{} updated').format(self._item_type_label)
            tg.flash(msg, CST.STATUS_OK)
            tg.redirect(self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item.content_id))

        except ValueError as e:
            msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
            tg.flash(msg, CST.STATUS_ERROR)
            tg.redirect(self._err_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item_id))
开发者ID:DarkDare,项目名称:tracim,代码行数:55,代码来源:content.py

示例2: post

# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import create_comment [as 别名]
    def post(self, content=''):
        # TODO - SECURE THIS
        workspace = tmpl_context.workspace
        thread = tmpl_context.thread


        api = ContentApi(tmpl_context.current_user)

        comment = api.create_comment(workspace, thread, content, True)

        next_url = tg.url('/workspaces/{}/folders/{}/threads/{}').format(tmpl_context.workspace_id,
                                                                              tmpl_context.folder_id,
                                                                              tmpl_context.thread_id)
        tg.flash(_('Comment added'), CST.STATUS_OK)
        tg.redirect(next_url)
开发者ID:DarkDare,项目名称:tracim,代码行数:17,代码来源:content.py

示例3: test_create_comment_ok

# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import create_comment [as 别名]
    def test_create_comment_ok(self):
        uapi = UserApi(None)
        groups = [GroupApi(None).get_one(Group.TIM_USER),
                  GroupApi(None).get_one(Group.TIM_MANAGER),
                  GroupApi(None).get_one(Group.TIM_ADMIN)]

        user = uapi.create_user(email='[email protected]',
                                groups=groups, save_now=True)

        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
        c = api.create_comment(workspace, p, 'this is the comment', True)

        eq_(Content, c.__class__)
        eq_(p.content_id, c.parent_id)
        eq_(user, c.owner)
        eq_(workspace, c.workspace)
        eq_(ContentType.Comment, c.type)
        eq_('this is the comment', c.description)
        eq_('', c.label)
        eq_(ActionDescription.COMMENT, c.revision_type)
开发者ID:buxx,项目名称:tracim,代码行数:26,代码来源:test_content_api.py


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