forms.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. import datetime
  2. from django import forms
  3. from .widgets import DatePickerWidget, SlotPickerWidget
  4. def get_hours():
  5. return [(x, datetime.time(x, 0)) for x in range(24)]
  6. def get_interval():
  7. return [(x, datetime.timedelta(minutes=x)) for x in [15, 30, 60]]
  8. class CreateEventForm(forms.Form):
  9. event_name = forms.CharField(label='Event name', max_length=100)
  10. event_date = forms.Field(label='Event date', widget=DatePickerWidget)
  11. start_time = forms.ChoiceField(label='Start time', initial=9, choices=get_hours)
  12. end_time = forms.ChoiceField(label='End time', initial=20, choices=get_hours)
  13. slot_interval = forms.ChoiceField(label='Time slot interval', initial=15, choices=get_interval)
  14. class LoginForm(forms.Form):
  15. username = forms.CharField(label='Username', max_length=100)
  16. password = forms.CharField(label='Password', max_length=100, widget=forms.PasswordInput, required=False)
  17. class UpdateSlotsForm(forms.Form):
  18. slots = forms.Field(label='Slots')
  19. def __init__(self, *args, participant, **kwargs):
  20. super().__init__(*args, **kwargs)
  21. self.fields['slots'].widget = SlotPickerWidget(participant=participant)