本文整理汇总了Python中indico.modules.events.Event.category_chain_overlaps方法的典型用法代码示例。如果您正苦于以下问题:Python Event.category_chain_overlaps方法的具体用法?Python Event.category_chain_overlaps怎么用?Python Event.category_chain_overlaps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.events.Event
的用法示例。
在下文中一共展示了Event.category_chain_overlaps方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_upcoming_events
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [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
示例2: _process
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def _process(self):
self.user.settings.set('suggest_categories', True)
tz = session.tzinfo
hours, minutes = timedelta_split(tz.utcoffset(datetime.now()))[:2]
categories = get_related_categories(self.user)
categories_events = []
if categories:
category_ids = {c['categ'].id for c in categories.itervalues()}
today = now_utc(False).astimezone(tz).date()
query = (Event.query
.filter(~Event.is_deleted,
Event.category_chain_overlaps(category_ids),
Event.start_dt.astimezone(session.tzinfo) >= today)
.options(joinedload('category').load_only('id', 'title'),
joinedload('series'),
subqueryload('acl_entries'),
load_only('id', 'category_id', 'start_dt', 'end_dt', 'title', 'access_key',
'protection_mode', 'series_id', 'series_pos', 'series_count'))
.order_by(Event.start_dt, Event.id))
categories_events = get_n_matching(query, 10, lambda x: x.can_access(self.user))
from_dt = now_utc(False) - relativedelta(weeks=1, hour=0, minute=0, second=0)
linked_events = [(event, {'management': bool(roles & self.management_roles),
'reviewing': bool(roles & self.reviewer_roles),
'attendance': bool(roles & self.attendance_roles)})
for event, roles in get_linked_events(self.user, from_dt, 10).iteritems()]
return WPUser.render_template('dashboard.html', 'dashboard',
offset='{:+03d}:{:02d}'.format(hours, minutes), user=self.user,
categories=categories,
categories_events=categories_events,
suggested_categories=get_suggested_categories(self.user),
linked_events=linked_events)
示例3: get_attachment_count
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def get_attachment_count(category_id=None):
"""Get the number of attachments in events in a category.
:param category_id: The category ID to get statistics for.
Attachments from subcategories are also
included.
:return: The number of attachments
"""
category_filter = Event.category_chain_overlaps(category_id) if category_id else True
subcontrib_contrib = db.aliased(Contribution)
query = (db.session
.query(db.func.count(Attachment.id))
.join(Attachment.folder)
.join(AttachmentFolder.event)
.outerjoin(AttachmentFolder.session)
.outerjoin(AttachmentFolder.contribution)
.outerjoin(AttachmentFolder.subcontribution)
.outerjoin(subcontrib_contrib, subcontrib_contrib.id == SubContribution.contribution_id)
.filter(AttachmentFolder.link_type != LinkType.category,
~Attachment.is_deleted,
~AttachmentFolder.is_deleted,
~Event.is_deleted,
# we have exactly one of those or none if the attachment is on the event itself
~db.func.coalesce(Session.is_deleted, Contribution.is_deleted, SubContribution.is_deleted, False),
# in case of a subcontribution we also need to check that the contrib is not deleted
(subcontrib_contrib.is_deleted.is_(None) | ~subcontrib_contrib.is_deleted),
category_filter))
return query.scalar()
示例4: serialize_category_atom
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def serialize_category_atom(category, url, user, event_filter):
"""Export the events in a category to Atom
:param category: The category to export
:param url: The URL of the feed
: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.
"""
query = (Event.query
.filter(Event.category_chain_overlaps(category.id),
~Event.is_deleted,
event_filter)
.options(load_only('id', 'category_id', 'start_dt', 'title', 'description', 'protection_mode',
'access_key'),
subqueryload('acl_entries'))
.order_by(Event.start_dt))
events = [e for e in query if e.can_access(user)]
feed = AtomFeed(feed_url=url, title='Indico Feed [{}]'.format(category.title))
for event in events:
feed.add(title=event.title,
summary=unicode(event.description), # get rid of RichMarkup
url=event.external_url,
updated=event.start_dt)
return BytesIO(feed.to_string().encode('utf-8'))
示例5: serialize_category_ical
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def serialize_category_ical(category, user, event_filter):
"""Export the events in a category to iCal
:param category: The category 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.
"""
own_room_strategy = joinedload('own_room')
own_room_strategy.load_only('building', 'floor', 'number', 'name')
own_room_strategy.lazyload('owner')
own_venue_strategy = joinedload('own_venue').load_only('name')
query = (Event.query
.filter(Event.category_chain_overlaps(category.id),
~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))
events = [e for e in query if e.can_access(user)]
cal = ical.Calendar()
cal.add('version', '2.0')
cal.add('prodid', '-//CERN//INDICO//EN')
now = now_utc(False)
for event in events:
url = url_for('event.conferenceDisplay', confId=event.id, _external=True)
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-{}@cern.ch'.format(event.id))
cal_event.add('dtstamp', now)
cal_event.add('dtstart', event.start_dt)
cal_event.add('dtend', event.end_dt)
cal_event.add('url', 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(url)
cal_event.add('description', u'\n'.join(description))
cal.add_component(cal_event)
return BytesIO(cal.to_ical())
示例6: category_events
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def category_events(self, catIds):
from indico.modules.events import Event
query = (Event.query
.filter(~Event.is_deleted,
Event.category_chain_overlaps(map(int, catIds)),
Event.happens_between(self._fromDT, self._toDT))
.options(joinedload('category').load_only('id', 'title')))
return self._process(x.as_legacy for x in query)
示例7: category
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def category(self, idlist):
query = (Event.query
.filter(~Event.is_deleted,
Event.category_chain_overlaps(map(int, idlist)),
Event.happens_between(self._fromDT, self._toDT))
.options(*self._get_query_options(self._detail_level)))
query = self._update_query(query)
return self.serialize_events(x for x in query if self._filter_event(x) and x.can_access(self.user))
示例8: get_events_by_year
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def get_events_by_year(category_id=None):
"""Get the number of events for each year.
:param category_id: The category ID to get statistics for. Events
from subcategories are also included.
:return: An `OrderedDict` mapping years to event counts.
"""
category_filter = Event.category_chain_overlaps(category_id) if category_id else True
query = (db.session
.query(db.cast(db.extract('year', Event.start_dt), db.Integer).label('year'),
db.func.count())
.filter(~Event.is_deleted,
category_filter)
.order_by('year')
.group_by('year'))
return OrderedDict(query)
示例9: get_contribs_by_year
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [as 别名]
def get_contribs_by_year(category_id=None):
"""Get the number of contributions for each year.
:param category_id: The category ID to get statistics for.
Contributions from subcategories are also
included.
:return: An `OrderedDict` mapping years to contribution counts.
"""
category_filter = Event.category_chain_overlaps(category_id) if category_id else True
query = (db.session
.query(db.cast(db.extract('year', TimetableEntry.start_dt), db.Integer).label('year'),
db.func.count())
.join(TimetableEntry.event)
.filter(TimetableEntry.type == TimetableEntryType.CONTRIBUTION,
~Event.is_deleted,
category_filter)
.order_by('year')
.group_by('year'))
return OrderedDict(query)
示例10: serialize_categories_ical
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import category_chain_overlaps [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())