Skip to content

Commit

Permalink
Merge branch '1384-related-list-503'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Dec 17, 2013
2 parents 5b30653 + 27831b3 commit ec8e5a0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions ckan/controllers/related.py
Expand Up @@ -40,7 +40,7 @@ def dashboard(self):
base.abort(400, ('"page" parameter must be an integer'))

# Update ordering in the context
query = logic.get_action('related_list')(context, data_dict)
related_list = logic.get_action('related_list')(context, data_dict)

def search_url(params):
url = h.url_for(controller='related', action='dashboard')
Expand All @@ -55,10 +55,10 @@ def pager_url(q=None, page=None):
return search_url(params)

c.page = h.Page(
collection=query.all(),
collection=related_list,
page=page,
url=pager_url,
item_count=query.count(),
item_count=len(related_list),
items_per_page=9
)

Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/dictization/model_dictize.py
Expand Up @@ -91,7 +91,7 @@ def related_list_dictize(related_list, context):
related_dict = related_dictize(res, context)
result_list.append(related_dict)

return sorted(result_list, key=lambda x: x["created"], reverse=True)
return result_list


def extras_dict_dictize(extras_dict, context):
Expand Down
5 changes: 2 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -214,8 +214,6 @@ def related_show(context, data_dict=None):
def related_list(context, data_dict=None):
'''Return a dataset's related items.
Either the ``id`` or the ``dataset`` parameter must be given.
:param id: id or name of the dataset (optional)
:type id: string
:param dataset: dataset dictionary of the dataset (optional)
Expand Down Expand Up @@ -264,10 +262,11 @@ 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()
else:
relateds = model.Related.get_for_dataset(dataset, status='active')
related_items = (r.related for r in relateds)
related_list = model_dictize.related_list_dictize( related_items, context)
related_list = model_dictize.related_list_dictize( related_items, context)
return related_list


Expand Down
11 changes: 8 additions & 3 deletions ckan/tests/functional/test_related.py
Expand Up @@ -367,8 +367,13 @@ def test_related_list_missing_id_and_name(self):
usr = logic.get_action('get_site_user')({'model':model,'ignore_auth': True},{})
context = dict(model=model, user=usr['name'], session=model.Session)
data_dict = {}
from sqlalchemy.orm.query import Query
assert type(logic.get_action('related_list')(context, data_dict)) == Query
related_list = logic.get_action('related_list')(context, data_dict)
assert len(related_list) == 8
related_keys = set(['view_count', 'description', 'title', 'url',
'created', 'featured', 'image_url', 'type', 'id', 'owner_id'])
for related in related_list:
assert set(related.keys()) == related_keys


def test_related_list(self):
p = model.Package.get('warandpeace')
Expand Down Expand Up @@ -462,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'] == "two", r
assert r['result'][0]['title'] == "one", r

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

0 comments on commit ec8e5a0

Please sign in to comment.