Commit ae96ca85 authored by Olga Brani's avatar Olga Brani
Browse files

Sorting + Pagination bug

parent ea372832
......@@ -21,7 +21,7 @@
</form>
{% else %}
<div class="projects">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br />You can <a href="{% url group_create_list %}">create a new group</a> or <a href="{% url group_search %}">join</a> to an existing one.</p>
<!--<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br />You can <a href="{% url group_create_list %}">create a new group</a> or <a href="{% url group_search %}">join</a> to an existing one.</p>
<ul class="widjets clearfix">
<li>
......@@ -36,7 +36,7 @@
<p class="btn"><a href="{% url group_search %}" class="submit">JOIN</a></p>
</div>
</li>
</ul>
</ul>-->
{% endif %}
{% with page_obj.object_list as object_list %}
......@@ -136,12 +136,13 @@
{% else %}
{% if mine %}
<div class="full-dotted">
<form method="POST" class="minimal" action="/im/billing"
<form method="POST" class="minimal" action="{% url group_list %}">{% csrf_token %}
<div class="form-row">
<label for="month">Sort by</label>
<select name="sorting">
<select name="own_sorting" onchange="this.form.submit();">
<option value="0">Sort by</option>
<option value="name">Name</option>
<option value="name">Type</option>
<option value="kind">Type</option>
</select>
</div>
</form>
......@@ -192,10 +193,10 @@
<div class="pagination">
<p class="next-prev">
{% if mine.has_previous %}
<a href="?own_page={{ mine.previous_page_number }}">previous</a>
<a href="?own_page={{ mine.previous_page_number }}{% if own_sorting %}&own_sorting={{ own_sorting }}{% endif%}">previous</a>
{% endif %}
{% if mine.has_next %}
<a href="?own_page={{ mine.next_page_number }}">next</a>
<a href="?own_page={{ mine.next_page_number }}{% if own_sorting %}&own_sorting={{ own_sorting }}{% endif%}">next</a>
{% endif %}
</p>
<p class="nums">
......@@ -208,7 +209,16 @@
{% endif %}
{% if other %}
<div class="full-dotted">
<table class="alt-style complex table_sorting">
<form method="POST" class="minimal" action="{% url group_list %}">{% csrf_token %}
<div class="form-row">
<select name="other_sorting" onchange="this.form.submit();">
<option value="0">Sort by</option>
<option value="name">Name</option>
<option value="kind">Type</option>
</select>
</div>
</form>
<table class="alt-style complex">
<caption>
{% if is_search %}
SEARCH RESULTS
......
......@@ -716,11 +716,21 @@ def group_add(request, kind_name='default'):
@signed_terms_required
@login_required
def group_list(request):
own_sorting = request.POST.get('own_sorting', None)
other_sorting = request.POST.get('other_sorting', None)
q = request.user.astakos_groups.none()
list = request.user.astakos_groups.select_related().all()
d = {}
d['own'] = [g for g in list if request.user in g.owner.all()]
d['other'] = list.exclude(id__in=(g.id for g in d['own']))
d['other'] = list.exclude(id__in=(g.id for g in d['own']))
print '>>>', d['own']
if own_sorting:
sorted(d['own'], key=lambda g: g.__getattribute__(own_sorting))
print '<<<', d['own']
if other_sorting:
d['other'] = list.exclude(id__in=(g.id for g in d['own'])).order_by(other_sorting)
for k, queryset in d.iteritems():
paginator = Paginator(queryset, PAGINATE_BY)
page = request.GET.get('%s_page' % k, 1)
......@@ -739,7 +749,9 @@ def group_list(request):
return object_list(request, queryset=q,
extra_context={'is_search':False,
'mine': locals()['own_page_obj'],
'other': locals()['other_page_obj']})
'other': locals()['other_page_obj'],
'own_sorting': own_sorting,
'other_sorting': other_sorting})
@signed_terms_required
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment