Ejemplo n.º 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))
            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))

        serialized_occurrences = serialize_occurrences(group_by_occurrence_date(resv.occurrences.all()))
        if is_prebooking:
            data = {'pre_bookings': serialized_occurrences}
        else:
            data = {'bookings': serialized_occurrences}
        return jsonify(room_id=room.id, **data)
Ejemplo n.º 2
0
    def _process(self):
        args = self.args
        args.setdefault('booked_for_user', session.user)

        if not is_booking_start_within_grace_period(args['start_dt'], session.user, args['admin_override_enabled']):
            raise ExpectedError(_('You cannot create a booking which starts in the past'))

        # Check that the booking is not longer than allowed
        booking_limit_days = self.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(self.room.name, booking_limit_days))
            raise ExpectedError(msg)

        try:
            resv = Reservation.create_from_data(self.room, args, session.user, prebook=self.prebook)
            if args.get('link_type') is not None and args.get('link_id') is not None:
                self._link_booking(resv, args['link_type'], args['link_id'], args['link_back'])
            db.session.flush()
        except NoReportError as e:
            db.session.rollback()
            raise ExpectedError(unicode(e))

        serialized_occurrences = serialize_occurrences(group_by_occurrence_date(resv.occurrences.all()))
        if self.prebook:
            data = {'pre_bookings': serialized_occurrences}
        else:
            data = {'bookings': serialized_occurrences}
        return jsonify(room_id=self.room.id, booking=reservation_details_schema.dump(resv), calendar_data=data)
Ejemplo n.º 3
0
    def _process(self):
        args = self.args
        user_id = args.pop('user_id', None)
        booked_for = User.get_one(user_id, is_deleted=False) if user_id else session.user

        # Check that the booking is not longer than allowed
        booking_limit_days = self.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(self.room.name, booking_limit_days))
            raise ExpectedError(msg)

        try:
            resv = Reservation.create_from_data(self.room, dict(args, booked_for_user=booked_for), session.user,
                                                prebook=self.prebook)
            if args.get('link_type') is not None and args.get('link_id') is not None:
                self._link_booking(resv, args['link_type'], args['link_id'], args['link_back'])
            db.session.flush()
        except NoReportError as e:
            db.session.rollback()
            raise ExpectedError(unicode(e))

        serialized_occurrences = serialize_occurrences(group_by_occurrence_date(resv.occurrences.all()))
        if self.prebook:
            data = {'pre_bookings': serialized_occurrences}
        else:
            data = {'bookings': serialized_occurrences}
        return jsonify(room_id=self.room.id, booking=reservation_details_schema.dump(resv).data, calendar_data=data)
Ejemplo n.º 4
0
 def accept(self, reason=None, force=False):
     if not force:
         collisions = get_prebooking_collisions(self.booking)
         if collisions:
             collision_data = reservation_occurrences_schema.dump(collisions)
             raise ExpectedError('prebooking_collision', data=collision_data)
     self.booking.accept(session.user, reason)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def _process_POST(self):
        if not self._can_register():
            raise ExpectedError(_('You cannot register for this event'))

        schema = make_registration_schema(self.regform)()
        form_data = parser.parse(schema)
        registration = create_registration(self.regform, form_data, self.invitation)
        return jsonify({'redirect': url_for('.display_regform', registration.locator.registrant)})
Ejemplo n.º 7
0
    def _process_DELETE(self):
        if EditingRevisionFile.query.with_parent(self.file_type).has_rows():
            raise ExpectedError(
                _('Cannot delete file type which already has files'))

        review_conditions = editing_settings.get(self.event,
                                                 'review_conditions')
        if any(self.file_type.id in cond for cond in review_conditions):
            raise ExpectedError(
                _('Cannot delete file type which is used in a review condition'
                  ))
        if self.file_type.publishable:
            is_last = not (EditingFileType.query.with_parent(
                self.event).filter(
                    EditingFileType.publishable,
                    EditingFileType.id != self.file_type.id).has_rows())
            if is_last:
                raise ExpectedError(
                    _('Cannot delete the only publishable file type'))
        delete_file_type(self.file_type)
        return '', 204
Ejemplo n.º 8
0
    def _checkSplitRooms(self, room, occs):

        if room in self.splitmap:
            for ri in self.splitmap[room]:
                oroom = Room.get_or_404(ri, is_deleted=False)
                overlap = Reservation.find_overlapping_with(oroom, occs).all()
                if overlap:
                    raise ExpectedError(
                        'Overlaps with other reservations in {}.'.format(
                            oroom.name))

        else:
            for ri, splits in self.splitmap.items():
                if room in splits:
                    oroom = Room.get_or_404(ri, is_deleted=False)
                    overlap = Reservation.find_overlapping_with(oroom,
                                                                occs).all()
                    if overlap:
                        raise ExpectedError(
                            'Overlaps with other reservations in {}.'.format(
                                oroom.name))
                    break
Ejemplo n.º 9
0
 def _process_DELETE(self):
     # XXX: we could safely allow deleting any locations regardless of whether there
     # are rooms now that we soft-delete them. but it's probably safer to disallow
     # deletion of locations with rooms, simply to prevent accidental deletions.
     if self.location.rooms:
         raise ExpectedError(_('Cannot delete location with active rooms'))
     self.location.is_deleted = True
     logger.info('Location %r deleted by %r', self.location, session.user)
     # this code currently doesn't do anything since we don't allow deleting locations
     # that have non-deleted rooms, but if we change this in the future it's needed
     for room in self.location.rooms:
         logger.info('Deleting room %r', room)
         room.is_deleted = True
     db.session.flush()
     return '', 204