Ejemplo n.º 1
0
def get_linked_events(user, dt, limit=None, load_also=()):
    """Get the linked events and the user's roles in them.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :param limit: Max number of events
    """
    from indico.modules.events.abstracts.util import (get_events_with_abstract_persons,
                                                      get_events_with_abstract_reviewer_convener)
    from indico.modules.events.contributions.util import get_events_with_linked_contributions
    from indico.modules.events.papers.util import get_events_with_paper_roles
    from indico.modules.events.registration.util import get_events_registered
    from indico.modules.events.sessions.util import get_events_with_linked_sessions
    from indico.modules.events.surveys.util import get_events_with_submitted_surveys
    from indico.modules.events.util import (get_events_created_by, get_events_managed_by,
                                            get_events_with_linked_event_persons)

    links = {}
    for event_id in get_events_registered(user, dt):
        links.setdefault(event_id, set()).add('registration_registrant')
    for event_id in get_events_with_submitted_surveys(user, dt):
        links.setdefault(event_id, set()).add('survey_submitter')
    for event_id in get_events_managed_by(user, dt):
        links.setdefault(event_id, set()).add('conference_manager')
    for event_id in get_events_created_by(user, dt):
        links.setdefault(event_id, set()).add('conference_creator')
    for event_id, principal_roles in get_events_with_linked_sessions(user, dt).items():
        links.setdefault(event_id, set()).update(principal_roles)
    for event_id, principal_roles in get_events_with_linked_contributions(user, dt).items():
        links.setdefault(event_id, set()).update(principal_roles)
    for event_id, role in get_events_with_linked_event_persons(user, dt).items():
        links.setdefault(event_id, set()).add(role)
    for event_id, roles in get_events_with_abstract_reviewer_convener(user, dt).items():
        links.setdefault(event_id, set()).update(roles)
    for event_id, roles in get_events_with_abstract_persons(user, dt).items():
        links.setdefault(event_id, set()).update(roles)
    for event_id, roles in get_events_with_paper_roles(user, dt).items():
        links.setdefault(event_id, set()).update(roles)
    for event in user.favorite_events:
        if event.start_dt >= dt:
            links.setdefault(event.id, set()).add('favorited')

    if not links:
        return {}

    query = (Event.query
             .filter(~Event.is_deleted,
                     Event.id.in_(links))
             .options(joinedload('series'),
                      joinedload('label'),
                      load_only('id', 'category_id', 'title', 'start_dt', 'end_dt',
                                'series_id', 'series_pos', 'series_count', 'label_id', 'label_message',
                                *load_also))
             .order_by(Event.start_dt, Event.id))
    if limit is not None:
        query = query.limit(limit)
    return {event: links[event.id] for event in query}
Ejemplo n.º 2
0
def get_linked_events(user, dt, limit=None):
    """Get the linked events and the user's roles in them

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :param limit: Max number of events
    """
    from indico.modules.events.abstracts.util import (get_events_with_abstract_reviewer_convener,
                                                      get_events_with_abstract_persons)
    from indico.modules.events.contributions.util import get_events_with_linked_contributions
    from indico.modules.events.registration.util import get_events_registered
    from indico.modules.events.sessions.util import get_events_with_linked_sessions
    from indico.modules.events.surveys.util import get_events_with_submitted_surveys
    from indico.modules.events.util import (get_events_managed_by, get_events_created_by,
                                            get_events_with_linked_event_persons)

    links = avatar_links.get_links(user, dt) if redis_client else OrderedDict()
    allowed_redis_links = {'conference_editor', 'conference_paperReviewManager', 'conference_referee',
                           'conference_reviewer'}
    for event_id, event_links in links.items():
        event_links &= allowed_redis_links
        if not event_links:
            del links[event_id]
    for event_id in get_events_registered(user, dt):
        links.setdefault(str(event_id), set()).add('registration_registrant')
    for event_id in get_events_with_submitted_surveys(user, dt):
        links.setdefault(str(event_id), set()).add('survey_submitter')
    for event_id in get_events_managed_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_manager')
    for event_id in get_events_created_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_creator')
    for event_id, principal_roles in get_events_with_linked_sessions(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id, principal_roles in get_events_with_linked_contributions(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id in get_events_with_linked_event_persons(user, dt):
        links.setdefault(str(event_id), set()).add('conference_chair')
    for event_id, roles in get_events_with_abstract_reviewer_convener(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)
    for event_id, roles in get_events_with_abstract_persons(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)

    if not links:
        return OrderedDict()

    query = (Event.query
             .filter(~Event.is_deleted,
                     Event.id.in_(map(int, links)))
             .options(joinedload('series'),
                      load_only('id', 'category_id', 'title', 'start_dt', 'end_dt',
                                'series_id', 'series_pos', 'series_count'))
             .order_by(Event.start_dt, Event.id))
    if limit is not None:
        query = query.limit(limit)
    return OrderedDict((event, links[str(event.id)]) for event in query)
Ejemplo n.º 3
0
def get_category_scores(user, debug=False):
    # XXX: check if we can add some more roles such as 'contributor' to assume attendance
    event_ids = set()
    event_ids.update(
        id_
        for id_, roles in get_events_with_abstract_persons(user).iteritems()
        if 'abstract_submitter' in roles)
    event_ids.update(id_ for id_, roles in
                     get_events_with_linked_contributions(user).iteritems()
                     if 'contribution_submission' in roles)
    event_ids |= get_events_registered(user)
    event_ids |= get_events_with_submitted_surveys(user)
    attended = (Event.query.filter(Event.id.in_(event_ids),
                                   ~Event.is_deleted).options(
                                       joinedload('category')).order_by(
                                           Event.start_dt, Event.id).all())
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.category].append(event)
    return dict((categ, _get_category_score(user, categ, events, debug))
                for categ, events in categ_events.iteritems())
Ejemplo n.º 4
0
def get_category_scores(user, debug=False):
    # XXX: check if we can add some more roles such as 'contributor' to assume attendance
    event_ids = set()
    event_ids.update(id_
                     for id_, roles in get_events_with_abstract_persons(user).iteritems()
                     if 'abstract_submitter' in roles)
    event_ids.update(id_
                     for id_, roles in get_events_with_linked_contributions(user).iteritems()
                     if 'contribution_submission' in roles)
    event_ids |= get_events_registered(user)
    event_ids |= get_events_with_submitted_surveys(user)
    if not event_ids:
        return {}
    attended = (Event.query
                .filter(Event.id.in_(event_ids), ~Event.is_deleted)
                .options(joinedload('category'))
                .order_by(Event.start_dt, Event.id)
                .all())
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.category].append(event)
    return dict((categ, _get_category_score(user, categ, events, debug))
                for categ, events in categ_events.iteritems())
Ejemplo n.º 5
0
def get_linked_events(user, dt, limit=None):
    """Get the linked events and the user's roles in them

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :param limit: Max number of events
    """
    from indico.modules.events.abstracts.util import (
        get_events_with_abstract_reviewer_convener,
        get_events_with_abstract_persons)
    from indico.modules.events.contributions.util import get_events_with_linked_contributions
    from indico.modules.events.registration.util import get_events_registered
    from indico.modules.events.sessions.util import get_events_with_linked_sessions
    from indico.modules.events.surveys.util import get_events_with_submitted_surveys
    from indico.modules.events.util import (
        get_events_managed_by, get_events_created_by,
        get_events_with_linked_event_persons)

    links = avatar_links.get_links(user, dt) if redis_client else OrderedDict()
    allowed_redis_links = {
        'conference_editor', 'conference_paperReviewManager',
        'conference_referee', 'conference_reviewer'
    }
    for event_id, event_links in links.items():
        event_links &= allowed_redis_links
        if not event_links:
            del links[event_id]
    for event_id in get_events_registered(user, dt):
        links.setdefault(str(event_id), set()).add('registration_registrant')
    for event_id in get_events_with_submitted_surveys(user, dt):
        links.setdefault(str(event_id), set()).add('survey_submitter')
    for event_id in get_events_managed_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_manager')
    for event_id in get_events_created_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_creator')
    for event_id, principal_roles in get_events_with_linked_sessions(
            user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id, principal_roles in get_events_with_linked_contributions(
            user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id in get_events_with_linked_event_persons(user, dt):
        links.setdefault(str(event_id), set()).add('conference_chair')
    for event_id, roles in get_events_with_abstract_reviewer_convener(
            user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)
    for event_id, roles in get_events_with_abstract_persons(user,
                                                            dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)

    if not links:
        return OrderedDict()

    query = (Event.query.filter(~Event.is_deleted, Event.id.in_(map(
        int, links))).options(
            joinedload('series'),
            load_only('id', 'category_id', 'title', 'start_dt', 'end_dt',
                      'series_id', 'series_pos',
                      'series_count')).order_by(Event.start_dt, Event.id))
    if limit is not None:
        query = query.limit(limit)
    return OrderedDict((event, links[str(event.id)]) for event in query)