Add subclass models for report types

This commit is contained in:
Oliver Walters 2020-05-22 13:01:21 +10:00
parent 251a23d127
commit 174c4cc591
3 changed files with 37 additions and 4 deletions

View File

@ -80,7 +80,7 @@ sentry:
latex: latex:
# Select the LaTeX interpreter to use for PDF rendering # Select the LaTeX interpreter to use for PDF rendering
# Note: The intepreter needs to be installed on the system! # Note: The intepreter needs to be installed on the system!
# e.g. to install pdflatx: apt-get texlive-latex-base # e.g. to install pdflatex: apt-get texlive-latex-base
interpreter: pdflatex interpreter: pdflatex
# Extra options to pass through to the LaTeX interpreter # Extra options to pass through to the LaTeX interpreter
options: '' options: ''

View File

@ -4,7 +4,7 @@ from __future__ import unicode_literals
from django.contrib import admin from django.contrib import admin
from .models import ReportTemplate, ReportAsset from .models import ReportTemplate, ReportAsset
from .models import TestReport
class ReportTemplateAdmin(admin.ModelAdmin): class ReportTemplateAdmin(admin.ModelAdmin):
@ -17,4 +17,5 @@ class ReportAssetAdmin(admin.ModelAdmin):
admin.site.register(ReportTemplate, ReportTemplateAdmin) admin.site.register(ReportTemplate, ReportTemplateAdmin)
admin.site.register(TestReport, ReportTemplateAdmin)
admin.site.register(ReportAsset, ReportAssetAdmin) admin.site.register(ReportAsset, ReportAssetAdmin)

View File

@ -38,7 +38,7 @@ class WeasyprintReportMixin(WeasyTemplateResponseMixin):
self.pdf_filename = kwargs.get('filename', 'report.pdf') self.pdf_filename = kwargs.get('filename', 'report.pdf')
class ReportTemplate(models.Model): class ReportTemplateBase(models.Model):
""" """
Reporting template model. Reporting template model.
""" """
@ -46,13 +46,16 @@ class ReportTemplate(models.Model):
def __str__(self): def __str__(self):
return os.path.basename(self.template.name) return os.path.basename(self.template.name)
def getSubdir(self):
return ''
@property @property
def extension(self): def extension(self):
return os.path.splitext(self.template.name)[1].lower() return os.path.splitext(self.template.name)[1].lower()
@property @property
def template_name(self): def template_name(self):
return os.path.join('report_template', os.path.basename(self.template.name)) return os.path.join('report_template', self.getSubdir(), os.path.basename(self.template.name))
def get_context_data(self, request): def get_context_data(self, request):
""" """
@ -105,6 +108,35 @@ class ReportTemplate(models.Model):
validators=[validate_filter_string] validators=[validate_filter_string]
) )
class Meta:
abstract = True
class ReportTemplate(ReportTemplateBase):
"""
A simple reporting template which is used to upload template files,
which can then be used in other concrete template classes.
"""
pass
class TestReport(ReportTemplateBase):
"""
Render a TestReport against a StockItem object.
"""
def getSubdir(self):
return 'test'
stock_item = None
def get_context_data(self, request):
return {
'stock_item': self.stock_item,
'results': self.stock_item.testResultMap()
}
def rename_asset(instance, filename): def rename_asset(instance, filename):