From 01e68d378eeb14053c5b787a4f0021c3a941539b Mon Sep 17 00:00:00 2001 From: Tobias Kunze Date: Fri, 22 Feb 2019 23:09:48 +0100 Subject: [PATCH] [schedule] Be more tolerant about submitted availabilities The previous version produced issues when organisers changed the event timeframe and availabilities were re-submitted afterwards. Closes #579 --- doc/changelog.rst | 1 + src/pretalx/schedule/forms.py | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 6194a60616..139901f23f 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -3,6 +3,7 @@ Release Notes ============= +- :bug:`579` When organisers changed the event timeframe, already submitted availabilites would have to be changed upon new submission. - :feature:`577` You can now decide if text lengths should be counted in words or in characters when restricting how long they should be. - :bug:`587` pretalx did not automtically update a talk's duration when it was changed via the submission type or directly. It was only changed when you moved the talk in the schedule editor. - :bug:`594` pretalx did not display speaker availabilities during submission, even when they were required, breaking submission workflows. diff --git a/src/pretalx/schedule/forms.py b/src/pretalx/schedule/forms.py index ae9bbb5574..cf5c1e92c3 100644 --- a/src/pretalx/schedule/forms.py +++ b/src/pretalx/schedule/forms.py @@ -100,23 +100,21 @@ def _validate_availability(self, rawavail): tz = pytz.timezone(self.event.timezone) - try: - timeframe_start = tz.localize( - datetime.datetime.combine(self.event.date_from, datetime.time()) - ) - assert rawavail['start'] >= timeframe_start + timeframe_start = tz.localize( + datetime.datetime.combine(self.event.date_from, datetime.time()) + ) + if rawavail['start'] < timeframe_start: + rawavail['start'] = timeframe_start - # add 1 day, not 24 hours, https://stackoverflow.com/a/25427822/2486196 - timeframe_end = datetime.datetime.combine( - self.event.date_to, datetime.time() - ) - timeframe_end = timeframe_end + datetime.timedelta(days=1) - timeframe_end = tz.localize(timeframe_end, is_dst=None) - assert rawavail['end'] <= timeframe_end - except AssertionError: - raise forms.ValidationError( - _("The submitted availability is not within the event timeframe.") - ) + # add 1 day, not 24 hours, https://stackoverflow.com/a/25427822/2486196 + timeframe_end = datetime.datetime.combine( + self.event.date_to, datetime.time() + ) + timeframe_end = timeframe_end + datetime.timedelta(days=1) + timeframe_end = tz.localize(timeframe_end, is_dst=None) + if rawavail['end'] > timeframe_end: + # If the submitted availability ended outside the event timeframe, fix it silently + rawavail['end'] = timeframe_end def clean_availabilities(self): data = self.cleaned_data.get('availabilities')