Paginate everything on the list page
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from django.shortcuts import HttpResponse, HttpResponseRedirect
|
from django.shortcuts import HttpResponse, HttpResponseRedirect
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from models import Item
|
from models import Item
|
||||||
@@ -25,16 +26,33 @@ def myItems(user):
|
|||||||
return Item.objects.filter(Q(created_by=user) | Q(committee__in=comms)) \
|
return Item.objects.filter(Q(created_by=user) | Q(committee__in=comms)) \
|
||||||
.order_by('-date_filed', 'desc')
|
.order_by('-date_filed', 'desc')
|
||||||
|
|
||||||
|
def pageItems(request, items, status):
|
||||||
|
if status != 'M':
|
||||||
|
p = Paginator(items.filter(status=status), 8)
|
||||||
|
else:
|
||||||
|
p = Paginator(items, 8)
|
||||||
|
page = request.GET.get(status)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return p.page(page)
|
||||||
|
except PageNotAnInteger:
|
||||||
|
return p.page(1)
|
||||||
|
except EmptyPage:
|
||||||
|
return p.page(p.num_pages)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def list(request):
|
def list(request):
|
||||||
template = loader.get_template('items/list.html')
|
template = loader.get_template('items/list.html')
|
||||||
items = myItems(request.user)
|
items = myItems(request.user)
|
||||||
|
mine = Item.objects.filter(created_by=request.user).order_by('-date_filed')
|
||||||
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'preapproved': items.filter(status=Item.PREAPPROVED),
|
'preapproved': pageItems(request, items, Item.PREAPPROVED),
|
||||||
'processed': items.filter(status=Item.PROCESSED),
|
'processed': pageItems(request, items, Item.PROCESSED),
|
||||||
'newitems': items.filter(status=Item.NEW),
|
'newitems': pageItems(request, items, Item.NEW),
|
||||||
'rejected': items.filter(status=Item.REJECTED),
|
'rejected': pageItems(request, items, Item.REJECTED),
|
||||||
|
'mine': pageItems(request, mine, 'M'),
|
||||||
}
|
}
|
||||||
|
|
||||||
return HttpResponse(template.render(context, request))
|
return HttpResponse(template.render(context, request))
|
||||||
|
|||||||
@@ -9,6 +9,27 @@ section {
|
|||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.items {
|
||||||
|
a.page {
|
||||||
|
display: inline-block;
|
||||||
|
margin: $pad-m;
|
||||||
|
text-decoration: none;
|
||||||
|
color: $midgray;
|
||||||
|
font-size: 12px;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.page:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
color: $purple;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.page.empty:hover {
|
||||||
|
color: $midgray;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.item {
|
.item {
|
||||||
padding: $pad-m $pad-xl;
|
padding: $pad-m $pad-xl;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
|||||||
@@ -9,49 +9,33 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if preapproved %}
|
{% if preapproved %}
|
||||||
<section>Pre-Approved</section>
|
{% with items=preapproved pagination_key="C" name="Pre-Approved" %}
|
||||||
<div>
|
{% include "./section.html" %}
|
||||||
{% for I in preapproved %}
|
{% endwith %}
|
||||||
{% include "./item.html" %}
|
|
||||||
{% empty %}
|
|
||||||
<div class="empty">No Reimbursements</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if newitems %}
|
{% if newitems %}
|
||||||
<section>New Items</section>
|
{% with items=newitems pagination_key="N" name="New Items" %}
|
||||||
<div>
|
{% include "./section.html" %}
|
||||||
{% for I in newitems %}
|
{% endwith %}
|
||||||
{% include "./item.html" %}
|
|
||||||
{% empty %}
|
|
||||||
<div class="empty">No Reimbursements</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if processed %}
|
{% if processed %}
|
||||||
<section>Approved</section>
|
{% with items=processed pagination_key="P" name="Approved" %}
|
||||||
<div>
|
{% include "./section.html" %}
|
||||||
{% for I in processed %}
|
{% endwith %}
|
||||||
{% include "./item.html" %}
|
|
||||||
{% empty %}
|
|
||||||
<div class="empty">No Reimbursements</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if rejected %}
|
{% if rejected %}
|
||||||
<section>Rejected</section>
|
{% with items=rejected pagination_key="R" name="Rejected" %}
|
||||||
<div>
|
{% include "./section.html" %}
|
||||||
{% for I in rejected %}
|
{% endwith %}
|
||||||
{% include "./item.html" %}
|
|
||||||
{% empty %}
|
|
||||||
<div class="empty">No Reimbursements</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% with items=mine pagination_key="M" name="My Reimbursements" %}
|
||||||
|
{% include "./section.html" %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block bottom %}
|
{% block bottom %}
|
||||||
|
|||||||
22
fincom/templates/items/section.html
Normal file
22
fincom/templates/items/section.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<section>{{ name }}</section>
|
||||||
|
<div class="items">
|
||||||
|
{% for I in items %}
|
||||||
|
{% include "./item.html" %}
|
||||||
|
{% empty %}
|
||||||
|
<div class="empty">No Reimbursements</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% if items.has_next %}
|
||||||
|
<a class="page" href="?{{ pagination_key }}={{ items.next_page_number }}">
|
||||||
|
Older →
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="page empty" href="#">Older →</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if items.has_previous %}
|
||||||
|
<a class="page" href="?{{ pagination_key }}={{ items.previous_page_number }}">
|
||||||
|
← Newer
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="page empty" href="#">← Newer</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user