Skip to content

Commit

Permalink
Fix test failures associted with related_list
Browse files Browse the repository at this point in the history
The related_list dictization changes returned them as returned by
the database. This change gives it a default order if they're not
previously sorted.
  • Loading branch information
nigelbabu authored and amercader committed Jan 8, 2014
1 parent d8a9e5c commit f66ab73
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -75,8 +75,9 @@ def related_list_dictize(related_list, context):
for res in related_list:
related_dict = related_dictize(res, context)
result_list.append(related_dict)

return result_list
if context.get('sorted'):
return result_list
return sorted(result_list, key=lambda x: x["created"], reverse=True)


def extras_dict_dictize(extras_dict, context):
Expand Down
1 change: 1 addition & 0 deletions ckan/logic/action/get.py
Expand Up @@ -249,6 +249,7 @@ def related_list(context, data_dict=None):
if data_dict.get('featured', False):
related_list = related_list.filter(model.Related.featured == 1)
related_items = related_list.all()
context['sorted'] = True
else:
relateds = model.Related.get_for_dataset(dataset, status='active')
related_items = (r.related for r in relateds)
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/functional/test_related.py
Expand Up @@ -467,7 +467,7 @@ def test_api_list(self):
r = json.loads(res.body)
assert r['success'] == True, r
assert r['result'][0]['type'] == "idea"
assert r['result'][0]['title'] == "one", r
assert r['result'][0]['title'] == "two", r

p.related.remove(one)
p.related.remove(two)
Expand Down

0 comments on commit f66ab73

Please sign in to comment.