本文整理汇总了Python中indico.modules.categories.Category._get_chain_query方法的典型用法代码示例。如果您正苦于以下问题:Python Category._get_chain_query方法的具体用法?Python Category._get_chain_query怎么用?Python Category._get_chain_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.categories.Category
的用法示例。
在下文中一共展示了Category._get_chain_query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialize_categories_ical
# 需要导入模块: from indico.modules.categories import Category [as 别名]
# 或者: from indico.modules.categories.Category import _get_chain_query [as 别名]
def serialize_categories_ical(category_ids, user, event_filter=True, event_filter_fn=None, update_query=None):
"""Export the events in a category to iCal
:param category_ids: Category IDs to export
:param user: The user who needs to be able to access the events
:param event_filter: A SQLalchemy criterion to restrict which
events will be returned. Usually something
involving the start/end date of the event.
:param event_filter_fn: A callable that determines which events to include (after querying)
:param update_query: A callable that can update the query used to retrieve the events.
Must return the updated query object.
"""
own_room_strategy = joinedload('own_room')
own_room_strategy.load_only('building', 'floor', 'number', 'verbose_name')
own_room_strategy.lazyload('owner')
own_venue_strategy = joinedload('own_venue').load_only('name')
query = (Event.query
.filter(Event.category_chain_overlaps(category_ids),
~Event.is_deleted,
event_filter)
.options(load_only('id', 'category_id', 'start_dt', 'end_dt', 'title', 'description', 'own_venue_name',
'own_room_name', 'protection_mode', 'access_key'),
subqueryload('acl_entries'),
joinedload('person_links'),
own_room_strategy,
own_venue_strategy)
.order_by(Event.start_dt))
if update_query:
query = update_query(query)
it = iter(query)
if event_filter_fn:
it = ifilter(event_filter_fn, it)
events = list(it)
# make sure the parent categories are in sqlalchemy's identity cache.
# this avoids query spam from `protection_parent` lookups
_parent_categs = (Category._get_chain_query(Category.id.in_({e.category_id for e in events}))
.options(load_only('id', 'parent_id', 'protection_mode'),
joinedload('acl_entries'))
.all())
cal = ical.Calendar()
cal.add('version', '2.0')
cal.add('prodid', '-//CERN//INDICO//EN')
now = now_utc(False)
for event in events:
if not event.can_access(user):
continue
location = ('{} ({})'.format(event.room_name, event.venue_name)
if event.venue_name and event.room_name
else (event.venue_name or event.room_name))
cal_event = ical.Event()
cal_event.add('uid', u'indico-event-{}@{}'.format(event.id, url_parse(config.BASE_URL).host))
cal_event.add('dtstamp', now)
cal_event.add('dtstart', event.start_dt)
cal_event.add('dtend', event.end_dt)
cal_event.add('url', event.external_url)
cal_event.add('summary', event.title)
cal_event.add('location', location)
description = []
if event.person_links:
speakers = [u'{} ({})'.format(x.full_name, x.affiliation) if x.affiliation else x.full_name
for x in event.person_links]
description.append(u'Speakers: {}'.format(u', '.join(speakers)))
if event.description:
desc_text = unicode(event.description) or u'<p/>' # get rid of RichMarkup
try:
description.append(unicode(html.fromstring(desc_text).text_content()))
except ParserError:
# this happens e.g. if desc_text contains only a html comment
pass
description.append(event.external_url)
cal_event.add('description', u'\n'.join(description))
cal.add_component(cal_event)
return BytesIO(cal.to_ical())