本文整理汇总了Python中tracim.model.data.Content类的典型用法代码示例。如果您正苦于以下问题:Python Content类的具体用法?Python Content怎么用?Python Content使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Content类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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'])
示例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})
)
示例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
示例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))
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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