diff --git a/InvenTree/InvenTree/static/script/inventree/label_admin.js b/InvenTree/InvenTree/static/script/inventree/label_admin.js index 4496b362a94..23b00e19b8b 100644 --- a/InvenTree/InvenTree/static/script/inventree/label_admin.js +++ b/InvenTree/InvenTree/static/script/inventree/label_admin.js @@ -2,7 +2,7 @@ function updateDropDownItemsVisibility() { var multipageWidgetNames = ['page_width', 'page_height', 'pagesize_preset', 'page_orientation', - 'multipage_border']; + 'multipage_border', 'multipage_common_style']; multipageWidgetNames.forEach(function(widget) { if (django.jQuery('#id_multipage').prop("checked")) django.jQuery('.field-' + widget).show(); diff --git a/InvenTree/label/admin.py b/InvenTree/label/admin.py index 276ea0a4bd7..3d5dbb96868 100644 --- a/InvenTree/label/admin.py +++ b/InvenTree/label/admin.py @@ -5,8 +5,10 @@ from django.utils.translation import gettext_lazy as _ import label.models -from .models import (LabelTemplate, PartLabel, StockItemLabel, - StockLocationLabel, BuildLineLabel) + +from .models import (BuildLineLabel, LabelTemplate, PartLabel, StockItemLabel, + StockLocationLabel) + class LabelAdminForm(forms.ModelForm): """Custom form for the label's admin form to inject non-model fields""" @@ -15,7 +17,7 @@ class Meta: model = LabelTemplate fields = ['metadata', 'name', 'description', 'label', 'enabled', 'width', 'height', 'filename_pattern', 'multipage', 'pagesize_preset', 'page_orientation', - 'page_width', 'page_height', 'multipage_border'] + 'page_width', 'page_height', 'multipage_border', 'multipage_common_style'] pagesize_preset = forms.ChoiceField( choices=[ @@ -57,11 +59,12 @@ class Meta: model = PartLabel fields = LabelAdminForm.Meta.fields + ["filters"] + class BuildLineLabelAdminForm(LabelAdminForm): """Custom form for the Build line label's admin form""" class Meta: """Meta is just for adding the fields field to the right position (last field)""" - model = PartLabel + model = BuildLineLabel fields = LabelAdminForm.Meta.fields + ["filters"] @@ -75,6 +78,7 @@ class Media: 'script/inventree/label_admin.js', ) + class StockLabelAdmin(LabelAdmin): """Admin class for the Stock label models""" form = StockItemLabelAdminForm @@ -89,12 +93,13 @@ class PartLabelAdmin(LabelAdmin): """Admin class for the Stock location label models""" form = PartLabelAdminForm -class BuildLineLabel(LabelAdmin): + +class BuildLineLabelAdmin(LabelAdmin): """Admin class for the Build line label models""" form = BuildLineLabelAdminForm + admin.site.register(label.models.StockItemLabel, LabelAdmin) admin.site.register(label.models.StockLocationLabel, LabelAdmin) admin.site.register(label.models.PartLabel, LabelAdmin) admin.site.register(label.models.BuildLineLabel, LabelAdmin) - diff --git a/InvenTree/label/models.py b/InvenTree/label/models.py index 47058606e9f..d9f1443838e 100644 --- a/InvenTree/label/models.py +++ b/InvenTree/label/models.py @@ -194,6 +194,13 @@ def __str__(self): blank=True, ) + multipage_common_style = models.TextField( + verbose_name=_('Common style for multiple labels per page'), + help_text=_("This CSS snippet will be generated once into the generated label once" + "into the head section of the main (builtin) template which providing the grid table for the individual labels."), + blank=True, + ) + @property def template_name(self): """Returns the file system path to the template file. @@ -255,7 +262,9 @@ def context_multipage(self, request, content): 'page_height': self.page_height, 'label_width': self.width, 'label_height': self.height, - 'content': content} + 'multipage_common_style': self.multipage_common_style, + 'content': content, + } # Pass the context through to any registered plugins plugins = registry.with_mixin('report') diff --git a/InvenTree/label/templates/label/multipage_label_base.html b/InvenTree/label/templates/label/multipage_label_base.html index ced306c876c..78d8f870257 100644 --- a/InvenTree/label/templates/label/multipage_label_base.html +++ b/InvenTree/label/templates/label/multipage_label_base.html @@ -41,6 +41,8 @@ body { margin: 0mm !important; } + + {{ multipage_common_style }} {% endlocalize %} diff --git a/docs/docs/report/labels.md b/docs/docs/report/labels.md index bb1cad9d55d..c82e9e23981 100644 --- a/docs/docs/report/labels.md +++ b/docs/docs/report/labels.md @@ -142,6 +142,18 @@ As an example, consider a label template for a StockItem. A user may wish to def To restrict the label accordingly, we could set the *filters* value to `part__IPN=IPN123`. +### Printing multiple pages per page + +If the 'Print multiple labels to a single page' option is enabled for a specific label then the label rendering is going to be performed in a different way: +- A builtin template (InvenTree/label/templates/label/multipage_label_base.html) will provide an HTML table which serves as a grid +- The labels' contents will be rendered to the cells of this table through the uploaded template + +This implies the following: +- The uploaded template file should not include the head/body sections +- The CSS included in the label's uploaded template will be generated to each cell. + This should not cause rendering issues, however it is advisable to move the common styles into the 'Common style for multiple labels per page' field. + The contents of this field will be rendered into the style tag in the head section of the grid template, so this was redundant CSS could be eliminated from the output. + ## Built-In Templates The InvenTree installation provides a number of simple *default* templates which can be used as a starting point for creating custom labels. These built-in templates can be disabled if they are not required.