Ejemplo n.º 1
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={},
                               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_details_occurrences_schema.dump([occ
                                                                      ]).data
        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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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