本文整理汇总了Python中tracim.model.data.Content.get_valid_children方法的典型用法代码示例。如果您正苦于以下问题:Python Content.get_valid_children方法的具体用法?Python Content.get_valid_children怎么用?Python Content.get_valid_children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.model.data.Content
的用法示例。
在下文中一共展示了Content.get_valid_children方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mark_unread
# 需要导入模块: from tracim.model.data import Content [as 别名]
# 或者: from tracim.model.data.Content import get_valid_children [as 别名]
def mark_unread(self, content: Content, do_flush=True) -> Content:
assert self._user
assert content
revisions = DBSession.query(ContentRevisionRO) \
.filter(ContentRevisionRO.content_id==content.content_id).all()
for revision in revisions:
del revision.read_by[self._user]
for child in content.get_valid_children():
self.mark_unread(child, do_flush=False)
if do_flush:
self.flush()
return content
示例2: mark_read
# 需要导入模块: from tracim.model.data import Content [as 别名]
# 或者: from tracim.model.data.Content import get_valid_children [as 别名]
def mark_read(self, content: Content,
read_datetime: datetime=None,
do_flush: bool=True, recursive: bool=True) -> Content:
assert self._user
assert content
# The algorithm is:
# 1. define the read datetime
# 2. update all revisions related to current Content
# 3. do the same for all child revisions
# (ie parent_id is content_id of current content)
if not read_datetime:
read_datetime = datetime.datetime.now()
viewed_revisions = DBSession.query(ContentRevisionRO) \
.filter(ContentRevisionRO.content_id==content.content_id).all()
for revision in viewed_revisions:
revision.read_by[self._user] = read_datetime
if recursive:
# mark read :
# - all children
# - parent stuff (if you mark a comment as read,
# then you have seen the parent)
# - parent comments
for child in content.get_valid_children():
self.mark_read(child, read_datetime=read_datetime,
do_flush=False)
if ContentType.Comment == content.type:
self.mark_read(content.parent, read_datetime=read_datetime,
do_flush=False, recursive=False)
for comment in content.parent.get_comments():
if comment != content:
self.mark_read(comment, read_datetime=read_datetime,
do_flush=False, recursive=False)
if do_flush:
self.flush()
return content