Skip to content

Commit

Permalink
Merge pull request #15 from moschlar/develop
Browse files Browse the repository at this point in the history
Fix for #12 - Robustness of search field
  • Loading branch information
amol- committed Jun 25, 2013
2 parents 43a4d2e + 1b77e80 commit e76e61b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tgext/crud/controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
"""
import tg
from tg import expose, flash, redirect, tmpl_context, request
from tg import expose, flash, redirect, tmpl_context, request, abort
from tg.decorators import without_trailing_slash, with_trailing_slash, before_validate
from tg.controllers import RestController

Expand Down Expand Up @@ -266,7 +266,10 @@ def get_all(self, *args, **kw):

if tg.request.response_type == 'application/json':
adapt_params_for_pagination(kw, self.pagination_enabled)
count, values = self.table_filler._do_get_provider_count_and_objs(**kw)
try:
count, values = self.table_filler._do_get_provider_count_and_objs(**kw)
except Exception as e:
abort(400, detail=unicode(e))
values = self._dictify(values, length=count)
if self.pagination_enabled:
values = SmartPaginationCollection(values, count)
Expand All @@ -280,7 +283,14 @@ def get_all(self, *args, **kw):
substring_filters = self.substring_filters

adapt_params_for_pagination(kw, self.pagination_enabled)
values = self.table_filler.get_value(substring_filters=substring_filters, **kw)
try:
values = self.table_filler.get_value(substring_filters=substring_filters, **kw)
except Exception as e:
flash(u'Invalid search query "%s": %s' % (request.query_string, e), 'warn')
# Reset all variables to sane defaults
kw = {}
values = []
self.table_filler.__count__ = 0
if self.pagination_enabled:
values = SmartPaginationCollection(values, self.table_filler.__count__)
else:
Expand Down

0 comments on commit e76e61b

Please sign in to comment.