manager: do not show weekday indexes field for exclusion periods (#72625) #26

Merged
vdeniaud merged 1 commits from wip/72625-api-datetimes-agenda-virtuel-Typ into main 2022-12-20 16:04:52 +01:00
3 changed files with 19 additions and 2 deletions

View File

@ -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'),

View File

@ -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):

View File

@ -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)