Пример #1
0
    def _process(self, args):
        room = Room.get_one(args.pop('room_id'))
        user_id = args.pop('user_id', None)
        booked_for = User.get_one(user_id) if user_id else session.user
        is_prebooking = args.pop('is_prebooking')

        # Check that the booking is not longer than allowed
        booking_limit_days = room.booking_limit_days or rb_settings.get(
            'booking_limit')
        if not self._validate_room_booking_limit(
                args['start_dt'], args['end_dt'], booking_limit_days):
            msg = (
                _('Bookings for the room "{}" may not be longer than {} days'
                  ).format(room.name, booking_limit_days))
            return jsonify(success=False, msg=msg)

        try:
            resv = Reservation.create_from_data(
                room,
                dict(args, booked_for_user=booked_for),
                session.user,
                prebook=is_prebooking)
            db.session.flush()
        except NoReportError as e:
            db.session.rollback()
            raise ExpectedError(unicode(e))
        return jsonify(booking=reservation_schema.dump(resv).data)
Пример #2
0
    def _process(self, args):
        room = Room.get_one(args.pop('room_id'))
        user_id = args.pop('user_id', None)
        booked_for = User.get_one(user_id) if user_id else session.user
        is_prebooking = args.pop('is_prebooking')

        # Check that the booking is not longer than allowed
        booking_limit_days = room.booking_limit_days or rb_settings.get('booking_limit')
        if not self._validate_room_booking_limit(args['start_dt'], args['end_dt'], booking_limit_days):
            msg = (_('Bookings for the room "{}" may not be longer than {} days')
                   .format(room.name, booking_limit_days))
            raise ExpectedError(msg)

        try:
            resv = Reservation.create_from_data(room, dict(args, booked_for_user=booked_for), session.user,
                                                prebook=is_prebooking)
            db.session.flush()
        except NoReportError as e:
            db.session.rollback()
            raise ExpectedError(unicode(e))
        return jsonify(room_id=room.id, booking=reservation_schema.dump(resv).data,
                       occurrences=serialize_occurrences(group_by_occurrence_date(resv.occurrences.all())))