comparison custom_search/forms.py @ 956:6cc9221d04a7

Issue #85: fix 500 error with custom search form. Can't rely on exact being in cleaned_data if there is an error with it.
author Brian Neal <bgneal@gmail.com>
date Sat, 30 May 2015 17:41:11 -0500
parents cf9918328c64
children 2f36abf65a62
comparison
equal deleted inserted replaced
953:8647a669edb4 956:6cc9221d04a7
52 super(CustomModelSearchForm, self).__init__(*args, **kwargs) 52 super(CustomModelSearchForm, self).__init__(*args, **kwargs)
53 self.fields['models'] = forms.MultipleChoiceField(choices=MODEL_CHOICES, 53 self.fields['models'] = forms.MultipleChoiceField(choices=MODEL_CHOICES,
54 label='Search in', widget=forms.CheckboxSelectMultiple) 54 label='Search in', widget=forms.CheckboxSelectMultiple)
55 55
56 def clean(self): 56 def clean(self):
57 super(CustomModelSearchForm, self).clean()
57 if not settings.SEARCH_QUEUE_ENABLED: 58 if not settings.SEARCH_QUEUE_ENABLED:
58 raise forms.ValidationError("Our search function is offline for " 59 raise forms.ValidationError("Our search function is offline for "
59 "maintenance. Please try again later. " 60 "maintenance. Please try again later. "
60 "We apologize for any inconvenience.") 61 "We apologize for any inconvenience.")
61 62
62 if not (self.cleaned_data['q'] or self.cleaned_data['exact'] or 63 q = self.cleaned_data.get('q')
63 self.cleaned_data['exclude']): 64 exact = self.cleaned_data.get('exact')
65 exclude = self.cleaned_data.get('exclude')
66
67 if not (q or exact or exclude):
64 raise forms.ValidationError('Please supply some search terms') 68 raise forms.ValidationError('Please supply some search terms')
65 69
66 return self.cleaned_data 70 return self.cleaned_data
67 71
68 def clean_exact(self): 72 def clean_exact(self):