Changeset - fb022bbc7b92
[Not reviewed]
0 2 0
Christopher Neugebauer - 8 years ago 2016-09-01 23:55:29
chrisjrn@gmail.com
Adds a view that shows all reports
2 files changed with 40 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/staff_views.py
Show inline comments
 
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
registrasion/urls.py
Show inline comments
...
 
@@ -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"),
 
]
0 comments (0 inline, 0 general)