def parse_indico_id(indico_id): event_match = re.match('(\d+)$', indico_id) session_match = re.match('(\d+)s(\d+)$', indico_id) contrib_match = re.match('(\d+)c(\d+)$', indico_id) subcontrib_match = re.match('(\d+)c(\d+)sc(\d+)$', indico_id) if subcontrib_match: event = Event.get(subcontrib_match.group(1), is_deleted=False) if not event: return None return SubContribution.find( SubContribution.id == subcontrib_match.group(3), ~SubContribution.is_deleted, SubContribution.contribution.has(event=event, id=subcontrib_match.group(2), is_deleted=False)).first() elif session_match: event = Event.get(session_match.group(1), is_deleted=False) return Session.query.with_parent(event).filter_by( id=session_match.group(2)).first() elif contrib_match: event = Event.get(contrib_match.group(1), is_deleted=False) return Contribution.query.with_parent(event).filter_by( id=contrib_match.group(2)).first() elif event_match: return Event.get(event_match.group(1), is_deleted=False) else: return None
def get_contributions(event): """Returns a list of contributions in rooms with AV equipment :return: a list of ``(contribution, capable, custom_room)`` tuples """ contribs = ( Contribution.query.with_parent(event).filter( Contribution.is_scheduled).filter( db.or_( Contribution.session == None, # noqa Contribution.session.has( db.or_( Session.type == None, # noqa Session.type.has(is_poster=False))))).options( joinedload('timetable_entry').load_only( 'start_dt'), joinedload('session_block'), subqueryload('person_links'), undefer('is_scheduled')).all()) subcontribs = (SubContribution.find( SubContribution.contribution_id.in_(c.id for c in contribs), ~SubContribution.is_deleted).options( subqueryload('person_links')).all()) all_contribs = sorted(contribs + subcontribs, key=_contrib_key) av_capable_rooms = get_av_capable_rooms() event_room = event.room return [(c, _get_contrib(c).room in av_capable_rooms, _get_contrib(c).room_name if _get_contrib(c).room and _get_contrib(c).room != event_room else None) for c in all_contribs]
def contribution_by_id(event, contrib_or_subcontrib_id): """Returns a contribution/subcontriution from an :func:`contribution_id`-style ID""" type_, id_ = contrib_or_subcontrib_id.split(':', 1) id_ = int(id_) if type_ == 'c': return Contribution.query.with_parent(event).filter_by(id=id_).first() elif type_ == 'sc': return SubContribution.find(SubContribution.id == id_, ~SubContribution.is_deleted, SubContribution.contribution.has(event=event, is_deleted=False)).first() else: raise ValueError('Invalid id type: ' + type_)
def _process_cascaded_event_contents(records, additional_events=None): """ Flatten a series of records into its most basic elements (subcontribution level). Yields results. :param records: queue records to process :param additional_events: events whose content will be included in addition to those found in records """ changed_events = additional_events or set() changed_contributions = set() changed_subcontributions = set() session_records = {rec.session_id for rec in records if rec.type == EntryType.session} contribution_records = {rec.contrib_id for rec in records if rec.type == EntryType.contribution} subcontribution_records = {rec.subcontrib_id for rec in records if rec.type == EntryType.subcontribution} event_records = {rec.event_id for rec in records if rec.type == EntryType.event} if event_records: changed_events.update(Event.find(Event.id.in_(event_records))) for event in changed_events: yield event # Sessions are added (explicitly changed only, since they don't need to be sent anywhere) if session_records: changed_contributions.update(Contribution .find(Contribution.session_id.in_(session_records), ~Contribution.is_deleted)) # Contributions are added (implictly + explicitly changed) changed_event_ids = {ev.id for ev in changed_events} condition = Contribution.event_id.in_(changed_event_ids) & ~Contribution.is_deleted if contribution_records: condition = db.or_(condition, Contribution.id.in_(contribution_records)) contrib_query = Contribution.find(condition).options(joinedload('subcontributions')) for contribution in contrib_query: yield contribution changed_subcontributions.update(contribution.subcontributions) # Same for subcontributions if subcontribution_records: changed_subcontributions.update(SubContribution.find(SubContribution.id.in_(subcontribution_records))) for subcontrib in changed_subcontributions: yield subcontrib
def get_object_from_args(args=None): """Retrieves an event object from request arguments. This utility is meant to be used in cases where the same controller can deal with objects attached to various parts of an event which use different URLs to indicate which object to use. :param args: The request arguments. If unspecified, ``request.view_args`` is used. :return: An ``(object_type, event, object)`` tuple. The event is always the :class:`Event` associated with the object. The object may be an `Event`, `Session`, `Contribution` or `SubContribution`. If the object does not exist, ``(object_type, None, None)`` is returned. """ if args is None: args = request.view_args object_type = args['object_type'] event = Event.find_first(id=args['confId'], is_deleted=False) if event is None: obj = None elif object_type == 'event': obj = event elif object_type == 'session': obj = Session.query.with_parent(event).filter_by( id=args['session_id']).first() elif object_type == 'contribution': obj = Contribution.query.with_parent(event).filter_by( id=args['contrib_id']).first() elif object_type == 'subcontribution': obj = SubContribution.find( SubContribution.id == args['subcontrib_id'], ~SubContribution.is_deleted, SubContribution.contribution.has(event=event, id=args['contrib_id'], is_deleted=False)).first() else: raise ValueError('Unexpected object type: {}'.format(object_type)) if obj is not None: return object_type, event, obj else: return object_type, None, None
def get_object_from_args(args=None): """Retrieves an event object from request arguments. This utility is meant to be used in cases where the same controller can deal with objects attached to various parts of an event which use different URLs to indicate which object to use. :param args: The request arguments. If unspecified, ``request.view_args`` is used. :return: An ``(object_type, event, object)`` tuple. The event is always the :class:`Event` associated with the object. The object may be an `Event`, `Session`, `Contribution` or `SubContribution`. If the object does not exist, ``(object_type, None, None)`` is returned. """ if args is None: args = request.view_args object_type = args['object_type'] event = Event.find_first(id=args['confId'], is_deleted=False) if event is None: obj = None elif object_type == 'event': obj = event elif object_type == 'session': obj = Session.query.with_parent(event).filter_by(id=args['session_id']).first() elif object_type == 'contribution': obj = Contribution.query.with_parent(event).filter_by(id=args['contrib_id']).first() elif object_type == 'subcontribution': obj = SubContribution.find(SubContribution.id == args['subcontrib_id'], ~SubContribution.is_deleted, SubContribution.contribution.has(event=event, id=args['contrib_id'], is_deleted=False)).first() else: raise ValueError('Unexpected object type: {}'.format(object_type)) if obj is not None: return object_type, event, obj else: return object_type, None, None
def _process_cascaded_event_contents(records, additional_events=None): """ Flatten a series of records into its most basic elements (subcontribution level). Yields results. :param records: queue records to process :param additional_events: events whose content will be included in addition to those found in records """ changed_events = additional_events or set() changed_contributions = set() changed_subcontributions = set() session_records = { rec.session_id for rec in records if rec.type == EntryType.session } contribution_records = { rec.contrib_id for rec in records if rec.type == EntryType.contribution } subcontribution_records = { rec.subcontrib_id for rec in records if rec.type == EntryType.subcontribution } event_records = { rec.event_id for rec in records if rec.type == EntryType.event } if event_records: changed_events.update(Event.find(Event.id.in_(event_records))) for event in changed_events: yield event # Sessions are added (explicitly changed only, since they don't need to be sent anywhere) if session_records: changed_contributions.update( Contribution.find(Contribution.session_id.in_(session_records), ~Contribution.is_deleted)) # Contributions are added (implictly + explicitly changed) changed_event_ids = {ev.id for ev in changed_events} condition = Contribution.event_id.in_( changed_event_ids) & ~Contribution.is_deleted if contribution_records: condition = db.or_(condition, Contribution.id.in_(contribution_records)) contrib_query = Contribution.find(condition).options( joinedload('subcontributions')) for contribution in contrib_query: yield contribution changed_subcontributions.update(contribution.subcontributions) # Same for subcontributions if subcontribution_records: changed_subcontributions.update( SubContribution.find( SubContribution.id.in_(subcontribution_records))) for subcontrib in changed_subcontributions: yield subcontrib