예제 #1
0
    def _process(self, args):
        query = search_for_rooms(args, availability=not args['unavailable'])
        if 'limit' in args:
            query = query.limit(args.pop('limit'))

        rooms = query.all()
        if 'additional_room_ids' in args:
            rooms.extend(
                Room.query.filter(Room.is_active,
                                  Room.id.in_(
                                      args.pop('additional_room_ids'))))

        date_range, availability = get_rooms_availability(
            rooms,
            args['start_dt'],
            args['end_dt'],
            args['repeat_frequency'],
            args['repeat_interval'],
            flexibility=0)
        date_range = [dt.isoformat() for dt in date_range]

        for data in availability.viewvalues():
            # add additional helpful attributes
            data.update({
                'num_days_available':
                len(date_range) - len(data['conflicts']),
                'all_days_available':
                not data['conflicts']
            })

        serialized = _serialize_availability(availability)
        return jsonify_data(flash=False,
                            availability=serialized.items(),
                            date_range=date_range)
예제 #2
0
    def _process(self, room_ids, **kwargs):
        rooms = [self.room] if self.room else Room.query.filter(Room.id.in_(room_ids), Room.is_active).all()
        date_range, availability = get_rooms_availability(rooms, **kwargs)
        date_range = [dt.isoformat() for dt in date_range]

        for data in availability.viewvalues():
            # add additional helpful attributes
            data.update({
                'num_days_available': len(date_range) - len(data['conflicts']),
                'all_days_available': not data['conflicts']
            })
        serialized = _serialize_availability(availability)
        if self.room:
            availability = serialized[self.room.id]
        else:
            # keep order of original room id list
            availability = sorted(serialized.items(), key=lambda x: room_ids.index(x[0]))
        return jsonify(availability=availability, date_range=date_range)
예제 #3
0
파일: bookings.py 프로젝트: pferreir/indico
    def _process(self, room_ids, **kwargs):
        rooms = [self.room] if self.room else Room.query.filter(Room.id.in_(room_ids), Room.is_active).all()
        date_range, availability = get_rooms_availability(rooms, **kwargs)
        date_range = [dt.isoformat() for dt in date_range]

        for data in availability.viewvalues():
            # add additional helpful attributes
            data.update({
                'num_days_available': len(date_range) - len(data['conflicts']),
                'all_days_available': not data['conflicts']
            })
        serialized = _serialize_availability(availability)
        if self.room:
            availability = serialized[self.room.id]
        else:
            # keep order of original room id list
            availability = sorted(serialized.items(), key=lambda x: room_ids.index(x[0]))
        return jsonify(availability=availability, date_range=date_range)