manager: hide unused settings for partial bookings agendas (#80465)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-10-03 10:41:33 +02:00
parent a13003cdec
commit 23a1b70dd7
5 changed files with 68 additions and 72 deletions

View File

@ -94,6 +94,7 @@ class AgendaAddForm(forms.ModelForm):
self.cleaned_data['kind'] = 'events'
self.instance.partial_bookings = True
self.instance.default_view = 'day'
self.instance.enable_check_for_future_events = True
def save(self, *args, **kwargs):
create = self.instance.pk is None
@ -1530,9 +1531,12 @@ class AgendaDisplaySettingsForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if kwargs['instance'].kind == 'events':
self.fields['booking_user_block_template'].help_text = (
_('Displayed for each booking in event page and check page'),
)
if self.instance.partial_bookings:
del self.fields['booking_user_block_template']
else:
self.fields['booking_user_block_template'].help_text = (
_('Displayed for each booking in event page and check page'),
)
else:
self.fields['booking_user_block_template'].help_text = (
_('Displayed for each booking in agenda view pages'),
@ -1552,6 +1556,12 @@ class AgendaBookingCheckSettingsForm(forms.ModelForm):
]
widgets = {'booking_extra_user_block_template': forms.Textarea(attrs={'rows': 3})}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance.partial_bookings:
del self.fields['enable_check_for_future_events']
del self.fields['booking_extra_user_block_template']
class AgendaInvoicingSettingsForm(forms.ModelForm):
class Meta:

View File

@ -41,7 +41,7 @@
<div class="pk-tabs">
<div class="pk-tabs--tab-list" role="tablist">
{% block agenda-settings-extra-tab-buttons %}{% endblock %}
{% if object.kind != 'virtual' %}
{% if object.kind != 'virtual' and not object.partial_bookings %}
<button aria-controls="panel-reminders" aria-selected="false" id="tab-reminders" role="tab" tabindex="-1">{% trans "Booking reminders" %}</button>
{% endif %}
<button aria-controls="panel-delays" aria-selected="false" id="tab-delays" role="tab" tabindex="-1">{% trans "Booking Delays" %}</button>
@ -51,7 +51,7 @@
{% block agenda-settings-extra-tab-list %}{% endblock %}
{% if object.kind != 'virtual' %}
{% if object.kind != 'virtual' and not object.partial_bookings %}
<div aria-labelledby="tab-reminders" id="panel-reminders" role="tabpanel" tabindex="0" hidden="">
{% for info in agenda.reminder_settings.display_info %}
<p>{{ info }}</p>

View File

@ -21,8 +21,9 @@
<button aria-controls="panel-booking-check-options" aria-selected="false" id="tab-booking-check-options" role="tab" tabindex="-1">{% trans "Booking check options" %}</button>
{% if agenda.partial_bookings %}
<button aria-controls="panel-invoicing-options" aria-selected="false" id="tab-invoicing-options" role="tab" tabindex="-1">{% trans "Invoicing options" %}</button>
{% else %}
<button aria-controls="panel-notifications" aria-selected="false" id="tab-notifications" role="tab" tabindex="-1">{% trans "Management notifications" %}</button>
{% endif %}
<button aria-controls="panel-notifications" aria-selected="false" id="tab-notifications" role="tab" tabindex="-1">{% trans "Management notifications" %}</button>
{% endblock %}
{% block agenda-settings-extra-tab-list %}
@ -89,10 +90,12 @@
{% trans "No event display template configured for this agenda." %}
{% endif %}
</li>
<li>
{% trans "Booking display template:" %}
{% if not agenda.partial_bookings %}
<li>
{% trans "Booking display template:" %}
<pre>{{ agenda.get_booking_user_block_template }}</pre>
</li>
</li>
{% endif %}
</ul>
<div class="panel--buttons">
<a rel="popup" class="button" href="{% url 'chrono-manager-agenda-display-settings' pk=object.pk %}">{% trans 'Configure' %}</a>
@ -116,11 +119,13 @@
{% endwith %}
<li>{% trans "Automatically mark event as checked when all bookings have been checked:" %} {{ agenda.mark_event_checked_auto|yesno }}</li>
<li>{% trans "Prevent the check of bookings when event was marked as checked:" %} {{ agenda.disable_check_update|yesno }}</li>
<li>{% trans "Enable the check of bookings when event has not passed:" %} {{ agenda.enable_check_for_future_events|yesno }}</li>
<li>
{% trans "Extra user block template:" %}
{% if not agenda.partial_bookings %}
<li>{% trans "Enable the check of bookings when event has not passed:" %} {{ agenda.enable_check_for_future_events|yesno }}</li>
<li>
{% trans "Extra user block template:" %}
<pre>{{ agenda.booking_extra_user_block_template }}</pre>
</li>
</li>
{% endif %}
</ul>
<div class="panel--buttons">
<a rel="popup" class="button" href="{% url 'chrono-manager-agenda-booking-check-settings' pk=object.pk %}">{% trans 'Configure' %}</a>
@ -139,21 +144,23 @@
</div>
{% endif %}
<div aria-labelledby="tab-notifications" hidden="" id="panel-notifications" role="tabpanel" tabindex="0">
{% for notification_type in object.notifications_settings.get_notification_types %}
{% if forloop.first %}<ul>{% endif %}
<li>
{% blocktrans trimmed with display_value=notification_type.display_value label=notification_type.label %}
{{ label }}: {{ display_value }} will be notified.
{% endblocktrans %}
</li>
{% if forloop.last %}</ul>{% endif %}
{% empty %}
<p>{% trans "Notifications are disabled for this agenda." %}</p>
{% endfor %}
<div class="panel--buttons">
<a rel="popup" class="button" href="{% url 'chrono-manager-agenda-notifications-settings' pk=object.id %}">{% trans 'Configure' %}</a>
{% if not agenda.partial_bookings %}
<div aria-labelledby="tab-notifications" hidden="" id="panel-notifications" role="tabpanel" tabindex="0">
{% for notification_type in object.notifications_settings.get_notification_types %}
{% if forloop.first %}<ul>{% endif %}
<li>
{% blocktrans trimmed with display_value=notification_type.display_value label=notification_type.label %}
{{ label }}: {{ display_value }} will be notified.
{% endblocktrans %}
</li>
{% if forloop.last %}</ul>{% endif %}
{% empty %}
<p>{% trans "Notifications are disabled for this agenda." %}</p>
{% endfor %}
<div class="panel--buttons">
<a rel="popup" class="button" href="{% url 'chrono-manager-agenda-notifications-settings' pk=object.id %}">{% trans 'Configure' %}</a>
</div>
</div>
</div>
{% endif %}
{% endblock %}

View File

@ -1625,13 +1625,8 @@ class AgendaDayView(EventChecksMixin, AgendaDateView, DayArchiveView):
context['event'] = event
context['allow_check'] = (
(
self.agenda.enable_check_for_future_events
or localtime(event.start_datetime).date() <= localtime().date()
)
and (not event.checked or not self.agenda.disable_check_update)
and not event.check_locked
)
not event.checked or not self.agenda.disable_check_update
) and not event.check_locked
self.add_filters_context(context, event)
min_time = localtime(event.start_datetime).time()
@ -1673,7 +1668,7 @@ class AgendaDayView(EventChecksMixin, AgendaDateView, DayArchiveView):
user_info = users_info.setdefault(
result.user_external_id,
{
'name': result.get_user_block(),
'name': result.user_name,
'check_url': result.get_partial_bookings_check_url(self.agenda, event),
'bookings': [],
},

View File

@ -27,6 +27,7 @@ def test_manager_partial_bookings_add_agenda(app, admin_user, settings):
assert agenda.kind == 'events'
assert agenda.partial_bookings is True
assert agenda.default_view == 'day'
assert agenda.enable_check_for_future_events is True
resp = resp.click('Options')
assert resp.form['default_view'].options == [
@ -94,6 +95,25 @@ def test_options_partial_bookings_invoicing_settings(app, admin_user):
assert '/manage/agendas/%s/invoicing-options' % agenda.pk not in resp
def test_options_partial_bookings_simpler_settings(app, admin_user):
agenda = Agenda.objects.create(label='Foo bar', kind='events', partial_bookings=True)
app = login(app)
resp = app.get('/manage/agendas/%s/settings' % agenda.pk)
assert 'Management notifications' not in resp.text
assert 'Booking reminders' not in resp.text
assert 'Booking display template' not in resp.text
assert 'Extra user block template' not in resp.text
assert 'Enable the check of bookings when event has not passed' not in resp.text
resp = app.get('/manage/agendas/%s/display-options' % agenda.pk)
assert 'booking_user_block_template' not in resp.form.fields
resp = app.get('/manage/agendas/%s/check-options' % agenda.pk)
assert 'enable_check_for_future_events' not in resp.form.fields
assert 'booking_extra_user_block_template' not in resp.form.fields
def test_manager_partial_bookings_add_event(app, admin_user):
agenda = Agenda.objects.create(label='Foo bar', kind='events', partial_bookings=True)
@ -407,42 +427,6 @@ def test_manager_partial_bookings_check(check_types, app, admin_user):
app.get('/manage/agendas/%s/bookings/%s/check' % (agenda.pk, booking.pk), status=404)
def test_manager_partial_bookings_check_future_events(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 = Booking.objects.create(
user_external_id='xxx',
user_first_name='Jane',
user_last_name='Doe',
start_time=datetime.time(11, 00),
end_time=datetime.time(13, 30),
event=event,
)
app = login(app)
day = start_datetime.date()
resp = app.get('/manage/agendas/%s/day/%d/%d/%d/' % (agenda.pk, day.year, day.month, day.day))
assert len(resp.pyquery('.registrant--name a')) == 1
app.get('/manage/agendas/%s/bookings/%s/check' % (agenda.pk, booking.pk), status=200)
freezer.move_to(start_datetime - datetime.timedelta(days=1))
resp = app.get('/manage/agendas/%s/day/%d/%d/%d/' % (agenda.pk, day.year, day.month, day.day))
assert len(resp.pyquery('.registrant--name a')) == 0
app.get('/manage/agendas/%s/bookings/%s/check' % (agenda.pk, booking.pk), status=404)
agenda.enable_check_for_future_events = True
agenda.save()
resp = app.get('/manage/agendas/%s/day/%d/%d/%d/' % (agenda.pk, day.year, day.month, day.day))
assert len(resp.pyquery('.registrant--name a')) == 1
app.get('/manage/agendas/%s/bookings/%s/check' % (agenda.pk, booking.pk), status=200)
@mock.patch('chrono.manager.forms.get_agenda_check_types')
def test_manager_partial_bookings_check_subscription(check_types, app, admin_user):
check_types.return_value = []