agendas: always order partial booking checks (#83544)
gitea/chrono/pipeline/head Build queued... Details

This commit is contained in:
Valentin Deniaud 2023-11-22 11:41:39 +01:00
parent 46e6fbcf5b
commit 7182871b9f
3 changed files with 6 additions and 2 deletions

View File

@ -33,5 +33,8 @@ class Migration(migrations.Migration):
),
),
],
options={
'ordering': ['start_time'],
},
),
]

View File

@ -3020,7 +3020,7 @@ class Booking(models.Model):
def refresh_computed_times(self, commit=False):
to_update = []
user_checks = sorted(self.user_checks.all(), key=lambda a: a.start_time or datetime.time(0))
user_checks = self.user_checks.all()
if len(user_checks) == 1:
user_check = user_checks[0]
@ -3158,6 +3158,7 @@ class BookingCheck(models.Model):
type_label = models.CharField(max_length=150, blank=True, null=True)
class Meta:
ordering = ['start_time']
constraints = [
models.UniqueConstraint(fields=['booking', 'presence'], name='max_2_checks_on_booking')
]

View File

@ -2339,7 +2339,7 @@ class MultipleAgendasEventsCheckStatus(APIView):
booking_queryset = Booking.objects.filter(
event__in=events,
user_external_id=user_external_id,
).prefetch_related(Prefetch('user_checks', queryset=BookingCheck.objects.order_by('start_time')))
).prefetch_related('user_checks')
bookings_by_event_id = collections.defaultdict(list)
for booking in booking_queryset:
bookings_by_event_id[booking.event_id].append(booking)