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

Improve and test error handling in search

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 2c6b2a23
...@@ -248,6 +248,16 @@ class SearchViewTest(ViewTestCase): ...@@ -248,6 +248,16 @@ class SearchViewTest(ViewTestCase):
'1 / 4' '1 / 4'
) )
def test_search_errors(self):
self.do_search(
{'type': 'nonexisting-type'},
'nonexisting-type is not one of the available choices'
)
self.do_search(
{'date': 'nonexisting'},
'date: Enter a valid date.'
)
def test_search_plural(self): def test_search_plural(self):
response = self.do_search( response = self.do_search(
{'q': 'banana'}, {'q': 'banana'},
......
...@@ -100,18 +100,25 @@ def search(translation, request): ...@@ -100,18 +100,25 @@ def search(translation, request):
review_form = ReviewForm(request.GET) review_form = ReviewForm(request.GET)
search_query = None search_query = None
if review_form.is_valid(): if 'date' in request.GET:
# Review if review_form.is_valid():
allunits = translation.unit_set.review( # Review
review_form.cleaned_data['date'], allunits = translation.unit_set.review(
request.user review_form.cleaned_data['date'],
) request.user
)
formatted_date = formats.date_format( formatted_date = formats.date_format(
review_form.cleaned_data['date'], review_form.cleaned_data['date'],
'SHORT_DATE_FORMAT' 'SHORT_DATE_FORMAT'
) )
name = _('Review of translations since %s') % formatted_date name = _('Review of translations since %s') % formatted_date
else:
show_form_errors(request, review_form)
# Filtering by type
allunits = translation.unit_set.all()
name = _('All strings')
elif search_form.is_valid(): elif search_form.is_valid():
# Apply search conditions # Apply search conditions
allunits = translation.unit_set.search( allunits = translation.unit_set.search(
...@@ -123,10 +130,7 @@ def search(translation, request): ...@@ -123,10 +130,7 @@ def search(translation, request):
name = search_form.get_name() name = search_form.get_name()
else: else:
# Error reporting # Error reporting
if 'date' in request.GET: show_form_errors(request, search_form)
show_form_errors(request, review_form)
elif 'q' in request.GET or 'type' in request.GET:
show_form_errors(request, search_form)
# Filtering by type # Filtering by type
allunits = translation.unit_set.all() allunits = translation.unit_set.all()
......
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