def get_context_data(self, **kwargs): """ Gets context for the template, including the report, graded rubric items, and context needed to display the report Returns: dict : context for template """ context = super(Feedback, self).get_context_data(**kwargs) context['reportSups'] = ReportSupplement.objects.filter( report=self.report) context['rpt'] = self.report context['gRub'] = self.report.rubric context['gri1'] = self.GRIs.filter(item__section=1).order_by( "item__order", "item__pk") context['gri2'] = self.GRIs.filter(item__section=2).order_by( "item__order", "item__pk") context['gri3'] = self.GRIs.filter(item__section=3).order_by( "item__order", "item__pk") context['gri4'] = self.GRIs.filter(item__section=4).order_by( "item__order", "item__pk") context = section1Context(self, context) context = section2Context(self, context) context = section3Context(self, context) context = section4Context(self, context) return context
def get_context_data(self, **kwargs): """ Gets the context data, including the report, the graded rubric and items, and the context needed to display the report Returns: dict : context for template """ context = super(RubricReview, self).get_context_data(**kwargs) context['reportSups'] = ReportSupplement.objects.filter( report=self.report) rIs = RubricItem.objects.filter( rubricVersion=self.report.rubric.rubricVersion) context['gRub'] = self.report.rubric context['object_list'] = self.GRIs context['rIs1'] = allRubricItemsSomeGrades( rIs.filter(section=1).order_by("order", "pk"), self.GRIs) context['rIs2'] = allRubricItemsSomeGrades( rIs.filter(section=2).order_by("order", "pk"), self.GRIs) context['rIs3'] = allRubricItemsSomeGrades( rIs.filter(section=3).order_by("order", "pk"), self.GRIs) context['rIs4'] = allRubricItemsSomeGrades( rIs.filter(section=4).order_by("order", "pk"), self.GRIs) context = section1Context(self, context) context = section2Context(self, context) context = section3Context(self, context) context = section4Context(self, context) context['toDo'] = todoGetter(4, self.report) context['reqTodo'] = len(context['toDo']['r']) context['sugTodo'] = len(context['toDo']['s']) return context
def get_context_data(self, **kwargs): """ Gets context needed to display section 3 of the form Returns: dict : context for template """ context = super(Section3Grading, self).get_context_data(**kwargs) return section3Context(self, context)
def get_context_data(self, **kwargs): """ Gets the context for the template, including the report and context needed for each section Returns: dict : context for template """ context = super(ReportPDFGen, self).get_context_data(**kwargs) context['rubric'] = self.report.rubric context['rpt'] = self.report context = section1Context(self, context) context = section2Context(self, context) context = section3Context(self, context) context = section4Context(self, context) return context
def get_context_data(self, **kwargs): """ Gets the context for the template, including the rubric and graded rubric items for the report, separated by section Returns: dict : template context """ context = super(PDFPreview, self).get_context_data(**kwargs) context['rubric'] = self.report.rubric context['rpt'] = self.report context = section1Context(self, context) context = section2Context(self, context) context = section3Context(self, context) context = section4Context(self, context) return context
def get_context_data(self, **kwargs): """ Gets template context, including the report, report supplements, and context needed for displaying all 4 sections Returns: dict : context for template """ context = super(DisplayReport, self).get_context_data(**kwargs) context['rpt'] = self.report context['reportSups'] = ReportSupplement.objects.filter( report=self.report) context = section1Context(self, context) context = section2Context(self, context) context = section3Context(self, context) context = section4Context(self, context) return context
def get_context_data(self, **kwargs): """ Returns template context, including the current report Returns: dict : context of template """ context = super(OverallComment, self).get_context_data(**kwargs) context['reportSups'] = ReportSupplement.objects.filter( report=self.report) context = section1Context(self, context) context = section2Context(self, context) context = section3Context(self, context) context = section4Context(self, context) context['toDo'] = todoGetter(4, self.report) context['reqTodo'] = len(context['toDo']['r']) context['sugTodo'] = len(context['toDo']['s']) return context
def reportPDF(request, report): """ View to generate report PDF with supplements Args: request (HttpRequest): request to view page report (str): primary key of :class:`~makeReports.models.basic_models.Report` Returns: HttpResponse : the PDF Notes: A function instead of class due to limitations of class based views """ #first get report or return 404 error report = get_object_or_404(Report, pk=report) #get templates for each of the sections (sec 1 and 2 together since sec 1 doesn't have supplements) sec1and2 = get_template('makeReports/DisplayReport/PDFsub/pdf1and2.html') sec3 = get_template('makeReports/DisplayReport/PDFsub/pdf3.html') sec4 = get_template('makeReports/DisplayReport/PDFsub/pdf4.html') #build the context needed for the report context = {'rpt': report, 'report': report} #SimpleNamespace lets report be accessed via dot-notation in section#Context s = SimpleNamespace(**context) context = section1Context(s, context) context = section2Context(s, context) #render HTML string for section 1 and 2 p1and2 = sec1and2.render(context).encode() #reset context for section 3 context = {'rpt': report, 'report': report} context = section3Context(s, context) #render HTML string for section 3 p3 = sec3.render(context).encode() #reset context context = {'rpt': report, 'report': report} context = section4Context(s, context) #render HTML string for section 4 p4 = sec4.render(context).encode() #get all supplements (PDFs) that go with the report assessSups = AssessmentSupplement.objects.filter( assessmentversion__report=report) dataSups = DataAdditionalInformation.objects.filter(report=report) repSups = ReportSupplement.objects.filter(report=report) #get the HTML of all sections html1and2 = HTML(string=p1and2) html3 = HTML(string=p3) html4 = HTML(string=p4) #set-up temporary files to write pdfs for each section f1and2 = tempfile.TemporaryFile() f3 = tempfile.TemporaryFile() f4 = tempfile.TemporaryFile() #write to those temporary files from the HTML generated html1and2.write_pdf( target=f1and2, stylesheets=[CSS(staticfiles_storage.path('css/report.css'))]) html3.write_pdf(target=f3, stylesheets=[ CSS(staticfiles_storage.path('css/report.css')), CSS(staticfiles_storage.path('css/shelves.css')) ]) html4.write_pdf( target=f4, stylesheets=[CSS(staticfiles_storage.path('css/report.css'))]) #set-up a merger to merge all PDFs together merged = PdfFileMerger() merged.append(f1and2) #start with section 1 and 2, then append assessment supplements merged = addSupplements(assessSups, merged) #add section 3 merged.append(f3) #append data supplements merged = addSupplements(dataSups, merged) #append section 4 merged.append(f4) #add report supplements merged = addSupplements(repSups, merged) #write the merged pdf to the HTTP Response http_response = HttpResponse(content_type="application/pdf") merged.write(http_response) return http_response