manager: allow multiple partial bookings for one user on the same day (#80050)
This commit is contained in:
parent
11ef5b4bd2
commit
7c34e4fe7f
|
@ -28,23 +28,23 @@
|
|||
</div>
|
||||
|
||||
<div class="partial-booking--registrant-items">
|
||||
{% for booking in results %}
|
||||
{% for user in users %}
|
||||
<section class="partial-booking--registrant">
|
||||
{% spaceless %}
|
||||
<h3 class="registrant--name">
|
||||
{% if booking.kind == "booking" and allow_check %}
|
||||
{% if user.bookings and allow_check %}
|
||||
<a
|
||||
rel="popup"
|
||||
href="{% url 'chrono-manager-partial-booking-check' pk=agenda.pk booking_pk=booking.pk %}"
|
||||
>{{ booking.get_user_block }}</a>
|
||||
href="{% url 'chrono-manager-partial-booking-check' pk=agenda.pk booking_pk=user.bookings.0.pk %}"
|
||||
>{{ user.name }}</a>
|
||||
{% else %}
|
||||
<span>{{ booking.get_user_block }}</span>
|
||||
<span>{{ user.name }}</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
{% endspaceless %}
|
||||
<div class="registrant--datas">
|
||||
{% if booking.kind == "booking" %}
|
||||
<div class="registrant--bar-container">
|
||||
<div class="registrant--bar-container">
|
||||
{% for booking in user.bookings %}
|
||||
<p
|
||||
class="registrant--bar booking"
|
||||
title="{% trans "Booked period" %}"
|
||||
|
@ -55,24 +55,28 @@
|
|||
–
|
||||
<time datetime="{{ booking.end_time|time:"H:i" }}">{{ booking.end_time|time:"H:i" }}</time>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if booking.user_was_present is not None %}
|
||||
<div class="registrant--bar-container">
|
||||
<p
|
||||
class="registrant--bar check {{ booking.check_css_class }}"
|
||||
title="{% trans "Checked period" %}"
|
||||
style="left: {{ booking.check_css_left }}%; width: {{ booking.check_css_width }}%;"
|
||||
>
|
||||
<strong class="sr-only">{% trans "Checked period:" %}</strong>
|
||||
<time datetime="{{ booking.user_check_start_time|time:"H:i" }}">{{ booking.user_check_start_time|time:"H:i" }}</time>
|
||||
–
|
||||
<time datetime="{{ booking.user_check_end_time|time:"H:i" }}">{{ booking.user_check_end_time|time:"H:i" }}</time>
|
||||
{% if booking.user_check_type_label %}<span>{{ booking.user_check_type_label }}</span>{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% if booking.computed_start_time != None and booking.computed_end_time != None %}
|
||||
<div class="registrant--bar-container">
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="registrant--bar-container">
|
||||
{% for booking in user.bookings %}
|
||||
{% if booking.user_was_present is not None %}
|
||||
<p
|
||||
class="registrant--bar check {{ booking.check_css_class }}"
|
||||
title="{% trans "Checked period:" %}"
|
||||
style="left: {{ booking.check_css_left }}%; width: {{ booking.check_css_width }}%;"
|
||||
>
|
||||
<strong class="sr-only">{% trans "Checked period:" %}</strong>
|
||||
<time datetime="{{ booking.user_check_start_time|time:"H:i" }}">{{ booking.user_check_start_time|time:"H:i" }}</time>
|
||||
–
|
||||
<time datetime="{{ booking.user_check_end_time|time:"H:i" }}">{{ booking.user_check_end_time|time:"H:i" }}</time>
|
||||
{% if booking.user_check_type_label %}<span>{{ booking.user_check_type_label }}</span>{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="registrant--bar-container">
|
||||
{% for booking in user.bookings %}
|
||||
{% if booking.user_was_present is not None and booking.computed_start_time != None and booking.computed_end_time != None %}
|
||||
<p
|
||||
class="registrant--bar computed {{ booking.check_css_class }}"
|
||||
title="{% trans "Computed period" %}"
|
||||
|
@ -83,9 +87,9 @@
|
|||
–
|
||||
<time datetime="{{ booking.computed_end_time|time:"H:i" }}">{{ booking.computed_end_time|time:"H:i" }}</time>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
|
|
@ -1664,6 +1664,17 @@ class AgendaDayView(EventChecksMixin, AgendaDateView, DayArchiveView):
|
|||
booking.computed_end_time, booking.computed_start_time
|
||||
)
|
||||
|
||||
users_info = {}
|
||||
for result in context['results']:
|
||||
user_info = users_info.setdefault(
|
||||
result.user_external_id, {'name': result.get_user_block(), 'bookings': []}
|
||||
)
|
||||
if result.kind != 'booking':
|
||||
continue
|
||||
user_info['bookings'].append(result)
|
||||
|
||||
context['users'] = users_info.values()
|
||||
|
||||
|
||||
agenda_day_view = AgendaDayView.as_view()
|
||||
|
||||
|
|
|
@ -203,6 +203,41 @@ def test_manager_partial_bookings_day_view_24_hours(app, admin_user, freezer):
|
|||
)
|
||||
|
||||
|
||||
def test_manager_partial_bookings_day_view_multiple_bookings(app, admin_user, freezer):
|
||||
agenda = Agenda.objects.create(label='Foo bar', kind='events', partial_bookings=True)
|
||||
start_datetime = make_aware(datetime.datetime(2023, 5, 2, 8, 0))
|
||||
event = Event.objects.create(
|
||||
label='Event', start_datetime=start_datetime, end_time=datetime.time(18, 00), places=10, agenda=agenda
|
||||
)
|
||||
Booking.objects.create(
|
||||
user_external_id='xxx',
|
||||
user_first_name='Jane',
|
||||
user_last_name='Doe',
|
||||
start_time=datetime.time(9, 00),
|
||||
end_time=datetime.time(12, 00),
|
||||
event=event,
|
||||
)
|
||||
Booking.objects.create(
|
||||
user_external_id='xxx',
|
||||
user_first_name='Jane',
|
||||
user_last_name='Doe',
|
||||
start_time=datetime.time(15, 00),
|
||||
end_time=datetime.time(18, 00),
|
||||
event=event,
|
||||
)
|
||||
|
||||
app = login(app)
|
||||
today = start_datetime.date()
|
||||
resp = app.get('/manage/agendas/%s/day/%d/%d/%d/' % (agenda.pk, today.year, today.month, today.day))
|
||||
|
||||
assert len(resp.pyquery('.partial-booking--registrant')) == 1
|
||||
assert len(resp.pyquery('.registrant--bar')) == 2
|
||||
assert resp.pyquery('.registrant--bar')[0].findall('time')[0].text == '09:00'
|
||||
assert resp.pyquery('.registrant--bar')[0].findall('time')[1].text == '12:00'
|
||||
assert resp.pyquery('.registrant--bar')[1].findall('time')[0].text == '15:00'
|
||||
assert resp.pyquery('.registrant--bar')[1].findall('time')[1].text == '18:00'
|
||||
|
||||
|
||||
@mock.patch('chrono.manager.forms.get_agenda_check_types')
|
||||
def test_manager_partial_bookings_check(check_types, app, admin_user):
|
||||
check_types.return_value = []
|
||||
|
|
Loading…
Reference in New Issue