Browse Source

check if start and end time differ

subDesTagesMitExtraKaese 2 years ago
parent
commit
2ec82095a9
1 changed files with 10 additions and 0 deletions
  1. 10 0
      zitap/forms.py

+ 10 - 0
zitap/forms.py

@@ -16,6 +16,16 @@ class CreateEventForm(forms.Form):
     end_time = forms.ChoiceField(label='End time', initial=20, choices=get_hours)
     slot_interval = forms.ChoiceField(label='Time slot interval', initial=15, choices=get_interval)
 
+    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)
     password = forms.CharField(label='Password', max_length=100, widget=forms.PasswordInput, required=False)