123456789101112131415161718192021222324252627282930313233343536373839 |
- import datetime
- from django import forms
- from django.utils.translation import gettext_lazy as _
- from .widgets import DatePickerWidget, SlotPickerWidget
- def get_hours():
- return [(x, datetime.time(x, 0)) for x in range(24)]
- def get_interval():
- return [(x, datetime.timedelta(minutes=x)) for x in [15, 30, 60]]
- class CreateEventForm(forms.Form):
- event_name = forms.CharField(label=_('Event name'), max_length=100, help_text=_('The name of your event. This will be displayed to participants.'))
- event_date = forms.Field(label=_('Event date'), widget=DatePickerWidget)
- start_time = forms.ChoiceField(label=_('Start time'), initial=9, choices=get_hours, help_text=_('The first time slot available for participants to select.'))
- end_time = forms.ChoiceField(label=_('End time'), initial=20, choices=get_hours, help_text=_('The last time slot available for participants to select.'))
- slot_interval = forms.ChoiceField(label=_('Time slot interval'), initial=15, choices=get_interval, help_text=_('The interval between time slots.'))
- def clean(self) -> dict:
- cleaned_data = super().clean()
- if (not "start_time" in cleaned_data) or (not "end_time" in cleaned_data):
- return cleaned_data
- if cleaned_data['start_time'] == cleaned_data['end_time']:
- self.add_error('start_time', _('Start time must be different from end time'))
-
- return cleaned_data
- class LoginForm(forms.Form):
- username = forms.CharField(label=_('Username'), max_length=100, help_text=_('This will be displayed to other participants.'))
- password = forms.CharField(label=_('Password'), max_length=100, widget=forms.PasswordInput, required=False, help_text=_('Fill in a password to create a new account. Leave empty to login as a guest.'))
- class UpdateSlotsForm(forms.Form):
- slots = forms.Field(label=_('Slots'), help_text=_('Click on a time slot to select it. Click again to deselect it. You can also drag the mouse to select multiple slots.'))
- def __init__(self, *args, event, n_slots, participant, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields['slots'].widget = SlotPickerWidget(event=event, n_slots=n_slots, participant=participant)
|