Ejemplo n.º 1
0
    def _process(self, args):
        new_booking_data = {
            'booking_reason': args['booking_reason'],
            'room_usage':
            'current_user' if args.get('user_id', None) is None else 'someone',
            'booked_for_user': User.get(args.get('user_id', session.user.id)),
            'start_dt': args['start_dt'],
            'end_dt': args['end_dt'],
            'repeat_frequency': args['repeat_frequency'],
            'repeat_interval': args['repeat_interval'],
        }

        additional_booking_attrs = {}
        if not should_split_booking(self.booking, new_booking_data):
            has_date_changed = not has_same_dates(self.booking,
                                                  new_booking_data)
            room = self.booking.room
            self.booking.modify(new_booking_data, session.user)
            if (has_date_changed
                    and not room.can_book(session.user, allow_admin=False)
                    and room.can_prebook(session.user, allow_admin=False)
                    and self.booking.is_accepted):
                self.booking.reset_approval(session.user)
        else:
            new_booking = split_booking(self.booking, new_booking_data)
            additional_booking_attrs['new_booking_id'] = new_booking.id

        db.session.flush()
        today = date.today()
        calendar = get_room_calendar(args['start_dt'] or today, args['end_dt']
                                     or today, [args['room_id']])
        return jsonify(
            booking=dict(_serialize_booking_details(self.booking),
                         **additional_booking_attrs),
            room_calendar=_serialize_availability(calendar).values())
Ejemplo n.º 2
0
    def _process(self, args):
        data = {
            'booking_reason': args['booking_reason'],
            'room_usage':
            'current_user' if args.get('user_id', None) is None else 'someone',
            'booked_for_user': User.get(args.get('user_id', session.user.id)),
            'start_dt': args['start_dt'],
            'end_dt': args['end_dt'],
            'repeat_frequency': args['repeat_frequency'],
            'repeat_interval': args['repeat_interval'],
        }
        has_date_changed = not has_same_dates(self.booking, data)
        self.booking.modify(data, session.user)

        room = self.booking.room
        if (has_date_changed
                and not room.can_book(session.user, allow_admin=False)
                and room.can_prebook(session.user, allow_admin=False)
                and self.booking.is_accepted):
            self.booking.reset_approval(session.user)
        db.session.flush()

        start_date = args['start_dt']
        end_date = args['end_dt']
        calendar = get_room_calendar(start_date or date.today(), end_date
                                     or date.today(), [args['room_id']])
        return jsonify(
            booking=_serialize_booking_details(self.booking),
            room_calendar=_serialize_availability(calendar).values())