本文整理汇总了Python中subreddit.Subreddit.default方法的典型用法代码示例。如果您正苦于以下问题:Python Subreddit.default方法的具体用法?Python Subreddit.default怎么用?Python Subreddit.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subreddit.Subreddit
的用法示例。
在下文中一共展示了Subreddit.default方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _link_nav_query
# 需要导入模块: from subreddit import Subreddit [as 别名]
# 或者: from subreddit.Subreddit import default [as 别名]
def _link_nav_query(self, clause = None, sort = None):
sr = Subreddit.default()
q = Link._query(self._nav_query_date_clause(sort), Link.c._deleted == False, Link.c._spam == False, Link.c.sr_id == sr._id, limit = 1, sort = sort, data = True)
if clause is not None:
q._filter(clause)
return q
示例2: _next_link_for_tag
# 需要导入模块: from subreddit import Subreddit [as 别名]
# 或者: from subreddit.Subreddit import default [as 别名]
def _next_link_for_tag(self, tag, sort):
"""Returns a query navigation by tag using the supplied sort"""
from r2.lib.db import tdb_sql as tdb
import sqlalchemy as sa
# List of the subreddit ids this user has access to
sr = Subreddit.default()
# Get a reference to reddit_rel_linktag
linktag_type = tdb.rel_types_id[LinkTag._type_id]
linktag_thing_table = linktag_type.rel_table[0]
# Get a reference to the reddit_thing_link & reddit_data_link tables
link_type = tdb.types_id[Link._type_id]
link_data_table = link_type.data_table[0]
link_thing_table = link_type.thing_table
# Subreddit subquery aliased as link_sr
link_sr = sa.select([
link_data_table.c.thing_id,
sa.cast(link_data_table.c.value, sa.INT).label('sr_id')],
link_data_table.c.key == 'sr_id').alias('link_sr')
# Determine the date clause based on the sort order requested
if isinstance(sort, operators.desc):
date_clause = link_thing_table.c.date < self._date
sort = sa.desc(link_thing_table.c.date)
else:
date_clause = link_thing_table.c.date > self._date
sort = sa.asc(link_thing_table.c.date)
query = sa.select([linktag_thing_table.c.thing1_id],
sa.and_(linktag_thing_table.c.thing2_id == tag._id,
linktag_thing_table.c.thing1_id == link_sr.c.thing_id,
linktag_thing_table.c.thing1_id == link_thing_table.c.thing_id,
linktag_thing_table.c.name == 'tag',
link_thing_table.c.spam == False,
link_thing_table.c.deleted == False,
date_clause,
link_sr.c.sr_id == sr._id),
order_by = sort,
limit = 1)
row = query.execute().fetchone()
return Link._byID(row.thing1_id, data=True) if row else None