Skip to content

Commit

Permalink
[2330] Extended allowable argument types of "term_translation_show" a…
Browse files Browse the repository at this point in the history
…ction.

Extended the `terms` and (optional) `lang_codes` arguments to accept a
string in lieu of a unit-length list of strings.  This ensures compatibility
with access to this action via a GET request where the arguments are
constructed from URL parameters.
  • Loading branch information
Ian Murray committed May 14, 2012
1 parent 33ba385 commit 4e52232
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -1055,10 +1055,20 @@ def term_translation_show(context, data_dict):
if 'terms' not in data_dict:
raise ValidationError({'terms': 'terms not in data'})

q = q.where(trans_table.c.term.in_(_get_or_bust(data_dict, 'terms')))

# This action accepts `terms` as either a list of strings, or a single
# string.
terms = _get_or_bust(data_dict, 'terms')
if isinstance(terms, basestring):
terms = [terms]
q = q.where(trans_table.c.term.in_(terms))

# This action accepts `lang_codes` as either a list of strings, or a single
# string.
if 'lang_codes' in data_dict:
q = q.where(trans_table.c.lang_code.in_(_get_or_bust(data_dict, 'lang_codes')))
lang_codes = _get_or_bust(data_dict, 'lang_codes')
if isinstance(lang_codes, basestring):
lang_codes = [lang_codes]
q = q.where(trans_table.c.lang_code.in_(lang_codes))

conn = model.Session.connection()
cursor = conn.execute(q)
Expand Down

0 comments on commit 4e52232

Please sign in to comment.