当前位置: 首页>>代码示例>>Python>>正文


Python RepeatMapping.getNewMapping方法代码示例

本文整理汇总了Python中indico.modules.rb.models.reservations.RepeatMapping.getNewMapping方法的典型用法代码示例。如果您正苦于以下问题:Python RepeatMapping.getNewMapping方法的具体用法?Python RepeatMapping.getNewMapping怎么用?Python RepeatMapping.getNewMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在indico.modules.rb.models.reservations.RepeatMapping的用法示例。


在下文中一共展示了RepeatMapping.getNewMapping方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_reservation_repeatability

# 需要导入模块: from indico.modules.rb.models.reservations import RepeatMapping [as 别名]
# 或者: from indico.modules.rb.models.reservations.RepeatMapping import getNewMapping [as 别名]
def convert_reservation_repeatability(old):
    return RepeatMapping.getNewMapping(old)
开发者ID:sofian86,项目名称:indico-gh-test,代码行数:4,代码来源:migrate_to_sqlalchemy.py

示例2: find_with_filters

# 需要导入模块: from indico.modules.rb.models.reservations import RepeatMapping [as 别名]
# 或者: from indico.modules.rb.models.reservations.RepeatMapping import getNewMapping [as 别名]
    def find_with_filters(filters, avatar):
        from indico.modules.rb.models.locations import Location

        equipment_count = len(filters['available_equipment'])
        equipment_subquery = None
        if equipment_count:
            equipment_subquery = (
                db.session.query(RoomEquipmentAssociation)
                .with_entities(func.count(RoomEquipmentAssociation.c.room_id))
                .filter(
                    RoomEquipmentAssociation.c.room_id == Room.id,
                    RoomEquipmentAssociation.c.equipment_id.in_(eq.id for eq in filters['available_equipment'])
                )
                .correlate(Room)
                .as_scalar()
            )

        q = (
            Room.query
            .join(Location.rooms)
            .filter(
                Location.id == filters['location'].id if filters['location'] else True,
                (Room.capacity >= (filters['capacity'] * 0.8)) if filters['capacity'] else True,
                Room.is_reservable if filters['is_only_public'] else True,
                Room.is_auto_confirm if filters['is_auto_confirm'] else True,
                Room.is_active if filters.get('is_only_active', False) else True,
                (equipment_subquery == equipment_count) if equipment_subquery is not None else True)
        )

        if filters['available'] != -1:
            repetition = RepeatMapping.getNewMapping(ast.literal_eval(filters['repeatability']))
            is_available = Room.filter_available(filters['start_dt'], filters['end_dt'], repetition,
                                                 include_pre_bookings=filters['include_pre_bookings'],
                                                 include_pending_blockings=filters['include_pending_blockings'])
            # Filter the search results
            if filters['available'] == 0:  # booked/unavailable
                q = q.filter(~is_available)
            elif filters['available'] == 1:  # available
                q = q.filter(is_available)

        free_search_columns = (
            'name', 'site', 'division', 'building', 'floor', 'number', 'telephone', 'key_location', 'comments'
        )
        if filters['details']:
            # Attributes are stored JSON-encoded, so we need to JSON-encode the provided string and remove the quotes
            # afterwards since PostgreSQL currently does not expose a function to decode a JSON string:
            # http://www.postgresql.org/message-id/[email protected]
            details = filters['details'].lower()
            details_str = u'%{}%'.format(details)
            details_json = u'%{}%'.format(json.dumps(details)[1:-1])
            free_search_criteria = [getattr(Room, c).ilike(details_str) for c in free_search_columns]
            free_search_criteria.append(Room.attributes.any(cast(RoomAttributeAssociation.value, db.String)
                                                            .ilike(details_json)))
            q = q.filter(or_(*free_search_criteria))

        q = q.order_by(Room.capacity)
        rooms = q.all()
        # Apply a bunch of filters which are *much* easier to do here than in SQL!
        if filters['is_only_public']:
            # This may trigger additional SQL queries but is_public is cached and doing this check here is *much* easier
            rooms = [r for r in rooms if r.is_public]
        if filters.get('is_only_my_rooms'):
            rooms = [r for r in rooms if r.is_owned_by(avatar)]
        if filters['capacity']:
            # Unless it would result in an empty resultset we don't want to show room which >20% more capacity
            # than requested. This cannot be done easily in SQL so we do that logic here after the SQL query already
            # weeded out rooms that are too small
            matching_capacity_rooms = [r for r in rooms if r.capacity <= filters['capacity'] * 1.2]
            if matching_capacity_rooms:
                rooms = matching_capacity_rooms
        return rooms
开发者ID:sofian86,项目名称:indico-gh-test,代码行数:73,代码来源:rooms.py


注:本文中的indico.modules.rb.models.reservations.RepeatMapping.getNewMapping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。