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
...
 
@@ -2,5 +2,8 @@ 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
...
 
@@ -55,4 +58,9 @@ class Report(object):
 

	
 

	
 
''' 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
...
 
@@ -84,8 +92,39 @@ 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):
registrasion/urls.py
Show inline comments
...
 
@@ -38,4 +38,5 @@ 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)