11# Copyright The IETF Trust 2013-2019, All Rights Reserved
2+ import datetime
23import re
34
45from django import forms
1011from ietf .name .models import TimeSlotTypeName
1112import ietf .utils .fields
1213
13- DAYS_CHOICES = ((0 ,'Saturday' ),
14- (1 ,'Sunday' ),
15- (2 ,'Monday' ),
16- (3 ,'Tuesday' ),
17- (4 ,'Wednesday' ),
18- (5 ,'Thursday' ),
19- (6 ,'Friday' ))
2014
2115# using Django week_day lookup values (Sunday=1)
2216SESSION_DAYS = ((2 ,'Monday' ),
@@ -131,15 +125,18 @@ class Meta:
131125 exclude = ['resources' ]
132126
133127class TimeSlotForm (forms .Form ):
134- day = forms .ChoiceField (choices = DAYS_CHOICES )
128+ day = forms .ChoiceField ()
135129 time = forms .TimeField ()
136130 duration = ietf .utils .fields .DurationField ()
137131 name = forms .CharField (help_text = 'Name that appears on the agenda' )
138132
139133 def __init__ (self ,* args ,** kwargs ):
134+ if 'meeting' in kwargs :
135+ self .meeting = kwargs .pop ('meeting' )
140136 super (TimeSlotForm , self ).__init__ (* args ,** kwargs )
141137 self .fields ["time" ].widget .attrs ["placeholder" ] = "HH:MM"
142138 self .fields ["duration" ].widget .attrs ["placeholder" ] = "HH:MM"
139+ self .fields ["day" ].choices = self .get_day_choices ()
143140
144141 def clean_duration (self ):
145142 '''Limit to HH:MM format'''
@@ -148,6 +145,16 @@ def clean_duration(self):
148145 raise forms .ValidationError ('{} value has an invalid format. It must be in HH:MM format' .format (duration ))
149146 return self .cleaned_data ['duration' ]
150147
148+ def get_day_choices (self ):
149+ '''Get day choices for form based on meeting duration'''
150+ choices = []
151+ start = self .meeting .date
152+ for n in range (self .meeting .days ):
153+ date = start + datetime .timedelta (days = n )
154+ choices .append ((n , date .strftime ("%a %b %d" )))
155+ return choices
156+
157+
151158class MiscSessionForm (TimeSlotForm ):
152159 short = forms .CharField (max_length = 32 ,label = 'Short Name' ,help_text = 'Enter an abbreviated session name (used for material file names)' ,required = False )
153160 type = forms .ModelChoiceField (queryset = TimeSlotTypeName .objects .filter (used = True ).exclude (slug__in = ('regular' ,)),empty_label = None )
0 commit comments