示例#1
0
def _mappers_configured():
    event_alias = db.aliased(Event)

    # Event.category_chain -- the category ids of the event, starting
    # with the root category down to the event's immediate parent.
    cte = Category.get_tree_cte()
    query = select([cte.c.path]).where(
        cte.c.id == Event.category_id).correlate_except(cte).scalar_subquery()
    Event.category_chain = column_property(query, deferred=True)

    # Event.detailed_category_chain -- the category chain of the event, starting
    # with the root category down to the event's immediate parent.
    cte = Category.get_tree_cte(lambda cat: db.func.json_build_object(
        'id', cat.id, 'title', cat.title))
    query = select([cte.c.path]).where(
        cte.c.id == Event.category_id).correlate_except(cte).scalar_subquery()
    Event.detailed_category_chain = column_property(query, deferred=True)

    # Event.effective_protection_mode -- the effective protection mode
    # (public/protected) of the event, even if it's inheriting it from its
    # parent category
    query = (select([
        db.case(
            {
                ProtectionMode.inheriting.value:
                Category.effective_protection_mode
            },
            else_=Event.protection_mode,
            value=Event.protection_mode)
    ]).where(
        Category.id == Event.category_id).correlate(Event).scalar_subquery())
    Event.effective_protection_mode = column_property(query, deferred=True)

    # Event.series_pos -- the position of the event in its series
    subquery = (select([
        event_alias.id,
        db.func.row_number().over(order_by=(event_alias.start_dt,
                                            event_alias.id)).label('pos')
    ]).where((event_alias.series_id == Event.series_id)
             & ~event_alias.is_deleted).correlate(Event).alias())
    query = select([subquery.c.pos
                    ]).where(subquery.c.id == Event.id).correlate_except(
                        subquery).scalar_subquery()
    Event.series_pos = column_property(query, group='series', deferred=True)

    # Event.series_count -- the number of events in the event's series
    query = (db.select([db.func.count(event_alias.id)
                        ]).where((event_alias.series_id == Event.series_id)
                                 & ~event_alias.is_deleted).correlate_except(
                                     event_alias).scalar_subquery())
    Event.series_count = column_property(query, group='series', deferred=True)

    # Event.contributions_count -- the number of contributions in the event
    from indico.modules.events.contributions.models.contributions import Contribution
    query = (db.select([db.func.count(Contribution.id)
                        ]).where((Contribution.event_id == Event.id)
                                 & ~Contribution.is_deleted).correlate_except(
                                     Contribution).scalar_subquery())
    Event.contributions_count = db.column_property(query, deferred=True)
示例#2
0
def _mappers_configured():
    event_alias = db.aliased(Event)

    # Event.category_chain -- the category ids of the event, starting
    # with the root category down to the event's immediate parent.
    cte = Category.get_tree_cte()
    query = select([cte.c.path]).where(cte.c.id == Event.category_id).correlate_except(cte)
    Event.category_chain = column_property(query, deferred=True)

    # Event.effective_protection_mode -- the effective protection mode
    # (public/protected) of the event, even if it's inheriting it from its
    # parent category
    query = (select([db.case({ProtectionMode.inheriting.value: Category.effective_protection_mode},
                             else_=Event.protection_mode, value=Event.protection_mode)])
             .where(Category.id == Event.category_id))
    Event.effective_protection_mode = column_property(query, deferred=True)

    # Event.series_pos -- the position of the event in its series
    subquery = (select([event_alias.id,
                        db.func.row_number().over(order_by=(event_alias.start_dt, event_alias.id)).label('pos')])
                .where((event_alias.series_id == Event.series_id) & ~event_alias.is_deleted)
                .correlate(Event)
                .alias())
    query = select([subquery.c.pos]).where(subquery.c.id == Event.id).correlate_except(subquery)
    Event.series_pos = column_property(query, group='series', deferred=True)

    # Event.series_count -- the number of events in the event's series
    query = (db.select([db.func.count(event_alias.id)])
             .where((event_alias.series_id == Event.series_id) & ~event_alias.is_deleted)
             .correlate_except(event_alias))
    Event.series_count = column_property(query, group='series', deferred=True)
示例#3
0
def _mappers_configured():
    event_alias = db.aliased(Event)

    # Event.category_chain -- the category ids of the event, starting
    # with the root category down to the event's immediate parent.
    cte = Category.get_tree_cte()
    query = select([cte.c.path]).where(cte.c.id == Event.category_id).correlate_except(cte)
    Event.category_chain = column_property(query, deferred=True)

    # Event.effective_protection_mode -- the effective protection mode
    # (public/protected) of the event, even if it's inheriting it from its
    # parent category
    query = (select([db.case({ProtectionMode.inheriting.value: Category.effective_protection_mode},
                             else_=Event.protection_mode, value=Event.protection_mode)])
             .where(Category.id == Event.category_id))
    Event.effective_protection_mode = column_property(query, deferred=True)

    # Event.series_pos -- the position of the event in its series
    subquery = (select([event_alias.id,
                        db.func.row_number().over(order_by=(event_alias.start_dt, event_alias.id)).label('pos')])
                .where((event_alias.series_id == Event.series_id) & ~event_alias.is_deleted)
                .correlate(Event)
                .alias())
    query = select([subquery.c.pos]).where(subquery.c.id == Event.id).correlate_except(subquery)
    Event.series_pos = column_property(query, group='series', deferred=True)

    # Event.series_count -- the number of events in the event's series
    query = (db.select([db.func.count(event_alias.id)])
             .where((event_alias.series_id == Event.series_id) & ~event_alias.is_deleted)
             .correlate_except(event_alias))
    Event.series_count = column_property(query, group='series', deferred=True)
示例#4
0
 def is_visible_in(cls, category):
     """
     Create a filter that checks whether the event is visible in
     the specified category.
     """
     cte = category.visible_categories_cte
     return (db.exists(db.select([1]))
             .where(db.and_(cte.c.id == Event.category_id,
                            db.or_(Event.visibility.is_(None), Event.visibility > cte.c.level))))
示例#5
0
 def is_visible_in(cls, category_id):
     """
     Create a filter that checks whether the event is visible in
     the specified category.
     """
     cte = Category.get_visible_categories_cte(category_id)
     return (db.exists(db.select([1]))
             .where(db.and_(cte.c.id == Event.category_id,
                            db.or_(Event.visibility.is_(None), Event.visibility > cte.c.level))))