本文整理汇总了Python中tracim_backend.lib.core.content.ContentApi.create方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.create方法的具体用法?Python ContentApi.create怎么用?Python ContentApi.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_func__create_new_content_with_notification__ok__nominal_case
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import create [as 别名]
def test_func__create_new_content_with_notification__ok__nominal_case(self):
uapi = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
current_user = uapi.get_one_by_email('[email protected]')
# Create new user with notification enabled on w1 workspace
wapi = WorkspaceApi(
current_user=current_user,
session=self.session,
config=self.app_config,
)
workspace = wapi.get_one_by_label('Recipes')
user = uapi.get_one_by_email('[email protected]')
wapi.enable_notifications(user, workspace)
api = ContentApi(
current_user=user,
session=self.session,
config=self.app_config,
)
item = api.create(
content_type_list.Folder.slug,
workspace,
None,
'parent',
do_save=True,
do_notify=False,
)
item2 = api.create(
content_type_list.File.slug,
workspace,
item,
'file1',
do_save=True,
do_notify=True,
)
# Send mail async from redis queue
redis = get_redis_connection(
self.app_config
)
queue = get_rq_queue(
redis,
'mail_sender',
)
worker = SimpleWorker([queue], connection=queue.connection)
worker.work(burst=True)
# check mail received
response = self.get_mailhog_mails()
headers = response[0]['Content']['Headers']
assert headers['From'][0] == '"Bob i. via Tracim" <[email protected]>' # nopep8
assert headers['To'][0] == 'Global manager <[email protected]>'
assert headers['Subject'][0] == '[TRACIM] [Recipes] file1 (Open)'
assert headers['References'][0] == '[email protected]'
assert headers['Reply-to'][0] == '"Bob i. & all members of Recipes" <[email protected]>' # nopep8
示例2: test_func__create_comment_with_notification__ok__nominal_case
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import create [as 别名]
def test_func__create_comment_with_notification__ok__nominal_case(self):
uapi = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
current_user = uapi.get_one_by_email('[email protected]')
# set admin as french, useful to verify if i18n work properly
current_user.lang = 'fr'
# Create new user with notification enabled on w1 workspace
wapi = WorkspaceApi(
current_user=current_user,
session=self.session,
config=self.app_config,
)
workspace = wapi.get_one_by_label('Recipes')
user = uapi.get_one_by_email('[email protected]')
wapi.enable_notifications(user, workspace)
api = ContentApi(
current_user=user,
session=self.session,
config=self.app_config,
)
item = api.create(
content_type_list.Folder.slug,
workspace,
None,
'parent',
do_save=True,
do_notify=False,
)
item2 = api.create(
content_type_list.File.slug,
workspace,
item,
'file1',
do_save=True,
do_notify=False,
)
api.create_comment(parent=item2, content='My super comment', do_save=True, do_notify=True)
transaction.commit()
# check mail received
response = self.get_mailhog_mails()
headers = response[0]['Content']['Headers']
assert headers['From'][0] == '"Bob i. via Tracim" <[email protected]>' # nopep8
assert headers['To'][0] == 'Global manager <[email protected]>'
assert headers['Subject'][0] == '[TRACIM] [Recipes] file1 (Open)'
assert headers['References'][0] == '[email protected]'
assert headers['Reply-to'][0] == '"Bob i. & all members of Recipes" <[email protected]>' # nopep8
示例3: create_file
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import create [as 别名]
def create_file(self, context, request: TracimRequest, hapic_data=None):
"""
Create a file .This will create 2 new revision.
"""
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,
)
_file = hapic_data.files.files
parent_id = hapic_data.forms.parent_id
api = ContentApi(
current_user=request.current_user,
session=request.dbsession,
config=app_config
)
parent = None # type: typing.Optional['Content']
if parent_id:
try:
parent = api.get_one(content_id=parent_id, content_type=content_type_list.Any_SLUG) # nopep8
except ContentNotFound as exc:
raise ParentNotFound(
'Parent with content_id {} not found'.format(parent_id)
) from exc
content = api.create(
filename=_file.filename,
content_type_slug=FILE_TYPE,
workspace=request.current_workspace,
parent=parent,
)
api.save(content, ActionDescription.CREATION)
with new_revision(
session=request.dbsession,
tm=transaction.manager,
content=content
):
api.update_file_data(
content,
new_filename=_file.filename,
new_mimetype=_file.type,
new_content=_file.file,
)
return api.get_content_in_context(content)
示例4: create_generic_empty_content
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import create [as 别名]
def create_generic_empty_content(
self,
context,
request: TracimRequest,
hapic_data=None,
) -> ContentInContext:
"""
Creates a generic empty content. The minimum viable content has a label and a content type.
Creating a content generally starts with a request to this endpoint.
For specific contents like files, it is recommended to use the dedicated endpoint.
This feature is accessible to contributors and higher role only.
"""
app_config = request.registry.settings['CFG']
creation_data = hapic_data.body
api = ContentApi(
current_user=request.current_user,
session=request.dbsession,
config=app_config
)
parent = None
if creation_data.parent_id:
try:
parent = api.get_one(content_id=creation_data.parent_id, content_type=content_type_list.Any_SLUG) # nopep8
except ContentNotFound as exc:
raise ParentNotFound(
'Parent with content_id {} not found'.format(creation_data.parent_id)
) from exc
content = api.create(
label=creation_data.label,
content_type_slug=creation_data.content_type,
workspace=request.current_workspace,
parent=parent,
)
api.save(content, ActionDescription.CREATION)
content = api.get_content_in_context(content)
return content
示例5: insert
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import create [as 别名]
def insert(self):
admin = self._session.query(User) \
.filter(User.email == '[email protected]') \
.one()
bob = self._session.query(User) \
.filter(User.email == '[email protected]') \
.one()
john_the_reader = self._session.query(User) \
.filter(User.email == '[email protected]') \
.one()
admin_workspace_api = WorkspaceApi(
current_user=admin,
session=self._session,
config=self._config,
)
bob_workspace_api = WorkspaceApi(
current_user=bob,
session=self._session,
config=self._config
)
content_api = ContentApi(
current_user=admin,
session=self._session,
config=self._config
)
bob_content_api = ContentApi(
current_user=bob,
session=self._session,
config=self._config
)
reader_content_api = ContentApi(
current_user=john_the_reader,
session=self._session,
config=self._config
)
role_api = RoleApi(
current_user=admin,
session=self._session,
config=self._config,
)
# Workspaces
business_workspace = admin_workspace_api.create_workspace(
'Business',
description='All importants documents',
save_now=True,
)
recipe_workspace = admin_workspace_api.create_workspace(
'Recipes',
description='Our best recipes',
save_now=True,
)
other_workspace = bob_workspace_api.create_workspace(
'Others',
description='Other Workspace',
save_now=True,
)
# Workspaces roles
role_api.create_one(
user=bob,
workspace=recipe_workspace,
role_level=UserRoleInWorkspace.CONTENT_MANAGER,
with_notif=False,
)
role_api.create_one(
user=john_the_reader,
workspace=recipe_workspace,
role_level=UserRoleInWorkspace.READER,
with_notif=False,
)
# Folders
tool_workspace = content_api.create(
content_type_slug=content_type_list.Folder.slug,
workspace=business_workspace,
label='Tools',
do_save=True,
do_notify=False,
)
menu_workspace = content_api.create(
content_type_slug=content_type_list.Folder.slug,
workspace=business_workspace,
label='Menus',
do_save=True,
do_notify=False,
)
dessert_folder = content_api.create(
content_type_slug=content_type_list.Folder.slug,
workspace=recipe_workspace,
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',
#.........这里部分代码省略.........
示例6: WorkspaceResource
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import create [as 别名]
class WorkspaceResource(DAVCollection):
"""
Workspace resource corresponding to tracim's workspaces.
Direct children can only be folders, though files might come later on and are supported
"""
def __init__(self,
path: str,
environ: dict,
workspace: Workspace,
tracim_context: 'WebdavTracimContext'
) -> None:
super(WorkspaceResource, self).__init__(path, environ)
self.workspace = workspace
self.content = None
self.tracim_context = tracim_context
self.user = tracim_context.current_user
self.session = tracim_context.dbsession
self.content_api = ContentApi(
current_user=self.user,
session=tracim_context.dbsession,
config=tracim_context.app_config,
show_temporary=True
)
self._file_count = 0
def __repr__(self) -> str:
return "<DAVCollection: Workspace (%d)>" % self.workspace.workspace_id
def getPreferredPath(self):
return self.path
def getCreationDate(self) -> float:
return mktime(self.workspace.created.timetuple())
def getDisplayName(self) -> str:
return webdav_convert_file_name_to_display(self.workspace.label)
def getDisplayInfo(self):
return {
'type': "workspace".capitalize(),
}
def getLastModified(self) -> float:
return mktime(self.workspace.updated.timetuple())
def getMemberNames(self) -> [str]:
retlist = []
children = self.content_api.get_all(
parent_ids=[self.content.id] if self.content is not None else None,
workspace=self.workspace
)
for content in children:
# the purpose is to display .history only if there's at least one content's type that has a history
if content.type != content_type_list.Folder.slug:
self._file_count += 1
retlist.append(webdav_convert_file_name_to_display(content.file_name))
return retlist
def getMember(self, content_label: str) -> _DAVResource:
return self.provider.getResourceInst(
'%s/%s' % (self.path, webdav_convert_file_name_to_display(content_label)),
self.environ
)
@webdav_check_right(is_contributor)
def createEmptyResource(self, file_name: str):
"""
[For now] we don't allow to create files right under workspaces.
Though if we come to allow it, deleting the error's raise will make it possible.
"""
# TODO : remove commentary here raise DAVError(HTTP_FORBIDDEN)
if '/.deleted/' in self.path or '/.archived/' in self.path:
raise DAVError(HTTP_FORBIDDEN)
content = None
# Note: To prevent bugs, check here again if resource already exist
# fixed path
fixed_file_name = webdav_convert_file_name_to_display(file_name)
path = os.path.join(self.path, file_name)
resource = self.provider.getResourceInst(path, self.environ)
if resource:
content = resource.content
# return item
return FakeFileStream(
session=self.session,
file_name=fixed_file_name,
content_api=self.content_api,
workspace=self.workspace,
content=content,
parent=self.content,
#.........这里部分代码省略.........
示例7: 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 create [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']
示例8: 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 create [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