class RHUpdateRoomAvailability(RHRoomAdminBase): @use_args({ 'bookable_hours': fields.Nested({ 'start_time': fields.Time(), 'end_time': fields.Time() }, many=True), 'nonbookable_periods': fields.Nested({ 'start_dt': fields.Date(), 'end_dt': fields.Date() }, many=True) }) def _process(self, args): if 'bookable_hours' in args: self._check_invalid_times(args) update_room_availability(self.room, args) return jsonify(nonbookable_periods=nonbookable_periods_schema.dump( self.room.nonbookable_periods, many=True), bookable_hours=bookable_hours_schema.dump( self.room.bookable_hours, many=True)) def _check_invalid_times(self, availability): if any(bh['start_time'] >= bh['end_time'] for bh in availability['bookable_hours']): abort(422, messages={ 'bookable_hours': [_('Start time should not be later than end time')] })
@APP.teardown_appcontext def shutdown_session(exception=None): """ This ties into sqlalchemy to make sure that each API session has an independent DB session. """ DB_SESSION.remove() @APP.route('/data/alert_events') @use_args({ 'startDate': fields.Date(required=True), 'endDate': fields.Date(required=True), 'startTime': fields.Time(required=True), 'endTime': fields.Time(required=True), }) def get_alert_events(args): """ This end point will respond with a list of alert events within the given range. Date and Time values are independent. For example, a query for all the events in the past year within the hours of 7am and 7pm will not return an event at 8pm yesterday, but it will return an event at 6pm yesterday. :args: The dict from webargs containing the args above - startDate: The first day of events to look at (inclusive). - endDate: The last day of events to look at (inclusive).