Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class EventForm(forms.ModelForm):
- dt = '%Y-%m-%d %H:%M'
- start = forms.DateTimeField(
- label="Start time (in event's local time)",
- required=False,
- input_formats=[dt]
- )
- end = forms.DateTimeField(
- label="End time (in event's local time)",
- required=False,
- input_formats=[dt]
- )
- class Meta:
- model = Event
- fields = [
- 'name', 'flexibility', 'timezone',
- 'date_start', 'date_end', 'last_field',
- ]
- def __init__(self, *args, **kwargs):
- super(EventForm, self).__init__(*args, **kwargs)
- self.fields['date_start'].widget = forms.HiddenInput()
- self.fields['date_end'].widget = forms.HiddenInput()
- i = kwargs.get('instance')
- tz = pytz.timezone(i.timezone) if i and i.timezone else None
- if i and i.flexibility == Event.FLEXIBILITY_ONTIME and tz:
- self.fields['start'].initial = i.date_start.astimezone(tz).strftime(self.dt) if i.date_start else None
- self.fields['end'].initial = i.date_end.astimezone(tz).strftime(self.dt) if i.date_end else None
- else:
- self.fields['start'].initial = None
- self.fields['end'].initial = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement