From aeef82cbf16656308730b3e3b9121a4828b526c2 Mon Sep 17 00:00:00 2001 From: Ian Murray Date: Tue, 26 Jun 2012 17:53:41 +0100 Subject: [PATCH] Useful validation errors for resource_search --- ckan/logic/action/get.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 5c03b07b63e..69ad1cd4949 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -1260,9 +1260,11 @@ def resource_search(context, data_dict): elif query is not None: if isinstance(query, basestring): query = [query] - - # TODO: escape ':' with '\:' - fields = dict(pair.split(":", 1) for pair in query) + try: + fields = dict(pair.split(":", 1) for pair in query) + except ValueError: + raise ValidationError( + {'query': _('Must be {field}:{value} pair(s)')}) else: # legacy fields paramter would split string terms # maintain that behaviour @@ -1284,7 +1286,10 @@ def resource_search(context, data_dict): if isinstance(terms, basestring): terms = [terms] if field not in resource_fields: - raise search.SearchError('Field "%s" not recognised in Resource search.' % field) + raise ValidationError( + {'query': + _('Field "{field}" not recognised in resource_search.')\ + .format(field=field)}) for term in terms: term = misc.escape_sql_like_special_characters(term) model_attr = getattr(model.Resource, field)