0001-manager-hide-secondary-bookings-during-event-check-5.patch
chrono/manager/templates/chrono/manager_event_check.html | ||
---|---|---|
11 | 11 |
{% block content %} |
12 | 12 |
<div class="section"> |
13 | 13 |
<h3> |
14 |
{% blocktrans with places=object.places booked_places=booked|length %}Bookings ({{ booked_places }}/{{ places }}){% endblocktrans %}
|
|
14 |
{% blocktrans with places=object.places %}Bookings ({{ booked_places }}/{{ places }}){% endblocktrans %} |
|
15 | 15 |
</h3> |
16 | 16 |
<div> |
17 | 17 |
<form class="check-bookings-filters"> |
... | ... | |
76 | 76 |
{% if object.waiting_list_places %} |
77 | 77 |
<div class="section"> |
78 | 78 |
<h3> |
79 |
{% blocktrans with places=object.waiting_list_places booked_places=waiting|length %}Waiting List ({{ booked_places }}/{{ places }}){% endblocktrans %}
|
|
79 |
{% blocktrans with places=object.waiting_list_places %}Waiting List ({{ waiting_places }}/{{ places }}){% endblocktrans %}
|
|
80 | 80 |
</h3> |
81 | 81 |
<div> |
82 | 82 |
<table class="main check-bookings"> |
83 | 83 |
<tbody> |
84 | 84 |
{% for booking in waiting %} |
85 |
<tr><td class="booking-username">{{ booking.get_user_block }}</td></tr>
|
|
85 |
<tr><td class="booking-username waiting">{{ booking.get_user_block }}{% if booking.places_count > 1 %} ({{ booking.places_count }} {% trans "places" %}){% endif %}</td></tr>
|
|
86 | 86 |
{% endfor %} |
87 | 87 |
</tbody> |
88 | 88 |
</table> |
chrono/manager/templates/chrono/manager_event_check_booking_fragment.html | ||
---|---|---|
1 | 1 |
{% load i18n %} |
2 | 2 | |
3 |
<td class="booking-username">{{ booking.get_user_block }}</td>
|
|
3 |
<td class="booking-username main-list">{{ booking.get_user_block }}{% if booking.places_count > 1 %} ({{ booking.places_count }} {% trans "places" %}){% endif %}</td>
|
|
4 | 4 |
<td class="booking-status {% if booking.user_was_present is None %}without-status{% endif %}"> |
5 | 5 |
{{ booking.user_was_present|yesno:_('Present,Absent,-') }} |
6 | 6 |
{% if booking.user_was_present is False and booking.user_absence_reason %} |
chrono/manager/views.py | ||
---|---|---|
25 | 25 |
from django.contrib import messages |
26 | 26 |
from django.core.exceptions import PermissionDenied |
27 | 27 |
from django.db import transaction |
28 |
from django.db.models import BooleanField, Max, Min, Q, Value
|
|
28 |
from django.db.models import BooleanField, Count, Max, Min, Q, Sum, Value
|
|
29 | 29 |
from django.http import Http404, HttpResponse, HttpResponseRedirect |
30 | 30 |
from django.shortcuts import get_object_or_404, redirect, render |
31 | 31 |
from django.template.defaultfilters import title |
... | ... | |
2013 | 2013 |
context = super().get_context_data(**kwargs) |
2014 | 2014 | |
2015 | 2015 |
event = self.object |
2016 |
booked_qs = event.booking_set.filter(cancellation_datetime__isnull=True, in_waiting_list=False) |
|
2016 |
booked_qs = event.booking_set.filter( |
|
2017 |
cancellation_datetime__isnull=True, in_waiting_list=False, primary_booking__isnull=True |
|
2018 |
) |
|
2019 |
booked_qs = booked_qs.annotate( |
|
2020 |
places_count=Value(1) |
|
2021 |
+ Count('secondary_booking_set', filter=Q(cancellation_datetime__isnull=True)) |
|
2022 |
) |
|
2017 | 2023 |
filterset = BookingCheckFilterSet(self.request.GET, queryset=booked_qs, agenda=self.agenda) |
2018 | 2024 |
context['filterset'] = filterset |
2019 | 2025 | |
2020 | 2026 |
# build booking list |
2021 | 2027 |
context['booked'] = filterset.qs.order_by('user_last_name', 'user_first_name') |
2028 |
context['booked_places'] = context['booked'].aggregate(places=Sum('places_count'))['places'] |
|
2022 | 2029 |
context['booked_without_status'] = any(e.user_was_present is None for e in context['booked']) |
2023 | 2030 |
if context['booked_without_status']: |
2024 | 2031 |
context['absence_form'] = BookingAbsenceReasonForm(agenda=self.agenda) |
... | ... | |
2026 | 2033 |
booking.form = BookingAbsenceReasonForm( |
2027 | 2034 |
agenda=self.agenda, initial={'reason': booking.user_absence_reason} |
2028 | 2035 |
) |
2029 |
context['waiting'] = event.booking_set.filter(
|
|
2030 |
cancellation_datetime__isnull=True, in_waiting_list=True |
|
2036 |
waiting_qs = event.booking_set.filter(
|
|
2037 |
cancellation_datetime__isnull=True, in_waiting_list=True, primary_booking__isnull=True
|
|
2031 | 2038 |
).order_by('user_last_name', 'user_first_name') |
2039 |
waiting_qs = waiting_qs.annotate( |
|
2040 |
places_count=Value(1) |
|
2041 |
+ Count('secondary_booking_set', filter=Q(cancellation_datetime__isnull=True)) |
|
2042 |
) |
|
2043 |
context['waiting'] = waiting_qs |
|
2044 |
context['waiting_places'] = waiting_qs.aggregate(places=Sum('places_count'))['places'] |
|
2032 | 2045 | |
2033 | 2046 |
return context |
2034 | 2047 |
tests/manager/test_event.py | ||
---|---|---|
1555 | 1555 |
params={'csrfmiddlewaretoken': token}, |
1556 | 1556 |
status=404, |
1557 | 1557 |
) |
1558 | ||
1559 | ||
1560 |
def test_event_check_primary_booking(app, admin_user): |
|
1561 |
group = AbsenceReasonGroup.objects.create(label='Foo bar') |
|
1562 |
agenda = Agenda.objects.create(label='Events', kind='events') |
|
1563 |
event = Event.objects.create( |
|
1564 |
label='xyz', |
|
1565 |
start_datetime=now() - datetime.timedelta(days=1), |
|
1566 |
places=10, |
|
1567 |
waiting_list_places=5, |
|
1568 |
agenda=agenda, |
|
1569 |
) |
|
1570 |
booking = Booking.objects.create(event=event, user_first_name='User', user_last_name='42') |
|
1571 |
booking_2 = Booking.objects.create(event=event, user_first_name='John', user_last_name='Doe') |
|
1572 |
booking_3 = Booking.objects.create( |
|
1573 |
event=event, user_first_name='Jane', user_last_name='Doe', in_waiting_list=True |
|
1574 |
) |
|
1575 |
# create secondary bookings |
|
1576 |
Booking.objects.create(event=event, user_first_name='User', user_last_name='42', primary_booking=booking) |
|
1577 |
Booking.objects.create(event=event, user_first_name='User', user_last_name='42', primary_booking=booking) |
|
1578 |
Booking.objects.create( |
|
1579 |
event=event, |
|
1580 |
user_first_name='Jane', |
|
1581 |
user_last_name='Doe', |
|
1582 |
primary_booking=booking_3, |
|
1583 |
in_waiting_list=True, |
|
1584 |
) |
|
1585 | ||
1586 |
login(app) |
|
1587 |
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk)) |
|
1588 |
assert 'Bookings (4/10)' in resp.text |
|
1589 |
user_bookings = resp.pyquery.find('td.booking-username.main-list') |
|
1590 |
assert len(user_bookings) == 2 |
|
1591 |
assert user_bookings[0].text == 'User 42 (3 places)' |
|
1592 |
assert user_bookings[1].text == 'John Doe' |
|
1593 | ||
1594 |
assert 'Waiting List (2/5)' in resp.text |
|
1595 |
user_bookings = resp.pyquery.find('td.booking-username.waiting') |
|
1596 |
assert len(user_bookings) == 1 |
|
1597 |
assert user_bookings[0].text == 'Jane Doe (2 places)' |
|
1558 |
- |