Adds some reporting documentation
This commit is contained in:
parent
ea07469634
commit
37fbc2ee40
1 changed files with 41 additions and 0 deletions
|
@ -213,8 +213,21 @@ def report_view(title, form_type=None):
|
|||
|
||||
|
||||
class ReportView(object):
|
||||
''' View objects that can render report data into HTML or CSV. '''
|
||||
|
||||
def __init__(self, inner_view, title, form_type):
|
||||
'''
|
||||
|
||||
Arguments:
|
||||
inner_view: Callable that returns either a Report or a sequence of
|
||||
Report objects.
|
||||
|
||||
title: The title that appears at the top of all of the reports.
|
||||
|
||||
form_type: A Form class that can be used to query the report.
|
||||
|
||||
'''
|
||||
|
||||
# Consolidate form_type so it has content type and section
|
||||
self.inner_view = inner_view
|
||||
self.title = title
|
||||
|
@ -226,6 +239,8 @@ class ReportView(object):
|
|||
|
||||
def get_form(self, request):
|
||||
|
||||
''' Creates an instance of self.form_type using request.GET '''
|
||||
|
||||
# Create a form instance
|
||||
if self.form_type is not None:
|
||||
form = self.form_type(request.GET)
|
||||
|
@ -239,6 +254,10 @@ class ReportView(object):
|
|||
|
||||
@classmethod
|
||||
def wrap_reports(cls, reports, content_type):
|
||||
''' Wraps the reports in a _ReportTemplateWrapper for the given
|
||||
content_type -- this allows data to be returned as HTML links, for
|
||||
instance. '''
|
||||
|
||||
reports = [
|
||||
_ReportTemplateWrapper(content_type, report)
|
||||
for report in reports
|
||||
|
@ -247,6 +266,16 @@ class ReportView(object):
|
|||
return reports
|
||||
|
||||
def render(self, data):
|
||||
''' Renders the reports based on data.content_type's value.
|
||||
|
||||
Arguments:
|
||||
data (ReportViewRequestData): The report data. data.content_type
|
||||
is used to determine how the reports are rendered.
|
||||
|
||||
Returns:
|
||||
HTTPResponse: The rendered version of the report.
|
||||
|
||||
'''
|
||||
renderers = {
|
||||
"text/csv": self._render_as_csv,
|
||||
"text/html": self._render_as_html,
|
||||
|
@ -280,8 +309,20 @@ class ReportView(object):
|
|||
|
||||
|
||||
class ReportViewRequestData(object):
|
||||
'''
|
||||
|
||||
Attributes:
|
||||
form (Form): form based on request
|
||||
reports ([Report, ...]): The reports rendered from the request
|
||||
|
||||
Arguments:
|
||||
report_view (ReportView): The ReportView to call back to.
|
||||
request (HTTPRequest): A django HTTP request
|
||||
|
||||
'''
|
||||
|
||||
def __init__(self, report_view, request, *a, **k):
|
||||
|
||||
self.report_view = report_view
|
||||
self.request = request
|
||||
|
||||
|
|
Loading…
Reference in a new issue