Commit e5773f79 authored by njoyard's avatar njoyard Committed by GitHub
Browse files

Merge pull request #110 from political-memory/sorting

Add sorting to rep list and dossier list
parents 1dde5a4c 5fbcc1ac
Display :
- if active_only
current legislature only /
%a{'href': '?={queries.urlencode}&active_only=0'}
all data
- else
%a{'href': '?={queries.urlencode}&active_only=1'}
current legislature only
="/ all data"
\ No newline at end of file
.active-block
Display :
- if active_only
current legislature only /
%a{'href': '?={queries.urlencode}&active_only=0'}
all data
- else
%a{'href': '?={queries.urlencode}&active_only=1'}
current legislature only
="/ all data"
\ No newline at end of file
%span.grid-list-selector
%a{:href => '?={queries.urlencode}&display=grid'}
%a{:href => '?={queries.urlencode}&display=grid'}<
<i class="fa fa-th"></i>
%a{:href => '?={queries.urlencode}&display=list'}
%a{:href => '?={queries.urlencode}&display=list'}<
<i class="fa fa-th-list"></i>
......@@ -36,21 +36,24 @@
<i aria-hidden="true" class="fa fa-chevron-circle-right"></i>
%div.count
Number of results : {{ paginator.count }}
.count-block
Number of results : {{ paginator.count }}
- if active_only != None
%br
- include 'core/blocks/active-filter.html'
%br
Number of displayed results :
{{ paginator.per_page }}
(
- for limit in pagination_limits
%a{'href': '?={queries.urlencode}&paginate_by={{ limit }}'}
{{ limit }}
- if not forloop.last
\/
)
- if grid_list
- include 'core/blocks/grid-list.html'
- if sort != None
- include 'core/blocks/sorting.html'
.page-size-block
Number of displayed results :
{{ paginator.per_page }}
(
- for limit in pagination_limits
%a{'href': '?={queries.urlencode}&paginate_by={{ limit }}'}<
{{ limit }}
- if not forloop.last
\/
)
- if grid_list
- include 'core/blocks/grid-list.html'
- if sort.fields|length > 0
.sorting-block
Order by :
- for field, label in sort.fields.items
- if sort.field == field
{{ label }}
- else
%a{'href': '?={queries.urlencode}&sort_by=={field}'}<
{{ label }}
- if not forloop.last
=" | "
&ndash;
- if sort.dir == 'asc'
ascending |
%a{'href': '?={queries.urlencode}&sort_dir=desc'}<
descending
- else
%a{'href': '?={queries.urlencode}&sort_dir=asc'}<
ascending
="| descending"
......@@ -50,6 +50,61 @@ class ActiveLegislatureMixin(object):
return c
class SortMixin(object):
"""
Mixin for views that allow sorting.
The sort_fields attribute should be defined to a {field: label} dict
containing all fields usable for sorting.
The sort_default and sort_default_dir attributes should contain the default
sorting settings.
"""
sort_fields = {}
sort_default_field = None
sort_default_dir = 'asc'
def get(self, *args, **kwargs):
self.set_sorting()
return super(SortMixin, self).get(*args, **kwargs)
def set_sorting(self):
if 'sort_by' in self.request.GET:
self.request.session['sort_by'] = self.request.GET['sort_by']
elif 'sort_by' not in self.request.session:
self.request.session['sort_by'] = self.sort_default_field
if self.request.session['sort_by'] not in self.sort_fields:
self.request.session['sort_by'] = self.sort_default_field
if 'sort_dir' in self.request.GET:
self.request.session['sort_dir'] = self.request.GET['sort_dir']
elif 'sort_dir' not in self.request.session:
self.request.session['sort_dir'] = self.sort_default_dir
def get_context_data(self, **kwargs):
c = super(SortMixin, self).get_context_data(**kwargs)
c['queries'] = copy(self.request.GET)
if 'sort_by' in c['queries']:
del c['queries']['sort_by']
if 'sort_dir' in c['queries']:
del c['queries']['sort_dir']
c['sort'] = {
'fields': self.sort_fields,
'field': self.request.session['sort_by'],
'dir': self.request.session['sort_dir'],
}
return c
def get_queryset(self):
qs = super(SortMixin, self).get_queryset()
if self.request.session['sort_by']:
qs = qs.order_by('%s%s' % (
'-' if self.request.session['sort_dir'] == 'desc' else '',
self.request.session['sort_by']))
return qs
class PaginationMixin(object):
pagination_limits = (12, 24, 48, 96)
......
......@@ -123,42 +123,84 @@
</ul>
</nav>
<div class='count'>
Number of results : 1
<div class='count-block'>
Number of results : 1
</div>
<br />
Number of displayed results :
12
(
<a href='?&paginate_by=12'>
12
</a>
/
<div class='sorting-block'>
Order by :
<a href='?&paginate_by=24'>
24
</a>
<a href='?&sort_by=nb_proposals'>proposals</a>
|
/
recommendations
|
<a href='?&paginate_by=48'>
48
</a>
<a href='?&sort_by=reference'>reference</a>
|
/
<a href='?&sort_by=title'>title</a>
<a href='?&paginate_by=96'>
96
</a>
&ndash;
<a href='?&sort_dir=asc'>ascending</a>
| descending
</div>
)
<div class='page-size-block'>
Number of displayed results :
12
(
<a href='?&paginate_by=12'>12</a>
/
<a href='?&paginate_by=24'>24</a>
/
<a href='?&paginate_by=48'>48</a>
/
<a href='?&paginate_by=96'>96</a>
)
</div>
</div>
</div>
......@@ -215,42 +257,84 @@
</ul>
</nav>
<div class='count'>
Number of results : 1
<div class='count-block'>
Number of results : 1
</div>
<br />
Number of displayed results :
12
(
<a href='?&paginate_by=12'>
12
</a>
/
<div class='sorting-block'>
Order by :
<a href='?&paginate_by=24'>
24
</a>
<a href='?&sort_by=nb_proposals'>proposals</a>
|
/
recommendations
|
<a href='?&paginate_by=48'>
48
</a>
<a href='?&sort_by=reference'>reference</a>
|
/
<a href='?&sort_by=title'>title</a>
<a href='?&paginate_by=96'>
96
</a>
&ndash;
<a href='?&sort_dir=asc'>ascending</a>
| descending
</div>
)
<div class='page-size-block'>
Number of displayed results :
12
(
<a href='?&paginate_by=12'>12</a>
/
<a href='?&paginate_by=24'>24</a>
/
<a href='?&paginate_by=48'>48</a>
/
<a href='?&paginate_by=96'>96</a>
)
</div>
</div>
</div>
......
......@@ -123,42 +123,84 @@
</ul>
</nav>
<div class='count'>
Number of results : 1
<div class='count-block'>
Number of results : 1
</div>
<br />
Number of displayed results :
12
(
<a href='?search=acta&paginate_by=12'>
12
</a>
/
<div class='sorting-block'>
Order by :
<a href='?search=acta&paginate_by=24'>
24
</a>
<a href='?search=acta&sort_by=nb_proposals'>proposals</a>
|
/
recommendations
|
<a href='?search=acta&paginate_by=48'>
48
</a>
<a href='?search=acta&sort_by=reference'>reference</a>
|
/
<a href='?search=acta&sort_by=title'>title</a>
<a href='?search=acta&paginate_by=96'>
96
</a>
&ndash;
<a href='?search=acta&sort_dir=asc'>ascending</a>
| descending
</div>
)
<div class='page-size-block'>
Number of displayed results :
12
(
<a href='?search=acta&paginate_by=12'>12</a>
/
<a href='?search=acta&paginate_by=24'>24</a>
/
<a href='?search=acta&paginate_by=48'>48</a>
/
<a href='?search=acta&paginate_by=96'>96</a>
)
</div>
</div>
</div>
......@@ -215,42 +257,84 @@
</ul>
</nav>
<div class='count'>
Number of results : 1
<div class='count-block'>
Number of results : 1
</div>
<br />
Number of displayed results :
12
(
<a href='?search=acta&paginate_by=12'>
12
</a>
/
<div class='sorting-block'>
Order by :
<a href='?search=acta&paginate_by=24'>
24
</a>
<a href='?search=acta&sort_by=nb_proposals'>proposals</a>
|
/
recommendations
|
<a href='?search=acta&paginate_by=48'>
48
</a>
<a href='?search=acta&sort_by=reference'>reference</a>
|
/
<a href='?search=acta&sort_by=title'>title</a>
<a href='?search=acta&paginate_by=96'>
96
</a>
&ndash;
<a href='?search=acta&sort_dir=asc'>ascending</a>
| descending
</div>
)
<div class='page-size-block'>
Number of displayed results :
12
(
<a href='?search=acta&paginate_by=12'>12</a>
/
<a href='?search=acta&paginate_by=24'>24</a>
/
<a href='?search=acta&paginate_by=48'>48</a>
/
<a href='?search=acta&paginate_by=96'>96</a>
)
</div>
</div>
</div>
......
<!DOCTYPE html>
<html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="/static/collected/img/favicon.ico" />
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width" />
<title>
Home
- The Political Memory of </title>