def _process(self): form = self._form if self._is_submitted() and form.validate(): if form.data.get('is_only_my_rooms'): form.room_ids.data = [ room.id for room in Room.find_all() if room.is_owned_by(session.user) ] occurrences = ReservationOccurrence.find_with_filters( form.data, session.user).all() rooms = self._filter_displayed_rooms( [r for r in self._rooms if r.id in set(form.room_ids.data)], occurrences) return WPRoomBookingSearchBookingsResults( self, rooms=rooms, occurrences=occurrences, show_blockings=self.show_blockings, start_dt=form.start_dt.data, end_dt=form.end_dt.data, form=form, form_data=self._form_data, menu_item=self.menu_item).display() my_rooms = [r.id for r in Room.get_owned_by(session.user)] return WPRoomBookingSearchBookings(self, errors=form.error_list, rooms=self._rooms, my_rooms=my_rooms, form=form).display()
def _main(location): yesterday = date.today() - relativedelta(days=1) past_month = yesterday - relativedelta(days=29) past_year = yesterday - relativedelta(years=1) if not location: rooms = Room.find_all() else: rooms = Room.find_all(Location.name.in_(location), _join=Location) print 'Month\tYear\tPublic?\tRoom' for room in rooms: print '{2:.2f}%\t{3:.2f}%\t{1}\t{0}'.format( room.full_name, "Y" if room.is_public else "N", calculate_rooms_occupancy([room], past_month, yesterday) * 100, calculate_rooms_occupancy([room], past_year, yesterday) * 100)
def _getAnswer(self): if not config.ENABLE_ROOMBOOKING: return {} criteria = {'_eager': Room.location} if self._isActive is not None: criteria['is_active'] = self._isActive rooms = Room.find_all(**criteria) return {room.id: '{}: {}'.format(room.location_name, room.full_name) for room in rooms}
def test_find_with_filters_details_cols(db, dummy_room, create_room, col): create_room() # some room we won't find! assert set(Room.find_with_filters({}, None)) == set(Room.find_all()) assert not Room.find_with_filters({'details': u'meow'}, None) setattr(dummy_room, col, u'meow') db.session.flush() assert set(Room.find_with_filters({'details': u'meow'}, None)) == {dummy_room}
def _make_select_room_form(self): # Step 1 self._rooms = sorted(Room.find_all(is_active=True), key=lambda r: natural_sort_key(r.full_name)) form_obj, self.date_changed = self._get_select_room_form_defaults() form = NewBookingCriteriaForm(obj=form_obj) form.room_ids.choices = [(r.id, None) for r in self._rooms] return form
def test_find_with_filters_details_values(db, dummy_room, create_room, value, search_value, other_value): other_room = create_room() assert set(Room.find_with_filters({}, None)) == set(Room.find_all()) assert not Room.find_with_filters({'details': search_value}, None) dummy_room.comments = value other_room.comments = other_value db.session.flush() assert set(Room.find_with_filters({'details': search_value}, None)) == {dummy_room}
def test_find_with_attribute(dummy_room, create_room, create_room_attribute): assert Room.find_all() == [dummy_room] # one room without the attribute assert not Room.find_with_attribute(u'foo') create_room_attribute(u'foo') assert not Room.find_with_attribute(u'foo') expected = set() for room in [create_room(), create_room()]: value = u'bar-{}'.format(room.id) room.set_attribute_value(u'foo', value) expected.add((room, value)) assert set(Room.find_with_attribute(u'foo')) == expected
def test_find_with_filters_details_attrs(dummy_room, create_room, create_room_attribute, value, search_value, other_value): other_room = create_room() assert set(Room.find_with_filters({}, None)) == set(Room.find_all()) assert not Room.find_with_filters({'details': search_value}, None) create_room_attribute(u'foo') assert not Room.find_with_filters({'details': search_value}, None) dummy_room.set_attribute_value(u'foo', value) other_room.set_attribute_value(u'foo', other_value) assert set(Room.find_with_filters({'details': search_value}, None)) == {dummy_room}
def _process(self): room = self._room rooms = Room.find_all() form = self._make_form() if form.is_submitted() and not form.validate(): occurrences = {} candidates = {} conflicts = {} pre_conflicts = {} only_conflicts = False else: occurrences, candidates = self._get_all_occurrences( [self._room.id], form) conflicts, pre_conflicts = self._get_all_conflicts( self._room, form) candidate_days = { occ.date for candidate in candidates.itervalues() for occ in candidate } conflicting_days = {occ.date for occ in conflicts.iterkeys()} only_conflicts = candidate_days <= conflicting_days if form.validate_on_submit() and not form.submit_check.data: booking_limit_days = room.booking_limit_days or rb_settings.get( 'booking_limit') if not self._validate_room_booking_limit(form, booking_limit_days): msg = (_( u'Bookings for the room "{}" may not be longer than {} days' ).format(room.name, booking_limit_days)) return jsonify(success=False, url=url_for('rooms.room_book', room), msg=msg) return self._create_booking_response(form, room) can_override = room.can_be_overridden(session.user) return self._get_view(form=form, room=room, rooms=rooms, occurrences=occurrences, candidates=candidates, conflicts=conflicts, only_conflicts=only_conflicts, pre_conflicts=pre_conflicts, start_dt=form.start_dt.data, end_dt=form.end_dt.data, repeat_frequency=form.repeat_frequency.data, repeat_interval=form.repeat_interval.data, can_override=can_override, past_date=not form.is_submitted() and self.past_date, date_changed=not form.is_submitted() and self.date_changed).display()
def test_find_with_filters_capacity(db, dummy_room, create_room, capacity, other_capacity, search_capacity, match, match_other): other_room = create_room() assert set(Room.find_with_filters({}, None)) == set(Room.find_all()) dummy_room.capacity = capacity other_room.capacity = other_capacity db.session.flush() expected = set() if match: expected.add(dummy_room) if match_other: expected.add(other_room) assert set(Room.find_with_filters({'capacity': search_capacity}, None)) == expected
def test_filter_available(dummy_room, create_reservation, create_blocking, has_booking, has_blocking, has_pre_booking, include_pre_bookings, has_pending_blocking, include_pending_blockings, filtered): if has_booking: create_reservation(start_dt=datetime.combine(date.today(), time(8)), end_dt=datetime.combine(date.today(), time(10))) if has_pre_booking: create_reservation(start_dt=datetime.combine(date.today(), time(10)), end_dt=datetime.combine(date.today(), time(12)), is_accepted=False) if has_blocking: create_blocking(state=BlockedRoom.State.accepted) if has_pending_blocking: create_blocking(state=BlockedRoom.State.pending) availabilty_filter = Room.filter_available( get_day_start(date.today()), get_day_end(date.today()), (RepeatFrequency.NEVER, 0), include_pre_bookings=include_pre_bookings, include_pending_blockings=include_pending_blockings) assert set(Room.find_all(availabilty_filter)) == (set() if filtered else {dummy_room})
def _process(self): if self._overload: rooms = [] occurrences = [] else: rooms = Room.find_all(is_active=True) occurrences = (ReservationOccurrence.find( Reservation.room_id.in_(room.id for room in rooms), ReservationOccurrence.start_dt >= self.start_dt, ReservationOccurrence.end_dt <= self.end_dt, ReservationOccurrence.is_valid, _join=ReservationOccurrence.reservation, _eager=ReservationOccurrence.reservation).options( ReservationOccurrence.NO_RESERVATION_USER_STRATEGY).all()) return WPRoomBookingCalendar(self, rooms=rooms, occurrences=occurrences, start_dt=self.start_dt, end_dt=self.end_dt, overload=self._overload, max_days=self.MAX_DAYS).display()
def test_find_with_filters_equipment(db, dummy_room, create_room, create_equipment_type): other_room = create_room() assert set(Room.find_with_filters({}, None)) == set(Room.find_all()) eq1 = create_equipment_type(u'eq1') eq2 = create_equipment_type(u'eq2') assert not Room.find_with_filters({'available_equipment': {eq1}}, None) dummy_room.available_equipment.append(eq1) db.session.flush() assert set(Room.find_with_filters({'available_equipment': {eq1}}, None)) == {dummy_room} assert not Room.find_with_filters({'available_equipment': {eq1, eq2}}, None) dummy_room.available_equipment.append(eq2) other_room.available_equipment.append(eq2) db.session.flush() assert set(Room.find_with_filters({'available_equipment': {eq1}}, None)) == {dummy_room} assert set(Room.find_with_filters({'available_equipment': {eq2}}, None)) == {dummy_room, other_room} assert set( Room.find_with_filters({'available_equipment': {eq1, eq2}}, None)) == {dummy_room}
def test_find_all(create_location, create_room): # Here we just test if we get the rooms in natural sort order loc1 = create_location('Z') loc2 = create_location('A') data = [(2, dict(location=loc1, building=u'1', floor=u'2', number=u'3', name=u'')), (3, dict(location=loc1, building=u'2', floor=u'2', number=u'3', name=u'')), (5, dict(location=loc1, building=u'100', floor=u'2', number=u'3', name=u'')), (4, dict(location=loc1, building=u'10', floor=u'2', number=u'3', name=u'')), (1, dict(location=loc2, building=u'999', floor=u'2', number=u'3', name=u''))] rooms = [(pos, create_room(**params)) for pos, params in data] sorted_rooms = map(itemgetter(1), sorted(rooms, key=itemgetter(0))) assert sorted_rooms == Room.find_all()
def _process_args(self): self._rooms = sorted(Room.find_all(is_active=True), key=lambda r: natural_sort_key(r.full_name)) self._form_data = self._get_form_data() self._form = BookingSearchForm(self._form_data, csrf_enabled=False) self._form.room_ids.choices = [(r.id, None) for r in self._rooms]
def _getAnswer(self): rooms = Room.find_all(Room.filter_available(self._start_dt, self._end_dt, self._repetition)) return [room.id for room in rooms]
def _process(self): room = self._reservation.room form = ModifyBookingForm(obj=self._reservation, old_start_dt=self._reservation.start_dt, old_end_dt=self._reservation.end_dt) form.used_equipment.query = room.find_available_vc_equipment() if not room.notification_for_assistance and not self._reservation.needs_assistance: del form.needs_assistance invalid_form = form.is_submitted() and not form.validate() if invalid_form: occurrences = {} candidates = {} conflicts = {} pre_conflicts = {} else: occurrences, candidates = self._get_all_occurrences( [room.id], form, reservation_id=self._reservation.id) conflicts, pre_conflicts = self._get_all_conflicts( room, form, self._reservation.id) if form.validate_on_submit() and not form.submit_check.data: try: booking_limit_days = room.booking_limit_days or rb_settings.get( 'booking_limit') if not self._validate_room_booking_limit( form, booking_limit_days): msg = (_( u'Bookings for the room "{}" may not be longer than {} days' ).format(room.name, booking_limit_days)) return jsonify(success=False, url=url_for( 'rooms.roomBooking-modifyBookingForm', self._reservation), msg=msg) self._reservation.modify(form.data, session.user) flash(_(u'Booking updated'), 'success') except NoReportError as e: db.session.rollback() return jsonify(success=False, msg=unicode(e)) return jsonify(success=True, url=self._get_success_url()) elif invalid_form and not form.submit_check.data and request.is_xhr: return jsonify(success=False, msg='\n'.join(form.error_list)) return self._get_view(form=form, room=room, rooms=Room.find_all(), occurrences=occurrences, candidates=candidates, conflicts=conflicts, pre_conflicts=pre_conflicts, start_dt=form.start_dt.data, end_dt=form.end_dt.data, only_conflicts=False, repeat_frequency=form.repeat_frequency.data, repeat_interval=form.repeat_interval.data, reservation=self._reservation, can_override=room.can_be_overridden( session.user)).display()