Makes the form type optional for reports
This commit is contained in:
parent
960de87343
commit
f1c8e90b77
1 changed files with 10 additions and 7 deletions
|
@ -50,8 +50,9 @@ def report_view(title, form_type):
|
||||||
Arguments:
|
Arguments:
|
||||||
title (str):
|
title (str):
|
||||||
The title of the report.
|
The title of the report.
|
||||||
form_type:
|
form_type (forms.Form or None):
|
||||||
A form class that can make this report display things.
|
A form class that can make this report display things. If None,
|
||||||
|
no form will be displayed.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -61,11 +62,13 @@ def report_view(title, form_type):
|
||||||
@user_passes_test(views._staff_only)
|
@user_passes_test(views._staff_only)
|
||||||
def inner_view(request, *a, **k):
|
def inner_view(request, *a, **k):
|
||||||
|
|
||||||
form = form_type(request.GET)
|
if form_type is not None:
|
||||||
if form.is_valid() and form.has_changed():
|
form = form_type(request.GET)
|
||||||
report = view(request, form, *a, **k)
|
form.is_valid()
|
||||||
else:
|
else:
|
||||||
report = None
|
form = None
|
||||||
|
|
||||||
|
report = view(request, form, *a, **k)
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"title": title,
|
"title": title,
|
||||||
|
@ -75,7 +78,7 @@ def report_view(title, form_type):
|
||||||
|
|
||||||
return render(request, "registrasion/report.html", ctx)
|
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)
|
_all_report_views.append(inner_view)
|
||||||
|
|
||||||
# Return the callable
|
# Return the callable
|
||||||
|
|
Loading…
Reference in a new issue