From fb022bbc7b92f8ba313035882c352ea9f2513597 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 2 Sep 2016 09:55:29 +1000 Subject: [PATCH] Adds a view that shows all reports --- registrasion/staff_views.py | 39 +++++++++++++++++++++++++++++++++++++ registrasion/urls.py | 1 + 2 files changed, 40 insertions(+) diff --git a/registrasion/staff_views.py b/registrasion/staff_views.py index 77226ab0..c07c5a92 100644 --- a/registrasion/staff_views.py +++ b/registrasion/staff_views.py @@ -1,7 +1,10 @@ import forms import views +from collections import namedtuple + from django.contrib.auth.decorators import user_passes_test +from django.core.urlresolvers import reverse from django.db import models from django.db.models import F, Q from django.db.models import Sum @@ -54,6 +57,11 @@ class Report(object): return self._data +''' A list of report views objects that can be used to load a list of +reports. ''' +_all_report_views = [] + + def report(title, form_type): ''' Decorator that converts a report view function into something that displays a Report. @@ -83,10 +91,41 @@ def report(title, form_type): return render(request, "registrasion/report.html", ctx) + # Add this report to the list of reports -- makes this reversable. + _all_report_views.append(inner_view) + + # Return the callable return inner_view return _report +@user_passes_test(views._staff_only) +def reports_list(request): + ''' Lists all of the reports currently available. ''' + + reports = [] + + for report in _all_report_views: + reports.append({ + "name" : report.__name__, + "url" : reverse(report), + "description" : report.__doc__, + }) + + reports.sort(key=lambda report: report["name"]) + + ctx = { + "reports" : reports, + } + + print reports + + return render(request, "registrasion/reports_list.html", ctx) + + +# Report functions + + @report("Paid items", forms.ProductAndCategoryForm) def items_sold(request, form): ''' Summarises the items sold and discounts granted for a given set of diff --git a/registrasion/urls.py b/registrasion/urls.py index 43f58110..d051c277 100644 --- a/registrasion/urls.py +++ b/registrasion/urls.py @@ -37,6 +37,7 @@ public = [ reports = [ + url(r"^$", staff_views.reports_list, name="reports_list"), url(r"^inventory/?$", staff_views.inventory, name="inventory"), url(r"^items_sold/?$", staff_views.items_sold, name="items_sold"), ]