From 9310ab2a8e8a9d6ddac9f8d23e20fb2549cecc49 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 11 Mar 2021 12:27:58 +0100 Subject: [PATCH 2/2] manager: allow editing event recurrence (#51778) --- chrono/manager/forms.py | 5 ++++- .../templates/chrono/manager_event_detail.html | 2 -- tests/test_manager.py | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/chrono/manager/forms.py b/chrono/manager/forms.py index dcf36a1..870645f 100644 --- a/chrono/manager/forms.py +++ b/chrono/manager/forms.py @@ -211,6 +211,9 @@ class EventForm(forms.ModelForm): self.fields[field].help_text = _( 'This field cannot be modified because some recurrences have bookings attached to them.' ) + if self.instance.primary_event: + for field in ('slug', 'repeat', 'recurrence_end_date', 'publication_date'): + del self.fields[field] def clean(self): super().clean() @@ -218,7 +221,7 @@ class EventForm(forms.ModelForm): after=self.cleaned_data['recurrence_end_date'] ): raise ValidationError(_('Bookings exist after this date.')) - if self.cleaned_data['recurrence_end_date'] and not self.cleaned_data['repeat']: + if self.cleaned_data.get('recurrence_end_date') and not self.cleaned_data.get('repeat'): raise ValidationError(_('Recurrence end date makes no sense without repetition.')) def save(self, *args, **kwargs): diff --git a/chrono/manager/templates/chrono/manager_event_detail.html b/chrono/manager/templates/chrono/manager_event_detail.html index eb0b5f3..7ead4ed 100644 --- a/chrono/manager/templates/chrono/manager_event_detail.html +++ b/chrono/manager/templates/chrono/manager_event_detail.html @@ -35,10 +35,8 @@ {% if not event.cancellation_status %} {% trans "Cancel" %} {% endif %} -{% if not object.primary_event %} {% trans "Options" %} {% endif %} -{% endif %} {% if object.agenda.booking_form_url %} {% trans "Booking form" %} {% endif %} diff --git a/tests/test_manager.py b/tests/test_manager.py index 1ddb67b..8f92427 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1515,12 +1515,13 @@ def test_edit_recurring_event(settings, app, admin_user, freezer): resp = resp.form.submit() assert not Event.objects.filter(slug='changed').exists() - # individually editing event recurrence is not supported, except for cancellation + # deletion of event recurrence is not allowed resp = app.get('/manage/agendas/%s/events/%s/' % (agenda.id, event_recurrence.id)) - assert 'Cancel' in resp.text - assert 'Options' not in resp.text assert 'Delete' not in resp.text + resp = resp.click('Options') + assert {'slug', 'repeat', 'recurrence_end_date', 'publication_date'}.isdisjoint(resp.form.fields) + def test_edit_recurring_event_with_end_date(settings, app, admin_user, freezer): freezer.move_to('2021-01-12 12:10') @@ -3967,7 +3968,7 @@ def test_agenda_events_month_view(app, admin_user): # trying to access event recurrence creates it event_count = Event.objects.count() time = localtime(event.start_datetime).strftime('%H%M') - resp = resp.click(href='abc:2020-12-02-%s' % time) + resp = resp.click(href='abc:2020-12-02-%s' % time).follow() assert Event.objects.count() == event_count + 1 resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, 2020, 12)) @@ -3982,6 +3983,14 @@ def test_agenda_events_month_view(app, admin_user): # the event occurence in DB does not hide recurrence of the second recurrent event assert len(resp.pyquery.find('.event-info')) == 10 + resp = resp.click('Options') + resp.form['start_datetime_1'] = '13:12' + resp = resp.form.submit(status=302).follow() + + resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, 2020, 12)) + assert len(resp.pyquery.find('.event-info')) == 5 + assert '1:12 p.m.' in resp.text + Event.objects.get(slug='abc--2020-12-02-%s' % time).cancel() resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, 2020, 12)) assert 'Cancelled' in resp.text -- 2.20.1