本文整理汇总了Python中indico.modules.events.Event.is_visible_in方法的典型用法代码示例。如果您正苦于以下问题:Python Event.is_visible_in方法的具体用法?Python Event.is_visible_in怎么用?Python Event.is_visible_in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.events.Event
的用法示例。
在下文中一共展示了Event.is_visible_in方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_upcoming_events
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import is_visible_in [as 别名]
def get_upcoming_events():
"""Get the global list of upcoming events"""
from indico.modules.events import Event
data = upcoming_events_settings.get_all()
if not data['max_entries'] or not data['entries']:
return
tz = timezone(config.DEFAULT_TIMEZONE)
now = now_utc(False).astimezone(tz)
base_query = (Event.query
.filter(Event.effective_protection_mode == ProtectionMode.public,
~Event.is_deleted,
Event.end_dt.astimezone(tz) > now)
.options(load_only('id', 'title', 'start_dt', 'end_dt')))
queries = []
predicates = {'category': lambda id_: Event.category_id == id_,
'category_tree': lambda id_: Event.category_chain_overlaps(id_) & Event.is_visible_in(id_),
'event': lambda id_: Event.id == id_}
for entry in data['entries']:
delta = timedelta(days=entry['days'])
query = (base_query
.filter(predicates[entry['type']](entry['id']))
.filter(db.cast(Event.start_dt.astimezone(tz), db.Date) > (now - delta).date())
.with_entities(Event, db.literal(entry['weight']).label('weight')))
queries.append(query)
query = (queries[0].union(*queries[1:])
.order_by(db.desc('weight'), Event.start_dt, Event.title)
.limit(data['max_entries']))
for row in query:
event = row[0]
# we cache the result of the function and is_deleted is used in the repr
# and having a broken repr on the cached objects would be ugly
set_committed_value(event, 'is_deleted', False)
yield event