Skip to content

Commit

Permalink
Useful validation errors for resource_search
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Murray authored and tobes committed Jul 2, 2012
1 parent f8450f4 commit aeef82c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ckan/logic/action/get.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit aeef82c

Please sign in to comment.