Esempio n. 1
0
 def _process_args(self):
     blocking_id = self._params.get('blocking_id')
     self._room = Room.get(self._params['room_id'])
     self._blocking = Blocking.get(blocking_id) if blocking_id else None
     if 'start_dt' in self._params and 'end_dt' in self._params:
         start_dt = datetime.strptime(self._params['start_dt'], '%H:%M %Y-%m-%d')
         end_dt = datetime.strptime(self._params['end_dt'], '%H:%M %Y-%m-%d')
         self._nonbookable = bool(NonBookablePeriod.find_first(NonBookablePeriod.room_id == self._room.id,
                                                               NonBookablePeriod.overlaps(start_dt, end_dt)))
     else:
         self._nonbookable = False
 def _process_confirm(self):
     # The form needs the room to create the equipment list, so we need to get it "manually"...
     room = Room.get(int(request.form['room_id']))
     form = self._make_confirm_form(room)
     if not room.can_be_booked(session.user) and not room.can_be_prebooked(
             session.user):
         raise Forbidden('You cannot book this room')
     if form.validate_on_submit():
         return self._create_booking_response(form, room)
     # There was an error in the form
     return self._show_confirm(room, form)
    def _process_args(self):
        RHRoomBookingBookingMixin._process_args(self)

        # use 'room' if passed through GET
        room_id = request.args.get('room', None)

        if room_id is None:
            # otherwise default to reservation's
            self._room = self._reservation.room
        else:
            self._room = Room.get(int(room_id))

        if self._room is None:
            raise NotFound(u'This room does not exist')
 def _process_select_period(self):
     form = self._make_select_period_form()
     if form.is_submitted():
         # Errors in here are only caused by users messing with the submitted data so it's not
         # worth making the code more complex to show the errors nicely on the originating page.
         # Doing so would be very hard anyway as we don't keep all data necessary to show step 2
         # when it's not a step 1 form submission.
         if not form.validate():
             raise fossirError(u'<br>'.join(form.error_list))
         room = Room.get(form.room_id.data)
         if not room:
             raise fossirError(u'Invalid room')
         # Show step 3 page
         confirm_form_defaults = FormDefaults(form.data)
         return self._show_confirm(room, form, self._step,
                                   confirm_form_defaults)
Esempio n. 5
0
    def _getParams(self):
        super(BookRoomHook, self)._getParams()
        self._fromDT = utc_to_server(self._fromDT.astimezone(
            pytz.utc)).replace(tzinfo=None) if self._fromDT else None
        self._toDT = utc_to_server(self._toDT.astimezone(pytz.utc)).replace(
            tzinfo=None) if self._toDT else None
        if not self._fromDT or not self._toDT or self._fromDT.date(
        ) != self._toDT.date():
            raise HTTPAPIError('from/to must be on the same day')
        elif self._fromDT >= self._toDT:
            raise HTTPAPIError('to must be after from')
        elif self._fromDT < datetime.now():
            raise HTTPAPIError('You cannot make bookings in the past')

        username = get_query_parameter(self._queryParams, 'username')
        if not username:
            raise HTTPAPIError('No username provided')
        users = User.find_all(~User.is_deleted,
                              Identity.identifier == username)
        if not users:
            raise HTTPAPIError('Username does not exist')
        elif len(users) != 1:
            raise HTTPAPIError('Ambiguous username ({} users found)'.format(
                len(users)))
        user = users[0]

        self._params = {
            'room_id': get_query_parameter(self._queryParams, 'roomid'),
            'reason': get_query_parameter(self._queryParams, 'reason'),
            'booked_for': user,
            'from': self._fromDT,
            'to': self._toDT
        }
        missing = [key for key, val in self._params.iteritems() if not val]
        if missing:
            raise HTTPAPIError('Required params missing: {}'.format(
                ', '.join(missing)))
        self._room = Room.get(self._params['room_id'])
        if not self._room:
            raise HTTPAPIError('A room with this ID does not exist')
 def _process_args(self):
     self._room = Room.get(int(request.view_args['roomID']))
     if self._room is None:
         raise NotFound(u'This room does not exist')
Esempio n. 7
0
 def _process_args(self):
     self._room = Room.get(request.view_args['roomID'])