talk list sorting
This commit is contained in:
parent
24732e4171
commit
7fe3582730
|
@ -76,6 +76,9 @@ class Talk(PonyConfModel):
|
|||
event = models.ForeignKey(Event, verbose_name=_('Intervention kind'))
|
||||
accepted = models.NullBooleanField(default=None)
|
||||
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
<form class="form-horizontal" method="get">
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-xs-6">
|
||||
{% bootstrap_field filter_form.kind layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.kind layout="horizontal" %}
|
||||
</div>
|
||||
<div class="col-md-4 col-xs-6">
|
||||
{% bootstrap_field filter_form.status layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.status layout="horizontal" %}
|
||||
</div>
|
||||
<div class="col-md-4 col-xs-6">
|
||||
{% bootstrap_field filter_form.topic layout="horizontal" %}
|
||||
{% bootstrap_field filter_form.topic layout="horizontal" %}
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success" value="Filter">
|
||||
|
@ -34,11 +34,11 @@
|
|||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">{% trans "Title" %} <a href="#"><span class="glyphicon glyphicon-sort pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Intervention kind" %} <a href="#"><span class="glyphicon glyphicon-sort pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Speakers" %} <a href="#"><span class="glyphicon glyphicon-sort pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Topics" %} <a href="#"><span class="glyphicon glyphicon-sort pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Status" %} <a href="#"><span class="glyphicon glyphicon-sort pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Title" %} <a href="?{{ sort_urls.title }}"><span class="glyphicon glyphicon-{{ sort_glyphicons.title }} pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Intervention kind" %} <a href="?{{ sort_urls.kind }}"><span class="glyphicon glyphicon-{{ sort_glyphicons.kind }} pull-right"></span></a></th>
|
||||
<th class="text-center">{% trans "Speakers" %}</th>
|
||||
<th class="text-center">{% trans "Topics" %}</th>
|
||||
<th class="text-center">{% trans "Status" %} <a href="?{{ sort_urls.status }}"><span class="glyphicon glyphicon-{{ sort_glyphicons.status }} pull-right"></span></a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for talk in talk_list %}
|
||||
|
|
|
@ -65,19 +65,57 @@ def talk_list(request):
|
|||
show_filters = False
|
||||
talks = Talk.objects.filter(site=get_current_site(request))
|
||||
filter_form = FilterForm(request.GET or None, site=get_current_site(request))
|
||||
# Filtering
|
||||
if filter_form.is_valid():
|
||||
data = filter_form.cleaned_data
|
||||
if len(data['kind']):
|
||||
show_filters = True
|
||||
talks = talks.filter(reduce(lambda x, y: x | y, [Q(event__pk=pk) for pk in data['kind']]))
|
||||
if len(data['status']):
|
||||
show_filters = True
|
||||
talks = talks.filter(reduce(lambda x, y: x | y, [Q(accepted=dict(STATUS_VALUES)[status]) for status in data['status']]))
|
||||
if len(data['topic']):
|
||||
show_filters = True
|
||||
talks = talks.filter(reduce(lambda x, y: x | y, [Q(topics__slug=topic) for topic in data['topic']]))
|
||||
show_filters = True
|
||||
# Sorting
|
||||
if request.GET.get('order') == 'desc':
|
||||
reverse = True
|
||||
else:
|
||||
reverse = False
|
||||
SORT_MAPPING = {
|
||||
'title': 'title',
|
||||
'kind': 'event',
|
||||
'status': 'accepted',
|
||||
}
|
||||
sort = request.GET.get('sort')
|
||||
if sort in SORT_MAPPING.keys():
|
||||
if reverse:
|
||||
talks = talks.order_by('-' + SORT_MAPPING[sort])
|
||||
else:
|
||||
talks = talks.order_by(SORT_MAPPING[sort])
|
||||
# Sorting URLs
|
||||
sort_urls = dict()
|
||||
sort_glyphicons = dict()
|
||||
for c in SORT_MAPPING.keys():
|
||||
url = request.GET.copy()
|
||||
url['sort'] = c
|
||||
if c == sort:
|
||||
if reverse:
|
||||
del url['order']
|
||||
glyphicon = 'sort-by-attributes-alt'
|
||||
else:
|
||||
url['order'] = 'desc'
|
||||
glyphicon = 'sort-by-attributes'
|
||||
else:
|
||||
glyphicon = 'sort'
|
||||
sort_urls[c] = url.urlencode()
|
||||
sort_glyphicons[c] = glyphicon
|
||||
return render(request, 'proposals/talk_list.html', {
|
||||
'show_filters': show_filters,
|
||||
'talk_list': talks,
|
||||
'filter_form': filter_form,
|
||||
'sort_urls': sort_urls,
|
||||
'sort_glyphicons': sort_glyphicons,
|
||||
})
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in New Issue