2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Extend ReportMixin class to support labels (#4678)

* Extend ReportMixin context to shim label templates also

* Update docs
This commit is contained in:
Oliver
2023-04-22 23:46:43 +10:00
committed by GitHub
parent 50cbaff76d
commit 8df207d8e1
3 changed files with 29 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import part.models
import stock.models
from InvenTree.helpers import normalize, validateFilterString
from InvenTree.models import MetadataMixin
from plugin.registry import registry
try:
from django_weasyprint import WeasyTemplateResponseMixin
@ -190,6 +191,13 @@ class LabelTemplate(MetadataMixin, models.Model):
context['width'] = self.width
context['height'] = self.height
# Pass the context through to any registered plugins
plugins = registry.with_mixin('report')
for plugin in plugins:
# Let each plugin add its own context data
plugin.add_label_context(self, self.object_to_print, request, context)
return context
def render_as_string(self, request, **kwargs):

View File

@ -34,3 +34,16 @@ class ReportMixin:
context: The context dictionary to add to
"""
pass
def add_label_context(self, label_instance, model_instance, request, context):
"""Add extra context to the provided label instance.
By default, this method does nothing.
Args:
label_instance: The label instance to add context to
model_instance: The model instance which initiated the label generation
request: The request object which initiated the label generation
context: The context dictionary to add to
"""
pass