We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Event's start date must be earlier than it's end date
We should enforce that the start date is early that the end date.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `workshops/forms.py`
Content:
```
1 from django import forms
2 from django.forms import HiddenInput, CheckboxSelectMultiple
3 
4 from crispy_forms.helper import FormHelper
5 from crispy_forms.layout import Layout, Div, HTML, Submit, Field
6 from crispy_forms.bootstrap import FormActions
7 from django_countries.fields import CountryField
8 from selectable import forms as selectable
9 
10 from workshops.models import (
11     Award, Event, Lesson, Person, Task, KnowledgeDomain,
12 )
13 from workshops import lookups
14 
15 INSTRUCTORS_NUM = 10  # how many instrutors to return from a search by default
16 
17 AUTOCOMPLETE_HELP_TEXT = (
18     "Autocomplete field; type characters to view available options, "
19     "then select desired item from list."
20 )
21 
22 DATE_HELP_TEXT = "Select date using widget, or enter in YYYY-MM-DD format."
23 
24 
25 class BootstrapHelper(FormHelper):
26     form_class = 'form-horizontal'
27     label_class = 'col-lg-2'
28     field_class = 'col-lg-8'
29 
30     def __init__(self, form=None):
31         super().__init__(form)
32 
33         self.attrs['role'] = 'form'
34         self.inputs.append(Submit('submit', 'Submit'))
35 
36 
37 class BootstrapHelperWithAdd(BootstrapHelper):
38     def __init__(self, form=None):
39         super().__init__(form)
40 
41         self.inputs[-1] = Submit('submit', 'Add')
42 
43 
44 class BootstrapHelperFilter(FormHelper):
45     form_method = 'get'
46 
47     def __init__(self, form=None):
48         super().__init__(form)
49         self.attrs['role'] = 'form'
50         self.inputs.append(Submit('', 'Submit'))
51 
52 
53 bootstrap_helper = BootstrapHelper()
54 bootstrap_helper_with_add = BootstrapHelperWithAdd()
55 bootstrap_helper_filter = BootstrapHelperFilter()
56 
57 
58 class InstructorsForm(forms.Form):
59     '''Represent instructor matching form.'''
60 
61     latitude = forms.FloatField(label='Latitude',
62                                 min_value=-90.0,
63                                 max_value=90.0,
64                                 required=False)
65     longitude = forms.FloatField(label='Longitude',
66                                  min_value=-180.0,
67                                  max_value=180.0,
68                                  required=False)
69     airport = selectable.AutoCompleteSelectField(
70         lookup_class=lookups.AirportLookup,
71         label='Airport',
72         required=False,
73         widget=selectable.AutoComboboxSelectWidget(
74             lookup_class=lookups.AirportLookup,
75         ),
76     )
77 
78     country = CountryField().formfield(required=False)
79 
80     lessons = forms.ModelMultipleChoiceField(queryset=Lesson.objects.all(),
81                                              widget=CheckboxSelectMultiple(),
82                                              required=False)
83 
84     def __init__(self, *args, **kwargs):
85         '''Build checkboxes for qualifications dynamically.'''
86         super(InstructorsForm, self).__init__(*args, **kwargs)
87         self.helper = FormHelper(self)
88         self.helper.form_class = 'form-inline'
89         self.helper.form_method = 'get'
90         self.helper.layout = Layout(
91             Div(
92                 Div(
93                     'latitude',
94                     'longitude',
95                     css_class='panel-body'
96                 ),
97                 css_class='panel panel-default ',
98             ),
99             HTML('<p>OR</p>'),
100             Div(
101                 Div(
102                     'airport',
103                     css_class='panel-body'
104                 ),
105                 css_class='panel panel-default ',
106             ),
107             HTML('<p>OR</p>'),
108             Div(
109                 Div(
110                     'country',
111                     css_class='panel-body'
112                 ),
113                 css_class='panel panel-default ',
114             ),
115             'lessons',
116             FormActions(
117                 Submit('submit', 'Submit'),
118             ),
119         )
120 
121     def clean(self):
122         cleaned_data = super(InstructorsForm, self).clean()
123         airport = cleaned_data.get('airport')
124         lat = cleaned_data.get('latitude')
125         long = cleaned_data.get('longitude')
126         country = cleaned_data.get('country')
127 
128         sum = bool(airport) + bool(lat and long) + bool(country)
129         # user can specify only one: either airport, or lat&long, or country
130         if sum != 1:
131             raise forms.ValidationError('Must specify an airport, or latitude'
132                                         ' and longitude, or a country.')
133         return cleaned_data
134 
135 
136 class PersonBulkAddForm(forms.Form):
137     '''Represent CSV upload form for bulk adding people.'''
138 
139     file = forms.FileField()
140 
141 
142 class SearchForm(forms.Form):
143     '''Represent general searching form.'''
144 
145     term = forms.CharField(label='term',
146                            max_length=100)
147     in_sites = forms.BooleanField(label='in sites',
148                                   required=False,
149                                   initial=True)
150     in_events = forms.BooleanField(label='in events',
151                                    required=False,
152                                    initial=True)
153     in_persons = forms.BooleanField(label='in persons',
154                                     required=False,
155                                     initial=True)
156     in_airports = forms.BooleanField(label='in airports',
157                                      required=False,
158                                      initial=True)
159 
160 
161 class DebriefForm(forms.Form):
162     '''Represent general debrief form.'''
163     begin_date = forms.DateField(
164         label='Begin date as YYYY-MM-DD',
165         input_formats=['%Y-%m-%d', ]
166     )
167     end_date = forms.DateField(
168         label='End date as YYYY-MD-DD',
169         input_formats=['%Y-%m-%d', ]
170     )
171 
172 
173 class EventForm(forms.ModelForm):
174 
175     site = selectable.AutoCompleteSelectField(
176         lookup_class=lookups.SiteLookup,
177         label='Site',
178         required=True,
179         help_text=AUTOCOMPLETE_HELP_TEXT,
180         widget=selectable.AutoComboboxSelectWidget,
181     )
182 
183     organizer = selectable.AutoCompleteSelectField(
184         lookup_class=lookups.SiteLookup,
185         label='Organizer',
186         required=False,
187         help_text=AUTOCOMPLETE_HELP_TEXT,
188         widget=selectable.AutoComboboxSelectWidget,
189     )
190 
191     def __init__(self, *args, **kwargs):
192         super().__init__(*args, **kwargs)
193         self.fields['start'].help_text = DATE_HELP_TEXT
194         self.fields['end'].help_text = DATE_HELP_TEXT
195 
196     def clean_slug(self):
197         # Ensure slug is not an integer value for Event.get_by_ident
198         data = self.cleaned_data['slug']
199 
200         try:
201             int(data)
202         except ValueError:
203             pass
204         else:
205             raise forms.ValidationError("Slug must not be an integer-value.")
206 
207         return data
208 
209     class Meta:
210         model = Event
211         # reorder fields, don't display 'deleted' field
212         fields = ('slug', 'start', 'end', 'site', 'organizer',
213                   'tags', 'url', 'reg_key', 'admin_fee', 'invoiced',
214                   'attendance', 'notes')
215 
216     class Media:
217         # thanks to this, {{ form.media }} in the template will generate
218         # a <link href=""> (for CSS files) or <script src=""> (for JS files)
219         js = ('calendar_popup.js', )
220 
221 
222 class TaskForm(forms.ModelForm):
223 
224     person = selectable.AutoCompleteSelectField(
225         lookup_class=lookups.PersonLookup,
226         label='Person',
227         required=True,
228         help_text=AUTOCOMPLETE_HELP_TEXT,
229         widget=selectable.AutoComboboxSelectWidget,
230     )
231 
232     class Meta:
233         model = Task
234         fields = '__all__'
235         widgets = {'event': HiddenInput}
236 
237 
238 class TaskFullForm(TaskForm):
239 
240     event = selectable.AutoCompleteSelectField(
241         lookup_class=lookups.EventLookup,
242         label='Event',
243         required=True,
244         help_text=AUTOCOMPLETE_HELP_TEXT,
245         widget=selectable.AutoComboboxSelectWidget,
246     )
247 
248     class Meta:
249         model = Task
250         fields = '__all__'
251 
252 
253 class PersonForm(forms.ModelForm):
254 
255     airport = selectable.AutoCompleteSelectField(
256         lookup_class=lookups.AirportLookup,
257         label='Airport',
258         required=False,
259         help_text=AUTOCOMPLETE_HELP_TEXT,
260         widget=selectable.AutoComboboxSelectWidget,
261     )
262 
263     lessons = forms.ModelMultipleChoiceField(required=False,
264                                              queryset=Lesson.objects.all())
265 
266     domains = forms.ModelMultipleChoiceField(
267         required=False, queryset=KnowledgeDomain.objects.all()
268     )
269 
270     class Meta:
271         model = Person
272         # don't display the 'password', 'user_permissions',
273         # 'groups' or 'is_superuser' fields
274         # + reorder fields
275         fields = ['username', 'personal', 'middle', 'family', 'may_contact',
276                   'email', 'gender', 'airport', 'affiliation', 'github',
277                   'twitter', 'url', 'notes', 'lessons', 'domains']
278 
279 
280 class PersonPermissionsForm(forms.ModelForm):
281     class Meta:
282         model = Person
283         # only display 'user_permissions', 'groups' and `is_superuser` fields
284         fields = [
285             'is_superuser',
286             'user_permissions',
287             'groups',
288         ]
289 
290 
291 class PersonMergeForm(forms.Form):
292 
293     person_from = selectable.AutoCompleteSelectField(
294         lookup_class=lookups.PersonLookup,
295         label='Person From',
296         required=True,
297         help_text=AUTOCOMPLETE_HELP_TEXT,
298         widget=selectable.AutoComboboxSelectWidget,
299     )
300 
301     person_to = selectable.AutoCompleteSelectField(
302         lookup_class=lookups.PersonLookup,
303         label='Person To',
304         required=True,
305         help_text=AUTOCOMPLETE_HELP_TEXT,
306         widget=selectable.AutoComboboxSelectWidget,
307     )
308 
309 
310 class BadgeAwardForm(forms.ModelForm):
311 
312     person = selectable.AutoCompleteSelectField(
313         lookup_class=lookups.PersonLookup,
314         label='Person',
315         required=True,
316         help_text=AUTOCOMPLETE_HELP_TEXT,
317         widget=selectable.AutoComboboxSelectWidget,
318     )
319 
320     event = selectable.AutoCompleteSelectField(
321         lookup_class=lookups.EventLookup,
322         label='Event',
323         required=False,
324         help_text=AUTOCOMPLETE_HELP_TEXT,
325         widget=selectable.AutoComboboxSelectWidget,
326     )
327 
328     class Meta:
329         model = Award
330         fields = '__all__'
331         widgets = {'badge': HiddenInput}
332 
333 
334 class PersonAwardForm(forms.ModelForm):
335 
336     event = selectable.AutoCompleteSelectField(
337         lookup_class=lookups.EventLookup,
338         label='Event',
339         required=False,
340         help_text=AUTOCOMPLETE_HELP_TEXT,
341         widget=selectable.AutoComboboxSelectWidget,
342     )
343 
344     class Meta:
345         model = Award
346         fields = '__all__'
347         widgets = {'person': HiddenInput}
348 
349 
350 class PersonTaskForm(forms.ModelForm):
351 
352     event = selectable.AutoCompleteSelectField(
353         lookup_class=lookups.EventLookup,
354         label='Event',
355         required=True,
356         help_text=AUTOCOMPLETE_HELP_TEXT,
357         widget=selectable.AutoComboboxSelectWidget,
358     )
359 
360     class Meta:
361         model = Task
362         fields = '__all__'
363         widgets = {'person': HiddenInput}
364
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/workshops/forms.py b/workshops/forms.py
--- a/workshops/forms.py
+++ b/workshops/forms.py
@@ -206,6 +206,15 @@
 
         return data
 
+    def clean_end(self):
+        """Ensure end >= start."""
+        start = self.cleaned_data['start']
+        end = self.cleaned_data['end']
+
+        if start and end and end < start:
+            raise forms.ValidationError('Must not be earlier than start date.')
+        return end
+
     class Meta:
         model = Event
         # reorder fields, don't display 'deleted' field

{"golden_diff": "diff --git a/workshops/forms.py b/workshops/forms.py\n--- a/workshops/forms.py\n+++ b/workshops/forms.py\n@@ -206,6 +206,15 @@\n \n         return data\n \n+    def clean_end(self):\n+        \"\"\"Ensure end >= start.\"\"\"\n+        start = self.cleaned_data['start']\n+        end = self.cleaned_data['end']\n+\n+        if start and end and end < start:\n+            raise forms.ValidationError('Must not be earlier than start date.')\n+        return end\n+\n     class Meta:\n         model = Event\n         # reorder fields, don't display 'deleted' field\n", "issue": "Event's start date must be earlier than it's end date\nWe should enforce that the start date is early that the end date.\n\n", "before_files": [{"content": "from django import forms\nfrom django.forms import HiddenInput, CheckboxSelectMultiple\n\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.layout import Layout, Div, HTML, Submit, Field\nfrom crispy_forms.bootstrap import FormActions\nfrom django_countries.fields import CountryField\nfrom selectable import forms as selectable\n\nfrom workshops.models import (\n    Award, Event, Lesson, Person, Task, KnowledgeDomain,\n)\nfrom workshops import lookups\n\nINSTRUCTORS_NUM = 10  # how many instrutors to return from a search by default\n\nAUTOCOMPLETE_HELP_TEXT = (\n    \"Autocomplete field; type characters to view available options, \"\n    \"then select desired item from list.\"\n)\n\nDATE_HELP_TEXT = \"Select date using widget, or enter in YYYY-MM-DD format.\"\n\n\nclass BootstrapHelper(FormHelper):\n    form_class = 'form-horizontal'\n    label_class = 'col-lg-2'\n    field_class = 'col-lg-8'\n\n    def __init__(self, form=None):\n        super().__init__(form)\n\n        self.attrs['role'] = 'form'\n        self.inputs.append(Submit('submit', 'Submit'))\n\n\nclass BootstrapHelperWithAdd(BootstrapHelper):\n    def __init__(self, form=None):\n        super().__init__(form)\n\n        self.inputs[-1] = Submit('submit', 'Add')\n\n\nclass BootstrapHelperFilter(FormHelper):\n    form_method = 'get'\n\n    def __init__(self, form=None):\n        super().__init__(form)\n        self.attrs['role'] = 'form'\n        self.inputs.append(Submit('', 'Submit'))\n\n\nbootstrap_helper = BootstrapHelper()\nbootstrap_helper_with_add = BootstrapHelperWithAdd()\nbootstrap_helper_filter = BootstrapHelperFilter()\n\n\nclass InstructorsForm(forms.Form):\n    '''Represent instructor matching form.'''\n\n    latitude = forms.FloatField(label='Latitude',\n                                min_value=-90.0,\n                                max_value=90.0,\n                                required=False)\n    longitude = forms.FloatField(label='Longitude',\n                                 min_value=-180.0,\n                                 max_value=180.0,\n                                 required=False)\n    airport = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.AirportLookup,\n        label='Airport',\n        required=False,\n        widget=selectable.AutoComboboxSelectWidget(\n            lookup_class=lookups.AirportLookup,\n        ),\n    )\n\n    country = CountryField().formfield(required=False)\n\n    lessons = forms.ModelMultipleChoiceField(queryset=Lesson.objects.all(),\n                                             widget=CheckboxSelectMultiple(),\n                                             required=False)\n\n    def __init__(self, *args, **kwargs):\n        '''Build checkboxes for qualifications dynamically.'''\n        super(InstructorsForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper(self)\n        self.helper.form_class = 'form-inline'\n        self.helper.form_method = 'get'\n        self.helper.layout = Layout(\n            Div(\n                Div(\n                    'latitude',\n                    'longitude',\n                    css_class='panel-body'\n                ),\n                css_class='panel panel-default ',\n            ),\n            HTML('<p>OR</p>'),\n            Div(\n                Div(\n                    'airport',\n                    css_class='panel-body'\n                ),\n                css_class='panel panel-default ',\n            ),\n            HTML('<p>OR</p>'),\n            Div(\n                Div(\n                    'country',\n                    css_class='panel-body'\n                ),\n                css_class='panel panel-default ',\n            ),\n            'lessons',\n            FormActions(\n                Submit('submit', 'Submit'),\n            ),\n        )\n\n    def clean(self):\n        cleaned_data = super(InstructorsForm, self).clean()\n        airport = cleaned_data.get('airport')\n        lat = cleaned_data.get('latitude')\n        long = cleaned_data.get('longitude')\n        country = cleaned_data.get('country')\n\n        sum = bool(airport) + bool(lat and long) + bool(country)\n        # user can specify only one: either airport, or lat&long, or country\n        if sum != 1:\n            raise forms.ValidationError('Must specify an airport, or latitude'\n                                        ' and longitude, or a country.')\n        return cleaned_data\n\n\nclass PersonBulkAddForm(forms.Form):\n    '''Represent CSV upload form for bulk adding people.'''\n\n    file = forms.FileField()\n\n\nclass SearchForm(forms.Form):\n    '''Represent general searching form.'''\n\n    term = forms.CharField(label='term',\n                           max_length=100)\n    in_sites = forms.BooleanField(label='in sites',\n                                  required=False,\n                                  initial=True)\n    in_events = forms.BooleanField(label='in events',\n                                   required=False,\n                                   initial=True)\n    in_persons = forms.BooleanField(label='in persons',\n                                    required=False,\n                                    initial=True)\n    in_airports = forms.BooleanField(label='in airports',\n                                     required=False,\n                                     initial=True)\n\n\nclass DebriefForm(forms.Form):\n    '''Represent general debrief form.'''\n    begin_date = forms.DateField(\n        label='Begin date as YYYY-MM-DD',\n        input_formats=['%Y-%m-%d', ]\n    )\n    end_date = forms.DateField(\n        label='End date as YYYY-MD-DD',\n        input_formats=['%Y-%m-%d', ]\n    )\n\n\nclass EventForm(forms.ModelForm):\n\n    site = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.SiteLookup,\n        label='Site',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    organizer = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.SiteLookup,\n        label='Organizer',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields['start'].help_text = DATE_HELP_TEXT\n        self.fields['end'].help_text = DATE_HELP_TEXT\n\n    def clean_slug(self):\n        # Ensure slug is not an integer value for Event.get_by_ident\n        data = self.cleaned_data['slug']\n\n        try:\n            int(data)\n        except ValueError:\n            pass\n        else:\n            raise forms.ValidationError(\"Slug must not be an integer-value.\")\n\n        return data\n\n    class Meta:\n        model = Event\n        # reorder fields, don't display 'deleted' field\n        fields = ('slug', 'start', 'end', 'site', 'organizer',\n                  'tags', 'url', 'reg_key', 'admin_fee', 'invoiced',\n                  'attendance', 'notes')\n\n    class Media:\n        # thanks to this, {{ form.media }} in the template will generate\n        # a <link href=\"\"> (for CSS files) or <script src=\"\"> (for JS files)\n        js = ('calendar_popup.js', )\n\n\nclass TaskForm(forms.ModelForm):\n\n    person = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Task\n        fields = '__all__'\n        widgets = {'event': HiddenInput}\n\n\nclass TaskFullForm(TaskForm):\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Task\n        fields = '__all__'\n\n\nclass PersonForm(forms.ModelForm):\n\n    airport = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.AirportLookup,\n        label='Airport',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    lessons = forms.ModelMultipleChoiceField(required=False,\n                                             queryset=Lesson.objects.all())\n\n    domains = forms.ModelMultipleChoiceField(\n        required=False, queryset=KnowledgeDomain.objects.all()\n    )\n\n    class Meta:\n        model = Person\n        # don't display the 'password', 'user_permissions',\n        # 'groups' or 'is_superuser' fields\n        # + reorder fields\n        fields = ['username', 'personal', 'middle', 'family', 'may_contact',\n                  'email', 'gender', 'airport', 'affiliation', 'github',\n                  'twitter', 'url', 'notes', 'lessons', 'domains']\n\n\nclass PersonPermissionsForm(forms.ModelForm):\n    class Meta:\n        model = Person\n        # only display 'user_permissions', 'groups' and `is_superuser` fields\n        fields = [\n            'is_superuser',\n            'user_permissions',\n            'groups',\n        ]\n\n\nclass PersonMergeForm(forms.Form):\n\n    person_from = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person From',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    person_to = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person To',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n\nclass BadgeAwardForm(forms.ModelForm):\n\n    person = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Award\n        fields = '__all__'\n        widgets = {'badge': HiddenInput}\n\n\nclass PersonAwardForm(forms.ModelForm):\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Award\n        fields = '__all__'\n        widgets = {'person': HiddenInput}\n\n\nclass PersonTaskForm(forms.ModelForm):\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Task\n        fields = '__all__'\n        widgets = {'person': HiddenInput}\n", "path": "workshops/forms.py"}], "after_files": [{"content": "from django import forms\nfrom django.forms import HiddenInput, CheckboxSelectMultiple\n\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.layout import Layout, Div, HTML, Submit, Field\nfrom crispy_forms.bootstrap import FormActions\nfrom django_countries.fields import CountryField\nfrom selectable import forms as selectable\n\nfrom workshops.models import (\n    Award, Event, Lesson, Person, Task, KnowledgeDomain,\n)\nfrom workshops import lookups\n\nINSTRUCTORS_NUM = 10  # how many instrutors to return from a search by default\n\nAUTOCOMPLETE_HELP_TEXT = (\n    \"Autocomplete field; type characters to view available options, \"\n    \"then select desired item from list.\"\n)\n\nDATE_HELP_TEXT = \"Select date using widget, or enter in YYYY-MM-DD format.\"\n\n\nclass BootstrapHelper(FormHelper):\n    form_class = 'form-horizontal'\n    label_class = 'col-lg-2'\n    field_class = 'col-lg-8'\n\n    def __init__(self, form=None):\n        super().__init__(form)\n\n        self.attrs['role'] = 'form'\n        self.inputs.append(Submit('submit', 'Submit'))\n\n\nclass BootstrapHelperWithAdd(BootstrapHelper):\n    def __init__(self, form=None):\n        super().__init__(form)\n\n        self.inputs[-1] = Submit('submit', 'Add')\n\n\nclass BootstrapHelperFilter(FormHelper):\n    form_method = 'get'\n\n    def __init__(self, form=None):\n        super().__init__(form)\n        self.attrs['role'] = 'form'\n        self.inputs.append(Submit('', 'Submit'))\n\n\nbootstrap_helper = BootstrapHelper()\nbootstrap_helper_with_add = BootstrapHelperWithAdd()\nbootstrap_helper_filter = BootstrapHelperFilter()\n\n\nclass InstructorsForm(forms.Form):\n    '''Represent instructor matching form.'''\n\n    latitude = forms.FloatField(label='Latitude',\n                                min_value=-90.0,\n                                max_value=90.0,\n                                required=False)\n    longitude = forms.FloatField(label='Longitude',\n                                 min_value=-180.0,\n                                 max_value=180.0,\n                                 required=False)\n    airport = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.AirportLookup,\n        label='Airport',\n        required=False,\n        widget=selectable.AutoComboboxSelectWidget(\n            lookup_class=lookups.AirportLookup,\n        ),\n    )\n\n    country = CountryField().formfield(required=False)\n\n    lessons = forms.ModelMultipleChoiceField(queryset=Lesson.objects.all(),\n                                             widget=CheckboxSelectMultiple(),\n                                             required=False)\n\n    def __init__(self, *args, **kwargs):\n        '''Build checkboxes for qualifications dynamically.'''\n        super(InstructorsForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper(self)\n        self.helper.form_class = 'form-inline'\n        self.helper.form_method = 'get'\n        self.helper.layout = Layout(\n            Div(\n                Div(\n                    'latitude',\n                    'longitude',\n                    css_class='panel-body'\n                ),\n                css_class='panel panel-default ',\n            ),\n            HTML('<p>OR</p>'),\n            Div(\n                Div(\n                    'airport',\n                    css_class='panel-body'\n                ),\n                css_class='panel panel-default ',\n            ),\n            HTML('<p>OR</p>'),\n            Div(\n                Div(\n                    'country',\n                    css_class='panel-body'\n                ),\n                css_class='panel panel-default ',\n            ),\n            'lessons',\n            FormActions(\n                Submit('submit', 'Submit'),\n            ),\n        )\n\n    def clean(self):\n        cleaned_data = super(InstructorsForm, self).clean()\n        airport = cleaned_data.get('airport')\n        lat = cleaned_data.get('latitude')\n        long = cleaned_data.get('longitude')\n        country = cleaned_data.get('country')\n\n        sum = bool(airport) + bool(lat and long) + bool(country)\n        # user can specify only one: either airport, or lat&long, or country\n        if sum != 1:\n            raise forms.ValidationError('Must specify an airport, or latitude'\n                                        ' and longitude, or a country.')\n        return cleaned_data\n\n\nclass PersonBulkAddForm(forms.Form):\n    '''Represent CSV upload form for bulk adding people.'''\n\n    file = forms.FileField()\n\n\nclass SearchForm(forms.Form):\n    '''Represent general searching form.'''\n\n    term = forms.CharField(label='term',\n                           max_length=100)\n    in_sites = forms.BooleanField(label='in sites',\n                                  required=False,\n                                  initial=True)\n    in_events = forms.BooleanField(label='in events',\n                                   required=False,\n                                   initial=True)\n    in_persons = forms.BooleanField(label='in persons',\n                                    required=False,\n                                    initial=True)\n    in_airports = forms.BooleanField(label='in airports',\n                                     required=False,\n                                     initial=True)\n\n\nclass DebriefForm(forms.Form):\n    '''Represent general debrief form.'''\n    begin_date = forms.DateField(\n        label='Begin date as YYYY-MM-DD',\n        input_formats=['%Y-%m-%d', ]\n    )\n    end_date = forms.DateField(\n        label='End date as YYYY-MD-DD',\n        input_formats=['%Y-%m-%d', ]\n    )\n\n\nclass EventForm(forms.ModelForm):\n\n    site = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.SiteLookup,\n        label='Site',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    organizer = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.SiteLookup,\n        label='Organizer',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields['start'].help_text = DATE_HELP_TEXT\n        self.fields['end'].help_text = DATE_HELP_TEXT\n\n    def clean_slug(self):\n        # Ensure slug is not an integer value for Event.get_by_ident\n        data = self.cleaned_data['slug']\n\n        try:\n            int(data)\n        except ValueError:\n            pass\n        else:\n            raise forms.ValidationError(\"Slug must not be an integer-value.\")\n\n        return data\n\n    def clean_end(self):\n        \"\"\"Ensure end >= start.\"\"\"\n        start = self.cleaned_data['start']\n        end = self.cleaned_data['end']\n\n        if start and end and end < start:\n            raise forms.ValidationError('Must not be earlier than start date.')\n        return end\n\n    class Meta:\n        model = Event\n        # reorder fields, don't display 'deleted' field\n        fields = ('slug', 'start', 'end', 'site', 'organizer',\n                  'tags', 'url', 'reg_key', 'admin_fee', 'invoiced',\n                  'attendance', 'notes')\n\n    class Media:\n        # thanks to this, {{ form.media }} in the template will generate\n        # a <link href=\"\"> (for CSS files) or <script src=\"\"> (for JS files)\n        js = ('calendar_popup.js', )\n\n\nclass TaskForm(forms.ModelForm):\n\n    person = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Task\n        fields = '__all__'\n        widgets = {'event': HiddenInput}\n\n\nclass TaskFullForm(TaskForm):\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Task\n        fields = '__all__'\n\n\nclass PersonForm(forms.ModelForm):\n\n    airport = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.AirportLookup,\n        label='Airport',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    lessons = forms.ModelMultipleChoiceField(required=False,\n                                             queryset=Lesson.objects.all())\n\n    domains = forms.ModelMultipleChoiceField(\n        required=False, queryset=KnowledgeDomain.objects.all()\n    )\n\n    class Meta:\n        model = Person\n        # don't display the 'password', 'user_permissions',\n        # 'groups' or 'is_superuser' fields\n        # + reorder fields\n        fields = ['username', 'personal', 'middle', 'family', 'may_contact',\n                  'email', 'gender', 'airport', 'affiliation', 'github',\n                  'twitter', 'url', 'notes', 'lessons', 'domains']\n\n\nclass PersonPermissionsForm(forms.ModelForm):\n    class Meta:\n        model = Person\n        # only display 'user_permissions', 'groups' and `is_superuser` fields\n        fields = [\n            'is_superuser',\n            'user_permissions',\n            'groups',\n        ]\n\n\nclass PersonMergeForm(forms.Form):\n\n    person_from = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person From',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    person_to = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person To',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n\nclass BadgeAwardForm(forms.ModelForm):\n\n    person = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.PersonLookup,\n        label='Person',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Award\n        fields = '__all__'\n        widgets = {'badge': HiddenInput}\n\n\nclass PersonAwardForm(forms.ModelForm):\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=False,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Award\n        fields = '__all__'\n        widgets = {'person': HiddenInput}\n\n\nclass PersonTaskForm(forms.ModelForm):\n\n    event = selectable.AutoCompleteSelectField(\n        lookup_class=lookups.EventLookup,\n        label='Event',\n        required=True,\n        help_text=AUTOCOMPLETE_HELP_TEXT,\n        widget=selectable.AutoComboboxSelectWidget,\n    )\n\n    class Meta:\n        model = Task\n        fields = '__all__'\n        widgets = {'person': HiddenInput}\n", "path": "workshops/forms.py"}]}