Example #1
0
def test_find_overlapping_with_different_room(overlapping_occurrences,
                                              create_room):
    db_occ, occ = overlapping_occurrences
    assert db_occ in ReservationOccurrence.find_overlapping_with(
        room=db_occ.reservation.room, occurrences=[occ]).all()
    assert db_occ not in ReservationOccurrence.find_overlapping_with(
        room=create_room(), occurrences=[occ]).all()
Example #2
0
def test_find_overlapping_with_skip_reservation(overlapping_occurrences):
    db_occ, occ = overlapping_occurrences
    assert db_occ in ReservationOccurrence.find_overlapping_with(
        room=db_occ.reservation.room, occurrences=[occ]).all()
    assert db_occ not in ReservationOccurrence.find_overlapping_with(
        room=db_occ.reservation.room,
        occurrences=[occ],
        skip_reservation_id=db_occ.reservation.id).all()
Example #3
0
def test_find_overlapping_with_is_not_valid(db, overlapping_occurrences):
    db_occ, occ = overlapping_occurrences
    assert db_occ in ReservationOccurrence.find_overlapping_with(
        room=db_occ.reservation.room, occurrences=[occ]).all()
    db_occ.is_cancelled = True
    db.session.flush()
    assert db_occ not in ReservationOccurrence.find_overlapping_with(
        room=db_occ.reservation.room, occurrences=[occ]).all()
def test_find_overlapping_with_is_not_valid(db, overlapping_occurrences):
    db_occ, occ = overlapping_occurrences
    assert db_occ in ReservationOccurrence.find_overlapping_with(room=db_occ.reservation.room,
                                                                 occurrences=[occ]).all()
    db_occ.is_cancelled = True
    db.session.flush()
    assert db_occ not in ReservationOccurrence.find_overlapping_with(room=db_occ.reservation.room,
                                                                     occurrences=[occ]).all()
def test_find_overlapping_with_skip_reservation(overlapping_occurrences):
    db_occ, occ = overlapping_occurrences
    assert db_occ in ReservationOccurrence.find_overlapping_with(room=db_occ.reservation.room, occurrences=[occ]).all()
    assert (
        db_occ
        not in ReservationOccurrence.find_overlapping_with(
            room=db_occ.reservation.room, occurrences=[occ], skip_reservation_id=db_occ.reservation.id
        ).all()
    )
def get_prebooking_collisions(reservation):
    from indico.modules.rb.models.reservation_occurrences import ReservationOccurrence
    valid_occurrences = reservation.occurrences.filter(
        ReservationOccurrence.is_valid).all()
    return ReservationOccurrence.find_overlapping_with(reservation.room,
                                                       valid_occurrences,
                                                       reservation.id).all()
Example #7
0
 def get_conflicting_occurrences(self):
     valid_occurrences = self.occurrences.filter(ReservationOccurrence.is_valid).all()
     colliding_occurrences = ReservationOccurrence.find_overlapping_with(self.room, valid_occurrences, self.id).all()
     conflicts = defaultdict(lambda: dict(confirmed=[], pending=[]))
     for occurrence in valid_occurrences:
         for colliding in colliding_occurrences:
             if occurrence.overlaps(colliding):
                 key = 'confirmed' if colliding.reservation.is_accepted else 'pending'
                 conflicts[occurrence][key].append(colliding)
     return conflicts
Example #8
0
 def get_conflicting_occurrences(self):
     valid_occurrences = self.occurrences.filter(ReservationOccurrence.is_valid).all()
     colliding_occurrences = ReservationOccurrence.find_overlapping_with(self.room, valid_occurrences, self.id).all()
     conflicts = defaultdict(lambda: dict(confirmed=[], pending=[]))
     for occurrence in valid_occurrences:
         for colliding in colliding_occurrences:
             if occurrence.overlaps(colliding):
                 key = "confirmed" if colliding.reservation.is_accepted else "pending"
                 conflicts[occurrence][key].append(colliding)
     return conflicts
Example #9
0
 def accept(self, user):
     self.state = ReservationState.accepted
     self.add_edit_log(ReservationEditLog(user_name=user.full_name, info=['Reservation accepted']))
     notify_confirmation(self)
     signals.rb.booking_state_changed.send(self)
     valid_occurrences = self.occurrences.filter(ReservationOccurrence.is_valid).all()
     pre_occurrences = ReservationOccurrence.find_overlapping_with(self.room, valid_occurrences, self.id).all()
     for occurrence in pre_occurrences:
         if not occurrence.is_valid:
             continue
         occurrence.reject(user, u'Rejected due to collision with a confirmed reservation')
Example #10
0
    def accept(self, user):
        self.is_accepted = True
        self.add_edit_log(ReservationEditLog(user_name=user.full_name, info=["Reservation accepted"]))
        notify_confirmation(self)

        valid_occurrences = self.occurrences.filter(ReservationOccurrence.is_valid).all()
        pre_occurrences = ReservationOccurrence.find_overlapping_with(self.room, valid_occurrences, self.id).all()
        for occurrence in pre_occurrences:
            if not occurrence.is_valid:
                continue
            occurrence.reject(user, u"Rejected due to collision with a confirmed reservation")
Example #11
0
    def _get_all_conflicts(self, room, form, reservation_id=None):
        conflicts = defaultdict(list)
        pre_conflicts = defaultdict(list)

        candidates = ReservationOccurrence.create_series(form.start_dt.data, form.end_dt.data,
                                                         (form.repeat_frequency.data, form.repeat_interval.data))
        occurrences = ReservationOccurrence.find_overlapping_with(room, candidates, reservation_id).all()

        for cand in candidates:
            for occ in occurrences:
                if cand.overlaps(occ):
                    if occ.reservation.is_accepted:
                        conflicts[cand].append(occ)
                    else:
                        pre_conflicts[cand].append(occ)

        return conflicts, pre_conflicts
Example #12
0
    def _get_all_conflicts(self, room, form, reservation_id=None):
        conflicts = defaultdict(list)
        pre_conflicts = defaultdict(list)

        candidates = ReservationOccurrence.create_series(form.start_dt.data, form.end_dt.data,
                                                         (form.repeat_frequency.data, form.repeat_interval.data))
        occurrences = ReservationOccurrence.find_overlapping_with(room, candidates, reservation_id).all()

        for cand in candidates:
            for occ in occurrences:
                if cand.overlaps(occ):
                    if occ.reservation.is_accepted:
                        conflicts[cand].append(occ)
                    else:
                        pre_conflicts[cand].append(occ)

        return conflicts, pre_conflicts
Example #13
0
    def accept(self, user):
        self.is_accepted = True
        self.add_edit_log(
            ReservationEditLog(user_name=user.getFullName(),
                               info=['Reservation accepted']))
        notify_confirmation(self)

        valid_occurrences = self.occurrences.filter(
            ReservationOccurrence.is_valid).all()
        pre_occurrences = ReservationOccurrence.find_overlapping_with(
            self.room, valid_occurrences, self.id).all()
        for occurrence in pre_occurrences:
            if not occurrence.is_valid:
                continue
            occurrence.reject(
                user,
                u'Rejected due to collision with a confirmed reservation')
Example #14
0
def get_room_conflicts(room, start_dt, end_dt, repeat_frequency, repeat_interval):
    conflicts = []
    pre_conflicts = []

    candidates = ReservationOccurrence.create_series(start_dt, end_dt, (repeat_frequency, repeat_interval))
    occurrences = ReservationOccurrence.find_overlapping_with(room, candidates).all()

    ReservationOccurrenceTmp = namedtuple('ReservationOccurrenceTmp', ('start_dt', 'end_dt', 'reservation'))
    for candidate in candidates:
        for occurrence in occurrences:
            if candidate.overlaps(occurrence):
                overlap = candidate.get_overlap(occurrence)
                obj = ReservationOccurrenceTmp(*overlap, reservation=occurrence.reservation)
                if occurrence.reservation.is_accepted:
                    conflicts.append(obj)
                else:
                    pre_conflicts.append(obj)
    return conflicts, pre_conflicts
def test_find_overlapping_with_different_room(overlapping_occurrences, create_room):
    db_occ, occ = overlapping_occurrences
    assert db_occ in ReservationOccurrence.find_overlapping_with(room=db_occ.reservation.room, occurrences=[occ]).all()
    assert db_occ not in ReservationOccurrence.find_overlapping_with(room=create_room(), occurrences=[occ]).all()