Open bevokactp opened 8 years ago
Please try latest version. Possibly fixed (or related) in #528
I am installed latest version your labour
!pip list | egrep 'suit|Django'
Django (1.9.7)
django-suit (0.2.19)
import sys
sys.version
'3.4.3 (default, Oct 14 2015, 20:28:29) \n[GCC 4.8.4]'
But the problem still has in my project
My custom view without changes:
def view_make_report(self, request):
"""View for ability of creating an Pdf reports in the admin."""
# if request`s method is GET,
# then return simple view for customization creating of Pdf report
if request.method == 'GET':
context = dict(
self.admin_site.each_context(request),
title=_('Make a report about polls'),
current_app=apps.get_app_config(Poll._meta.app_label),
django_admin_media=self.media,
)
return TemplateResponse(request, "polls/admin/report.html", context)
# if request`s method is POST,
# then Pdf report as file
elif request.method == 'POST':
# get type output of report: pdf or excel
output_report = request.POST.get('output_report', None)
# get subjects of report
subjects = [
request.POST.get('polls', None),
request.POST.get('choices', None),
request.POST.get('votes', None),
request.POST.get('voters', None),
request.POST.get('results', None),
]
subjects = [subject for subject in subjects if subject]
if not subjects:
return HttpResponseBadRequest('Not specified any theme for report.')
# generate pdf-report by subject
if output_report == 'report_pdf':
report = PollPDFReport(request, subjects)
# generate excel-report
elif output_report == 'report_excel':
report = ExcelReport(request, subjects)
else:
return HttpResponseBadRequest(_('Type of report is not supplied.'))
response = report.make_report()
return response
Result:
def view_make_report(self, request):
"""View for ability of creating an Pdf reports in the admin."""
# I ADDED THAT AND NOW ALL WORKING
request.current_app = 'admin'
# if request`s method is GET,
# then return simple view for customization creating of Pdf report
if request.method == 'GET':
context = dict(
self.admin_site.each_context(request),
title=_('Make a report about polls'),
current_app=apps.get_app_config(Poll._meta.app_label),
django_admin_media=self.media,
)
return TemplateResponse(request, "polls/admin/report.html", context)
# if request`s method is POST,
# then Pdf report as file
elif request.method == 'POST':
# get type output of report: pdf or excel
output_report = request.POST.get('output_report', None)
# get subjects of report
subjects = [
request.POST.get('polls', None),
request.POST.get('choices', None),
request.POST.get('votes', None),
request.POST.get('voters', None),
request.POST.get('results', None),
]
subjects = [subject for subject in subjects if subject]
if not subjects:
return HttpResponseBadRequest('Not specified any theme for report.')
# generate pdf-report by subject
if output_report == 'report_pdf':
report = PollPDFReport(request, subjects)
# generate excel-report
elif output_report == 'report_excel':
report = ExcelReport(request, subjects)
else:
return HttpResponseBadRequest(_('Type of report is not supplied.'))
response = report.make_report()
return response
Result:
If this is a bug please specify versions you're using first.
Django version: Django==1.9.5 Django Suit version: django-suit==0.2.18 Python version: Python 3.4.3 (default, Oct 14 2015, 20:28:29)
Issue: I a custom views is missed a value "request.current_app", hence not displaying a menu in the left sidebar
For it, I created next decorator:
Usage (from my current project):
For me it is working.
Much-esteemed creator django-suit, if you have a free time, please amend your project. Otherwise give me feedback, and I do make necessary changes alone (
)