Changeset - f1c8e90b77d3
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-09-02 00:28:24
chrisjrn@gmail.com
Makes the form type optional for reports
1 file changed with 10 insertions and 7 deletions:
0 comments (0 inline, 0 general)
registrasion/reporting/reports.py
Show inline comments
...
 
@@ -41,49 +41,52 @@ class Report(object):
 
    def data(self):
 
        ''' Returns the data rows for the table. '''
 
        return self._data
 

	
 

	
 
def report_view(title, form_type):
 
    ''' Decorator that converts a report view function into something that
 
    displays a Report.
 

	
 
    Arguments:
 
        title (str):
 
            The title of the report.
 
        form_type:
 
            A form class that can make this report display things.
 
        form_type (forms.Form or None):
 
            A form class that can make this report display things. If None,
 
            no form will be displayed.
 

	
 
    '''
 

	
 
    def _report(view):
 

	
 
        @wraps(view)
 
        @user_passes_test(views._staff_only)
 
        def inner_view(request, *a, **k):
 

	
 
            form = form_type(request.GET)
 
            if form.is_valid() and form.has_changed():
 
                report = view(request, form, *a, **k)
 
            if form_type is not None:
 
                form = form_type(request.GET)
 
                form.is_valid()
 
            else:
 
                report = None
 
                form = None
 

	
 
            report = view(request, form, *a, **k)
 

	
 
            ctx = {
 
                "title": title,
 
                "form": form,
 
                "report": report,
 
            }
 

	
 
            return render(request, "registrasion/report.html", ctx)
 

	
 
        # Add this report to the list of reports -- makes this reversable.
 
        # Add this report to the list of reports.
 
        _all_report_views.append(inner_view)
 

	
 
        # Return the callable
 
        return inner_view
 
    return _report
 

	
 

	
 
def get_all_reports():
 
    ''' Returns all the views that have been registered with @report '''
 

	
 
    return list(_all_report_views)
0 comments (0 inline, 0 general)