Commit e1a4bc36 authored by Michal Čihař's avatar Michal Čihař

Factor out filtering field

Add compatibility with new filter types and add backwards compatibility
with old URLs.

Fixes #986
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 5d525bd2
......@@ -422,6 +422,31 @@ def get_upload_form(user, project):
return SimpleUploadForm
class FilterField(forms.ChoiceField):
def __init__(self, *args, **kwargs):
kwargs['label'] = _('Search filter')
kwargs['required'] = False
kwargs['choices'] = [
('all', _('All strings')),
('nottranslated', _('Not translated strings')),
('todo', _('Strings needing attention')),
('translated', _('Translated strings')),
('fuzzy', _('Strings needing review')),
('suggestions', _('Strings with suggestions')),
('comments', _('Strings with comments')),
('allchecks', _('Strings with any failing checks')),
] + [
(check, CHECKS[check].description)
for check in CHECKS if CHECKS[check].target
]
super(FilterField, self).__init__(*args, **kwargs)
def to_python(self, value):
if value == 'untranslated':
return 'todo'
return super(FilterField, self).to_python(value)
class SearchForm(forms.Form):
'''
Text searching form.
......@@ -467,22 +492,7 @@ class SearchForm(forms.Form):
required=False,
initial=False
)
type = forms.ChoiceField(
label=_('Search filter'),
required=False,
choices=[
('all', _('All strings')),
('untranslated', _('Untranslated strings')),
('translated', _('Translated strings')),
('fuzzy', _('Strings needing review')),
('suggestions', _('Strings with suggestions')),
('comments', _('Strings with comments')),
('allchecks', _('Strings with any failing checks')),
] + [
(check, CHECKS[check].description)
for check in CHECKS if CHECKS[check].target
],
)
type = FilterField()
ignored = forms.BooleanField(
widget=forms.HiddenInput,
label=_('Show ignored checks as well'),
......
......@@ -83,6 +83,22 @@ class SearchViewTest(ViewTestCase):
response,
'<span class="hlmatch">Hello</span>, world'
)
response = self.client.get(
reverse('search'),
{'q': 'hello', 'type': 'todo'}
)
self.assertContains(
response,
'<span class="hlmatch">Hello</span>, world'
)
response = self.client.get(
reverse('search'),
{'q': 'hello', 'type': 'nottranslated'}
)
self.assertContains(
response,
'<span class="hlmatch">Hello</span>, world'
)
response = self.client.get(
reverse('search'),
{'type': 'php_format'}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment