Skip to content

Commit

Permalink
[ckan#2981] Preserve sort order in groups on pagination
Browse files Browse the repository at this point in the history
- Uses the same code that was introuced in ckan#2153 for organizations
- Changes the tests to sort descending so that they actually make sure
  that the sort order is not changed
  • Loading branch information
k-nut committed May 20, 2016
1 parent 05eb241 commit b1f9c75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ckan/templates/group/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="hide-heading">{{ _('Groups') }}</h1>
{% endif %}
{% endblock %}
{% block page_pagination %}
{{ c.page.pager() }}
{{ c.page.pager(q=c.q or '', sort=c.sort_by_selected or '') }}
{% endblock %}
{% endblock %}

Expand Down
31 changes: 24 additions & 7 deletions ckan/tests/controllers/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,34 @@ def test_bulk_process_throws_404_for_nonexistent_org(self):
action='bulk_process', id='does-not-exist')
app.get(url=bulk_process_url, status=404)

def test_page_thru_list_of_orgs(self):
orgs = [factories.Organization() for i in range(35)]
def test_page_thru_list_of_orgs_preserves_sort_order(self):
orgs = [factories.Organization() for _ in range(35)]
app = self._get_test_app()
org_url = url_for(controller='organization', action='index')
org_url = url_for(controller='organization',
action='index',
sort='name desc')
response = app.get(url=org_url)
assert orgs[0]['name'] in response
assert orgs[-1]['name'] not in response
assert orgs[-1]['name'] in response
assert orgs[0]['name'] not in response

response2 = response.click('2')
assert orgs[0]['name'] not in response2
assert orgs[-1]['name'] in response2
assert orgs[-1]['name'] not in response2
assert orgs[0]['name'] in response2

def test_page_thru_list_of_groups_preserves_sort_order(self):
groups = [factories.Group() for _ in range(35)]
app = self._get_test_app()
group_url = url_for(controller='group',
action='index',
sort='title desc')

response = app.get(url=group_url)
assert groups[-1]['title'] in response
assert groups[0]['title'] not in response

response2 = response.click(r'^2$')
assert groups[-1]['title'] not in response2
assert groups[0]['title'] in response2


def _get_group_new_page(app):
Expand Down

0 comments on commit b1f9c75

Please sign in to comment.