Example #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)
    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)
Example #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)
Example #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).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)
Example #4
0
 def filter_bookable_hours(start_time, end_time):
     if end_time == time(0):
         end_time = time(23, 59, 59)
     period_end_time = db.case({time(0): time(23, 59, 59)}, else_=BookableHours.end_time,
                               value=BookableHours.end_time)
     bookable_hours_filter = Room.bookable_hours.any(
         (BookableHours.start_time <= start_time) & (period_end_time >= end_time)
     )
     return ~Room.bookable_hours.any() | bookable_hours_filter
Example #5
0
 def filter_bookable_hours(start_time, end_time):
     if end_time == time(0):
         end_time = time(23, 59, 59)
     period_end_time = db.case({time(0): time(23, 59, 59)}, else_=BookableHours.end_time,
                               value=BookableHours.end_time)
     bookable_hours_filter = Room.bookable_hours.any(
         (BookableHours.start_time <= start_time) & (period_end_time >= end_time)
     )
     return ~Room.bookable_hours.any() | bookable_hours_filter
Example #6
0
 def full_name(cls):
     return db.case([[
         cls.verbose_name.isnot(None), cls.name + ' - ' + cls.verbose_name
     ]],
                    else_=cls.name)
Example #7
0
 def full_name(cls):
     simple_name = cls.building + '-' + cls.floor + '-' + cls.number
     return db.case([
         [((cls.name != '') & (cls.name != simple_name)), simple_name + ' - ' + cls.name]
     ], else_=simple_name)
Example #8
0
 def full_name(cls):
     return db.case([
         [cls.verbose_name.isnot(None), cls.name + ' - ' + cls.verbose_name]
     ], else_=cls.name)
Example #9
0
 def full_name(cls):
     simple_name = cls.building + '-' + cls.floor + '-' + cls.number
     return db.case([
         [((cls.name != '') & (cls.name != simple_name)), simple_name + ' - ' + cls.name]
     ], else_=simple_name)