diff --git a/fincom/items/views.py b/fincom/items/views.py index 82dce67..4cab057 100644 --- a/fincom/items/views.py +++ b/fincom/items/views.py @@ -1,6 +1,7 @@ from django.shortcuts import HttpResponse, HttpResponseRedirect from django.template import loader from django.utils import timezone +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib.auth.decorators import login_required from django.db.models import Q from models import Item @@ -25,16 +26,33 @@ def myItems(user): return Item.objects.filter(Q(created_by=user) | Q(committee__in=comms)) \ .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 def list(request): template = loader.get_template('items/list.html') items = myItems(request.user) + mine = Item.objects.filter(created_by=request.user).order_by('-date_filed') + context = { - 'preapproved': items.filter(status=Item.PREAPPROVED), - 'processed': items.filter(status=Item.PROCESSED), - 'newitems': items.filter(status=Item.NEW), - 'rejected': items.filter(status=Item.REJECTED), + 'preapproved': pageItems(request, items, Item.PREAPPROVED), + 'processed': pageItems(request, items, Item.PROCESSED), + 'newitems': pageItems(request, items, Item.NEW), + 'rejected': pageItems(request, items, Item.REJECTED), + 'mine': pageItems(request, mine, 'M'), } return HttpResponse(template.render(context, request)) diff --git a/fincom/static/sass/items.scss b/fincom/static/sass/items.scss index 285b030..e7dbc9a 100644 --- a/fincom/static/sass/items.scss +++ b/fincom/static/sass/items.scss @@ -9,6 +9,27 @@ section { 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 { padding: $pad-m $pad-xl; margin: 0px; diff --git a/fincom/templates/items/list.html b/fincom/templates/items/list.html index 6b0e47c..300bb6a 100644 --- a/fincom/templates/items/list.html +++ b/fincom/templates/items/list.html @@ -9,49 +9,33 @@ {% endif %} {% if preapproved %} -
Pre-Approved
-
-{% for I in preapproved %} - {% include "./item.html" %} -{% empty %} -
No Reimbursements
-{% endfor %} -
+{% with items=preapproved pagination_key="C" name="Pre-Approved" %} + {% include "./section.html" %} +{% endwith %} {% endif %} {% if newitems %} -
New Items
-
-{% for I in newitems %} - {% include "./item.html" %} -{% empty %} -
No Reimbursements
-{% endfor %} -
+{% with items=newitems pagination_key="N" name="New Items" %} + {% include "./section.html" %} +{% endwith %} {% endif %} {% if processed %} -
Approved
-
-{% for I in processed %} - {% include "./item.html" %} -{% empty %} -
No Reimbursements
-{% endfor %} -
+{% with items=processed pagination_key="P" name="Approved" %} + {% include "./section.html" %} +{% endwith %} {% endif %} {% if rejected %} -
Rejected
-
-{% for I in rejected %} - {% include "./item.html" %} -{% empty %} -
No Reimbursements
-{% endfor %} -
+{% with items=rejected pagination_key="R" name="Rejected" %} + {% include "./section.html" %} +{% endwith %} {% endif %} +{% with items=mine pagination_key="M" name="My Reimbursements" %} + {% include "./section.html" %} +{% endwith %} + {% endblock %} {% block bottom %} diff --git a/fincom/templates/items/section.html b/fincom/templates/items/section.html new file mode 100644 index 0000000..8333d84 --- /dev/null +++ b/fincom/templates/items/section.html @@ -0,0 +1,22 @@ +
{{ name }}
+
+ {% for I in items %} + {% include "./item.html" %} + {% empty %} +
No Reimbursements
+ {% endfor %} + {% if items.has_next %} + + Older → + + {% else %} + Older → + {% endif %} + {% if items.has_previous %} + + ← Newer + + {% else %} + ← Newer + {% endif %} +