本文整理汇总了Python中tracim_backend.lib.core.content.ContentApi.update_content方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.update_content方法的具体用法?Python ContentApi.update_content怎么用?Python ContentApi.update_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.update_content方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_html_document
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_content [as 别名]
def update_html_document(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext: # nopep8
"""
update_html_document
"""
app_config = request.registry.settings['CFG']
api = ContentApi(
show_archived=True,
show_deleted=True,
current_user=request.current_user,
session=request.dbsession,
config=app_config,
)
content = api.get_one(
hapic_data.path.content_id,
content_type=content_type_list.Any_SLUG
)
with new_revision(
session=request.dbsession,
tm=transaction.manager,
content=content
):
api.update_content(
item=content,
new_label=hapic_data.body.label,
new_content=hapic_data.body.raw_content,
)
api.save(content)
return api.get_content_in_context(content)
示例2: insert
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_content [as 别名]
#.........这里部分代码省略.........
label='Desserts',
do_save=True,
do_notify=False,
)
salads_folder = content_api.create(
content_type_slug=content_type_list.Folder.slug,
workspace=recipe_workspace,
label='Salads',
do_save=True,
do_notify=False,
)
other_folder = content_api.create(
content_type_slug=content_type_list.Folder.slug,
workspace=other_workspace,
label='Infos',
do_save=True,
do_notify=False,
)
# Pages, threads, ..
tiramisu_page = content_api.create(
content_type_slug=content_type_list.Page.slug,
workspace=recipe_workspace,
parent=dessert_folder,
label='Tiramisu Recipes!!!',
do_save=True,
do_notify=False,
)
with new_revision(
session=self._session,
tm=transaction.manager,
content=tiramisu_page,
):
content_api.update_content(
item=tiramisu_page,
new_content='<p>To cook a greet Tiramisu, you need many ingredients.</p>', # nopep8
new_label='Tiramisu Recipes!!!',
)
content_api.save(tiramisu_page)
best_cake_thread = content_api.create(
content_type_slug=content_type_list.Thread.slug,
workspace=recipe_workspace,
parent=dessert_folder,
label='Best Cake',
do_save=False,
do_notify=False,
)
best_cake_thread.description = 'Which is the best cake?'
self._session.add(best_cake_thread)
apple_pie_recipe = content_api.create(
content_type_slug=content_type_list.File.slug,
workspace=recipe_workspace,
parent=dessert_folder,
label='Apple_Pie',
do_save=False,
do_notify=False,
)
apple_pie_recipe.file_extension = '.txt'
apple_pie_recipe.depot_file = FileIntent(
b'Apple pie Recipe',
'apple_Pie.txt',
'text/plain',
)
self._session.add(apple_pie_recipe)
Brownie_recipe = content_api.create(
示例3: test_api__post_content_comment__ok_200__nominal_case
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_content [as 别名]
def test_api__post_content_comment__ok_200__nominal_case(self) -> None:
"""
Get alls comments of a content
"""
dbsession = get_tm_session(self.session_factory, transaction.manager)
admin = dbsession.query(User) \
.filter(User.email == '[email protected]') \
.one() # type: User
workspace_api = WorkspaceApi(
current_user=admin,
session=dbsession,
config=self.app_config
)
business_workspace = workspace_api.get_one(1)
content_api = ContentApi(
current_user=admin,
session=dbsession,
config=self.app_config
)
tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
test_thread = content_api.create(
content_type_slug=content_type_list.Thread.slug,
workspace=business_workspace,
parent=tool_folder,
label='Test Thread',
do_save=True,
do_notify=False,
)
with new_revision(
session=dbsession,
tm=transaction.manager,
content=test_thread,
):
content_api.update_content(
test_thread,
new_label='test_thread_updated',
new_content='Just a test'
)
transaction.commit()
self.testapp.authorization = (
'Basic',
(
'[email protected]',
'[email protected]'
)
)
params = {
'raw_content': 'I strongly disagree, Tiramisu win!'
}
res = self.testapp.post_json(
'/api/v2/workspaces/{}/contents/{}/comments'.format(
business_workspace.workspace_id,
test_thread.content_id
),
params=params,
status=200
)
comment = res.json_body
assert comment['content_id']
assert comment['parent_id'] == test_thread.content_id
assert comment['raw_content'] == 'I strongly disagree, Tiramisu win!'
assert comment['author']
assert comment['author']['user_id'] == admin.user_id
# TODO - G.M - 2018-06-172 - [avatar] setup avatar url
assert comment['author']['avatar_url'] is None
assert comment['author']['public_name'] == admin.display_name
# TODO - G.M - 2018-06-179 - better check for datetime
assert comment['created']
示例4: FileResource
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_content [as 别名]
#.........这里部分代码省略.........
if normpath(dirname(destpath)) == normpath(dirname(self.path)):
# INFO - G.M - 2018-12-12 - renaming case
checker = is_contributor
else:
# INFO - G.M - 2018-12-12 - move case
checker = can_move_content
try:
checker.check(self.tracim_context)
except TracimException as exc:
raise DAVError(HTTP_FORBIDDEN)
try:
with new_revision(
content=self.content,
tm=transaction.manager,
session=self.session,
):
# INFO - G.M - 2018-03-09 - First, renaming file if needed
if basename(destpath) != self.getDisplayName():
new_filename = webdav_convert_file_name_to_bdd(basename(destpath))
regex_file_extension = re.compile(
'(?P<label>.*){}'.format(
re.escape(self.content.file_extension)))
same_extension = regex_file_extension.match(new_filename)
if same_extension:
new_label = same_extension.group('label')
new_file_extension = self.content.file_extension
else:
new_label, new_file_extension = os.path.splitext(
new_filename)
self.content_api.update_content(
self.content,
new_label=new_label,
)
self.content.file_extension = new_file_extension
self.content_api.save(self.content)
# INFO - G.M - 2018-03-09 - Moving file if needed
destination_workspace = self.tracim_context.candidate_workspace
try:
destination_parent = self.tracim_context.candidate_parent_content
except ContentNotFound:
destination_parent = None
if destination_parent != parent or destination_workspace != workspace: # nopep8
# INFO - G.M - 12-03-2018 - Avoid moving the file "at the same place" # nopep8
# if the request does not result in a real move.
self.content_api.move(
item=self.content,
new_parent=destination_parent,
must_stay_in_same_workspace=False,
new_workspace=destination_workspace
)
except TracimException as exc:
raise DAVError(HTTP_FORBIDDEN) from exc
transaction.commit()
def copyMoveSingle(self, destpath, isMove):
if isMove:
# INFO - G.M - 12-03-2018 - This case should not happen
# As far as moveRecursive method exist, all move should not go
# through this method. If such case appear, try replace this to :
####
示例5: test_api__post_content_comment__err_400__content_not_editable
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_content [as 别名]
def test_api__post_content_comment__err_400__content_not_editable(self) -> None:
"""
Get alls comments of a content
"""
dbsession = get_tm_session(self.session_factory, transaction.manager)
admin = dbsession.query(User) \
.filter(User.email == '[email protected]') \
.one() # type: User
workspace_api = WorkspaceApi(
current_user=admin,
session=dbsession,
config=self.app_config
)
business_workspace = workspace_api.get_one(1)
content_api = ContentApi(
current_user=admin,
session=dbsession,
config=self.app_config
)
tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
test_thread = content_api.create(
content_type_slug=content_type_list.Thread.slug,
workspace=business_workspace,
parent=tool_folder,
label='Test Thread',
do_save=True,
do_notify=False,
)
with new_revision(
session=dbsession,
tm=transaction.manager,
content=test_thread,
):
content_api.update_content(
test_thread,
new_label='test_thread_updated',
new_content='Just a test'
)
content_api.set_status(test_thread, 'closed-deprecated')
transaction.commit()
self.testapp.authorization = (
'Basic',
(
'[email protected]',
'[email protected]'
)
)
params = {
'raw_content': 'I strongly disagree, Tiramisu win!'
}
res = self.testapp.post_json(
'/api/v2/workspaces/{}/contents/{}/comments'.format(
business_workspace.workspace_id,
test_thread.content_id
),
params=params,
status=400
)
assert res.json_body
assert 'code' in res.json_body
assert res.json_body['code'] == error.CONTENT_IN_NOT_EDITABLE_STATE