diff --git a/chrono/manager/forms.py b/chrono/manager/forms.py index 5a8ec2c8..5cd138f1 100644 --- a/chrono/manager/forms.py +++ b/chrono/manager/forms.py @@ -892,6 +892,10 @@ class TimePeriodForm(TimePeriodFormBase, forms.ModelForm): if self.instance.weekday_indexes: self.fields['repeat'].initial = 'custom' + if self.instance.agenda: # virtual agenda exclusion period + del self.fields['repeat'] + del self.fields['weekday_indexes'] + def save(self): super().save() @@ -923,6 +927,11 @@ class DateTimePeriodForm(TimePeriodForm): fields = ['date', 'start_time', 'end_time'] +class ExcludedPeriodAddForm(TimePeriodAddForm): + repeat = None + weekday_indexes = None + + class NewDeskForm(forms.ModelForm): copy_from = forms.ModelChoiceField( label=_('Copy settings of desk'), diff --git a/chrono/manager/views.py b/chrono/manager/views.py index 9915968a..17990a1d 100644 --- a/chrono/manager/views.py +++ b/chrono/manager/views.py @@ -117,6 +117,7 @@ from .forms import ( EventDuplicateForm, EventForm, EventsTimesheetForm, + ExcludedPeriodAddForm, ImportEventsForm, MeetingTypeForm, NewDeskForm, @@ -2827,7 +2828,7 @@ def process_time_period_add_form(form, desk=None, agenda=None): weekday=weekday, start_time=form.cleaned_data['start_time'], end_time=form.cleaned_data['end_time'], - weekday_indexes=form.cleaned_data['weekday_indexes'], + weekday_indexes=form.cleaned_data.get('weekday_indexes'), ) if desk: period.desk = desk @@ -2858,7 +2859,7 @@ agenda_add_time_period = AgendaAddTimePeriodView.as_view() class VirtualAgendaAddTimePeriodView(ManagedAgendaMixin, FormView): template_name = 'chrono/manager_time_period_form.html' - form_class = TimePeriodAddForm + form_class = ExcludedPeriodAddForm tab_anchor = 'time-periods' def get_form_kwargs(self): diff --git a/tests/manager/test_all.py b/tests/manager/test_all.py index 876d5735..b636fce2 100644 --- a/tests/manager/test_all.py +++ b/tests/manager/test_all.py @@ -2896,6 +2896,9 @@ def test_virtual_agenda_settings_add_excluded_period(app, admin_user): resp = app.get('/manage/agendas/%s/settings' % agenda.pk) resp = resp.click('Add Excluded Period') + assert 'repeat' not in resp.form.fields + assert 'weekday_indexes' not in resp.form.fields + resp.form.get('weekdays', index=0).checked = True resp.form['start_time'] = '10:00' resp.form['end_time'] = '17:00' @@ -2920,6 +2923,10 @@ def test_virtual_agenda_settings_edit_excluded_period(app, admin_user): resp = app.get('/manage/agendas/%s/settings' % agenda.pk) url = '/manage/timeperiods/%s/edit' % tp.pk resp = resp.click(href=url) + + assert 'repeat' not in resp.form.fields + assert 'weekday_indexes' not in resp.form.fields + resp.form['start_time'] = '11:00' resp = resp.form.submit() tp = TimePeriod.objects.get(agenda=agenda)