Commit a9123809 authored by fred's avatar fred

fix date options for absence dialog for non-staff users

parent c4d00c5f
......@@ -307,17 +307,20 @@ class NewsItemForm(forms.ModelForm):
class AbsenceDateTimeWidget(forms.Select):
def render_options(self, choices, selected_choices):
self.choices = []
def __init__(self, emission, *args, **kwargs):
super().__init__(*args, **kwargs)
self.choices = list(self.options(emission))
def options(self, emission):
dates = []
for i in range(4):
if dates:
since = dates[-1] + datetime.timedelta(minutes=10)
else:
since = None
dates.append(self.emission.get_next_planned_date(since))
choices = [(x, x.strftime('%d/%m/%Y %H:%M')) for x in dates]
return super(AbsenceDateTimeWidget, self).render_options(choices, selected_choices)
dates.append(emission.get_next_planned_date(since))
for date in dates:
yield (date, date.strftime('%d/%m/%Y %H:%M'))
class AbsenceForm(forms.ModelForm):
......@@ -326,7 +329,6 @@ class AbsenceForm(forms.ModelForm):
exclude = ()
widgets = {
'emission': forms.HiddenInput(),
'datetime': AbsenceDateTimeWidget(),
}
def __init__(self, *args, **kwargs):
......@@ -338,6 +340,8 @@ class AbsenceForm(forms.ModelForm):
date = emission.get_next_planned_date()
self.fields['datetime'].initial = date
self.fields['datetime'].widget = DateTimeWidget()
else:
self.fields['datetime'].widget = AbsenceDateTimeWidget(emission)
def save(self, commit=True):
t = super(AbsenceForm, self).save(commit=commit)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment