示例#1
0
def _serialize_booking_details(booking):
    attributes = reservation_details_schema.dump(booking)
    date_range, occurrences = get_booking_occurrences(booking)
    date_range = [dt.isoformat() for dt in date_range]
    booking_details = dict(attributes)
    occurrences_by_type = dict(bookings={},
                               cancellations={},
                               rejections={},
                               other_bookings={})
    booking_details['occurrences'] = occurrences_by_type
    booking_details['date_range'] = date_range
    for dt, [occ] in occurrences.iteritems():
        serialized_occ = reservation_occurrences_schema_with_permissions.dump(
            [occ])
        if occ.is_cancelled:
            occurrences_by_type['cancellations'][
                dt.isoformat()] = serialized_occ
        elif occ.is_rejected:
            occurrences_by_type['rejections'][dt.isoformat()] = serialized_occ
        occurrences_by_type['bookings'][
            dt.isoformat()] = serialized_occ if occ.is_valid else []
    start_dt = datetime.combine(booking.start_dt, time.min)
    end_dt = datetime.combine(booking.end_dt, time.max)
    occurrences_by_type['other_bookings'] = get_room_bookings(
        booking.room, start_dt, end_dt, skip_booking_id=booking.id)
    return booking_details
示例#2
0
 def _process(self):
     attributes = reservation_details_schema.dump(self.booking).data
     date_range, occurrences = get_booking_occurrences(self.booking)
     date_range = [dt.isoformat() for dt in date_range]
     occurrences = {dt.isoformat(): reservation_details_occurrences_schema.dump(data).data
                    for dt, data in occurrences.iteritems()}
     booking_details = dict(attributes)
     booking_details['occurrences'] = occurrences
     booking_details['date_range'] = date_range
     return jsonify(booking_details)
示例#3
0
def _serialize_booking_details(booking):
    attributes = reservation_details_schema.dump(booking).data
    date_range, occurrences = get_booking_occurrences(booking)
    date_range = [dt.isoformat() for dt in date_range]
    occurrences = {dt.isoformat(): reservation_details_occurrences_schema.dump(data).data
                   for dt, data in occurrences.iteritems()}
    booking_details = dict(attributes)
    booking_details['occurrences'] = occurrences
    booking_details['date_range'] = date_range
    return booking_details
示例#4
0
def _serialize_booking_details(booking):
    attributes = reservation_details_schema.dump(booking).data
    date_range, occurrences = get_booking_occurrences(booking)
    date_range = [dt.isoformat() for dt in date_range]
    booking_details = dict(attributes)
    occurrences_by_type = dict(bookings={}, cancelations={}, rejections={}, other_bookings={})
    booking_details['occurrences'] = occurrences_by_type
    booking_details['date_range'] = date_range
    for dt, [occ] in occurrences.iteritems():
        serialized_occ = reservation_details_occurrences_schema.dump([occ]).data
        if occ.is_cancelled:
            occurrences_by_type['cancelations'][dt.isoformat()] = serialized_occ
        elif occ.is_rejected:
            occurrences_by_type['rejections'][dt.isoformat()] = serialized_occ
        occurrences_by_type['bookings'][dt.isoformat()] = serialized_occ if occ.is_valid else []
    start_dt = datetime.combine(booking.start_dt, time.min)
    end_dt = datetime.combine(booking.end_dt, time.max)
    occurrences_by_type['other_bookings'] = get_room_bookings(booking.room, start_dt, end_dt,
                                                              skip_booking_id=booking.id)
    return booking_details
示例#5
0
def serialize_booking_details(booking):
    from indico.modules.rb_new.operations.bookings import (get_booking_occurrences, group_blockings,
                                                           group_nonbookable_periods, get_room_bookings)

    attributes = reservation_details_schema.dump(booking)
    date_range, occurrences = get_booking_occurrences(booking)
    booking_details = dict(attributes)
    occurrences_by_type = dict(bookings={}, cancellations={}, rejections={}, other={}, blockings={},
                               unbookable_hours={}, nonbookable_periods={}, overridable_blockings={})
    booking_details['occurrences'] = occurrences_by_type
    booking_details['date_range'] = [dt.isoformat() for dt in date_range]
    for dt, [occ] in occurrences.iteritems():
        serialized_occ = reservation_occurrences_schema_with_permissions.dump([occ])
        if occ.is_cancelled:
            occurrences_by_type['cancellations'][dt.isoformat()] = serialized_occ
        elif occ.is_rejected:
            occurrences_by_type['rejections'][dt.isoformat()] = serialized_occ
        occurrences_by_type['bookings'][dt.isoformat()] = serialized_occ if occ.is_valid else []

    start_dt = datetime.combine(booking.start_dt, time.min)
    end_dt = datetime.combine(booking.end_dt, time.max)
    unbookable_hours = get_rooms_unbookable_hours([booking.room]).get(booking.room.id, [])
    blocked_rooms = get_rooms_blockings([booking.room], start_dt.date(), end_dt.date())
    overridable_blockings = group_blocked_rooms(filter_blocked_rooms(blocked_rooms,
                                                                     overridable_only=True,
                                                                     explicit=True)).get(booking.room.id, [])
    nonoverridable_blockings = group_blocked_rooms(filter_blocked_rooms(blocked_rooms,
                                                                        nonoverridable_only=True,
                                                                        explicit=True)).get(booking.room.id, [])
    nonbookable_periods = get_rooms_nonbookable_periods([booking.room], start_dt, end_dt).get(booking.room.id, [])
    nonbookable_periods_grouped = group_nonbookable_periods(nonbookable_periods, date_range)
    occurrences_by_type['other'] = get_room_bookings(booking.room, start_dt, end_dt, skip_booking_id=booking.id)
    occurrences_by_type['blockings'] = serialize_blockings(group_blockings(nonoverridable_blockings, date_range))
    occurrences_by_type['overridable_blockings'] = serialize_blockings(group_blockings(overridable_blockings,
                                                                                       date_range))
    occurrences_by_type['unbookable_hours'] = serialize_unbookable_hours(unbookable_hours)
    occurrences_by_type['nonbookable_periods'] = serialize_nonbookable_periods(nonbookable_periods_grouped)
    return booking_details