本文整理汇总了Python中r2.lib.wrapped.Wrapped.focal方法的典型用法代码示例。如果您正苦于以下问题:Python Wrapped.focal方法的具体用法?Python Wrapped.focal怎么用?Python Wrapped.focal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.lib.wrapped.Wrapped
的用法示例。
在下文中一共展示了Wrapped.focal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_items
# 需要导入模块: from r2.lib.wrapped import Wrapped [as 别名]
# 或者: from r2.lib.wrapped.Wrapped import focal [as 别名]
def get_items(self):
tree = self.get_tree()
prev_item = next_item = None
if not self.parent:
if self.num is not None:
if self.after:
if self.reverse:
tree = filter(
self._tree_filter_reverse,
tree)
next_item = self.after._id
if len(tree) > self.num:
first = tree[-(self.num+1)]
prev_item = first[1][-1] if first[1] else first[0]
tree = tree[-self.num:]
else:
prev_item = self.after._id
tree = filter(
self._tree_filter,
tree)
if len(tree) > self.num:
tree = tree[:self.num]
last = tree[-1]
next_item = last[1][-1] if last[1] else last[0]
# generate the set of ids to look up and look them up
message_ids = []
for root, thread in tree:
message_ids.append(root)
message_ids.extend(thread)
if prev_item:
message_ids.append(prev_item)
messages = Message._byID(message_ids, data = True, return_dict = False)
wrapped = {}
for m in self.wrap_items(messages):
if not self._viewable_message(m):
g.log.warning("%r is not viewable by %s; path is %s" %
(m, c.user.name, request.fullpath))
continue
wrapped[m._id] = m
if prev_item:
prev_item = wrapped[prev_item]
if next_item:
next_item = wrapped[next_item]
final = []
for parent, children in tree:
if parent not in wrapped:
continue
parent = wrapped[parent]
if children:
# if no parent is specified, check if any of the messages are
# uncollapsed, and truncate the thread
children = [wrapped[child] for child in children
if child in wrapped]
parent.child = empty_listing()
# if the parent is new, uncollapsed, or focal we don't
# want it to become a moremessages wrapper.
if (self.skip and
not self.parent and not parent.new and parent.is_collapsed
and not (self.focal and self.focal._id == parent._id)):
for i, child in enumerate(children):
if (child.new or not child.is_collapsed or
(self.focal and self.focal._id == child._id)):
break
else:
i = -1
parent = Wrapped(MoreMessages(parent, empty_listing()))
children = children[i:]
parent.child.parent_name = parent._fullname
parent.child.things = []
for child in children:
child.is_child = True
if self.focal and child._id == self.focal._id:
# focal message is never collapsed
child.collapsed = False
child.focal = True
else:
child.collapsed = child.is_collapsed
parent.child.things.append(child)
parent.is_parent = True
# the parent might be the focal message on a permalink page
if self.focal and parent._id == self.focal._id:
parent.collapsed = False
parent.focal = True
else:
parent.collapsed = parent.is_collapsed
final.append(parent)
return (final, prev_item, next_item, len(final), len(final))
示例2: get_items
# 需要导入模块: from r2.lib.wrapped import Wrapped [as 别名]
# 或者: from r2.lib.wrapped.Wrapped import focal [as 别名]
def get_items(self):
tree = self.get_tree()
prev = next = None
if not self.parent:
if self.num is not None:
if self.after:
if self.reverse:
tree = filter(
lambda x: tree_sort_fn(x) >= self.after._id, tree)
next = self.after._id
if len(tree) > self.num:
prev = tree[-(self.num+1)][0]
tree = tree[-self.num:]
else:
prev = self.after._id
tree = filter(
lambda x: tree_sort_fn(x) < self.after._id, tree)
if len(tree) > self.num:
tree = tree[:self.num]
next = tree[-1][0]
# generate the set of ids to look up and look them up
message_ids = []
for root, thread in tree:
message_ids.append(root)
message_ids.extend(thread)
if prev:
message_ids.append(prev)
messages = Message._byID(message_ids, data = True, return_dict = False)
wrapped = dict((m._id, m) for m in self.wrap_items(messages))
if prev:
prev = wrapped[prev]
if next:
next = wrapped[next]
final = []
for parent, children in tree:
parent = wrapped[parent]
if children:
# if no parent is specified, check if any of the messages are
# uncollapsed, and truncate the thread
children = [wrapped[child] for child in children]
parent.child = empty_listing()
# if the parent is new, uncollapsed, or focal we don't
# want it to become a moremessages wrapper.
if (self.skip and
not self.parent and not parent.new and parent.is_collapsed
and not (self.focal and self.focal._id == parent._id)):
for i, child in enumerate(children):
if (child.new or not child.is_collapsed or
(self.focal and self.focal._id == child._id)):
break
else:
i = -1
parent = Wrapped(MoreMessages(parent, empty_listing()))
children = children[i:]
parent.child.parent_name = parent._fullname
parent.child.things = []
for child in children:
child.is_child = True
if self.focal and child._id == self.focal._id:
# focal message is never collapsed
child.collapsed = False
child.focal = True
else:
child.collapsed = child.is_collapsed
parent.child.things.append(child)
parent.is_parent = True
# the parent might be the focal message on a permalink page
if self.focal and parent._id == self.focal._id:
parent.collapsed = False
parent.focal = True
else:
parent.collapsed = parent.is_collapsed
final.append(parent)
return (final, prev, next, len(final), len(final))