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):
'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):
response = self.do_search(
{'q': 'banana'},
......
......@@ -100,18 +100,25 @@ def search(translation, request):
review_form = ReviewForm(request.GET)
search_query = None
if review_form.is_valid():
# Review
allunits = translation.unit_set.review(
review_form.cleaned_data['date'],
request.user
)
if 'date' in request.GET:
if review_form.is_valid():
# Review
allunits = translation.unit_set.review(
review_form.cleaned_data['date'],
request.user
)
formatted_date = formats.date_format(
review_form.cleaned_data['date'],
'SHORT_DATE_FORMAT'
)
name = _('Review of translations since %s') % formatted_date
formatted_date = formats.date_format(
review_form.cleaned_data['date'],
'SHORT_DATE_FORMAT'
)
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():
# Apply search conditions
allunits = translation.unit_set.search(
......@@ -123,10 +130,7 @@ def search(translation, request):
name = search_form.get_name()
else:
# Error reporting
if 'date' in request.GET:
show_form_errors(request, review_form)
elif 'q' in request.GET or 'type' in request.GET:
show_form_errors(request, search_form)
show_form_errors(request, search_form)
# Filtering by type
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