From f9f191b5e32d088ff85f1d7cd7639d7c687948b6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 12 May 2021 15:31:35 +0200 Subject: [PATCH 1/9] Inclusion in all tamplates #1574 --- InvenTree/build/templates/build/detail.html | 16 ++++++++-------- .../templates/company/company_base.html | 10 +++++----- .../company/templates/company/detail.html | 6 +++--- .../company/manufacturer_part_base.html | 10 +++++----- .../templates/company/supplier_part_base.html | 19 ++++++++++--------- .../company/supplier_part_detail.html | 8 ++++---- .../order/templates/order/order_base.html | 10 +++++----- .../templates/order/sales_order_base.html | 10 +++++----- InvenTree/part/templates/part/detail.html | 12 ++++++------ 9 files changed, 51 insertions(+), 50 deletions(-) diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 9bc1dd77cc..1b4c577b07 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -19,12 +19,12 @@ {% trans "Description" %} - {{ build.title }} + {{ build.title }}{% include "clip.html"%} {% trans "Part" %} - {{ build.part.full_name }} + {{ build.part.full_name }}{% include "clip.html"%} @@ -35,7 +35,7 @@ {% trans "Stock Source" %} {% if build.take_from %} - {{ build.take_from }} + {{ build.take_from }}{% include "clip.html"%} {% else %} {% trans "Stock can be taken from any available location." %} {% endif %} @@ -48,7 +48,7 @@ {% if build.destination %} {{ build.destination }} - + {% include "clip.html"%} {% else %} {% trans "Destination location not specified" %} {% endif %} @@ -68,28 +68,28 @@ {% trans "Batch" %} - {{ build.batch }} + {{ build.batch }}{% include "clip.html"%} {% endif %} {% if build.parent %} {% trans "Parent Build" %} - {{ build.parent }} + {{ build.parent }}{% include "clip.html"%} {% endif %} {% if build.sales_order %} {% trans "Sales Order" %} - {{ build.sales_order }} + {{ build.sales_order }}{% include "clip.html"%} {% endif %} {% if build.link %} {% trans "External Link" %} - {{ build.link }} + {{ build.link }}{% include "clip.html"%} {% endif %} {% if build.issued_by %} diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index 1825132b0e..7012272762 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -68,35 +68,35 @@ {% trans "Website" %} - {{ company.website }} + {{ company.website }}{% include "clip.html"%} {% endif %} {% if company.address %} {% trans "Address" %} - {{ company.address }} + {{ company.address }}{% include "clip.html"%} {% endif %} {% if company.phone %} {% trans "Phone" %} - {{ company.phone }} + {{ company.phone }}{% include "clip.html"%} {% endif %} {% if company.email %} {% trans "Email" %} - {{ company.email }} + {{ company.email }}{% include "clip.html"%} {% endif %} {% if company.contact %} {% trans "Contact" %} - {{ company.contact }} + {{ company.contact }}{% include "clip.html"%} {% endif %} diff --git a/InvenTree/company/templates/company/detail.html b/InvenTree/company/templates/company/detail.html index 9fdd6d0c05..9c3cbfb84a 100644 --- a/InvenTree/company/templates/company/detail.html +++ b/InvenTree/company/templates/company/detail.html @@ -19,20 +19,20 @@ {% trans "Company Name" %} - {{ company.name }} + {{ company.name }}{% include "clip.html"%} {% if company.description %} {% trans "Description" %} - {{ company.description }} + {{ company.description }}{% include "clip.html"%} {% endif %} {% trans "Website" %} - {% if company.website %}{{ company.website }} + {% if company.website %}{{ company.website }}{% include "clip.html"%} {% else %}{% trans "No website specified" %} {% endif %} diff --git a/InvenTree/company/templates/company/manufacturer_part_base.html b/InvenTree/company/templates/company/manufacturer_part_base.html index 441f1f845b..c3a64d9d76 100644 --- a/InvenTree/company/templates/company/manufacturer_part_base.html +++ b/InvenTree/company/templates/company/manufacturer_part_base.html @@ -62,7 +62,7 @@ src="{% static 'img/blank_image.png' %}" {% trans "Internal Part" %} {% if part.part %} - {{ part.part.full_name }} + {{ part.part.full_name }}{% include "clip.html"%} {% endif %} @@ -70,24 +70,24 @@ src="{% static 'img/blank_image.png' %}" {% trans "Description" %} - {{ part.description }} + {{ part.description }}{% include "clip.html"%} {% endif %} {% if part.link %} {% trans "External Link" %} - {{ part.link }} + {{ part.link }}{% include "clip.html"%} {% endif %} {% trans "Manufacturer" %} - {{ part.manufacturer.name }} + {{ part.manufacturer.name }}{% include "clip.html"%} {% trans "MPN" %} - {{ part.MPN }} + {{ part.MPN }}{% include "clip.html"%} {% endblock %} diff --git a/InvenTree/company/templates/company/supplier_part_base.html b/InvenTree/company/templates/company/supplier_part_base.html index 3716128bd8..bf6d914f19 100644 --- a/InvenTree/company/templates/company/supplier_part_base.html +++ b/InvenTree/company/templates/company/supplier_part_base.html @@ -61,7 +61,7 @@ src="{% static 'img/blank_image.png' %}" {% trans "Internal Part" %} {% if part.part %} - {{ part.part.full_name }} + {{ part.part.full_name }}{% include "clip.html"%} {% endif %} @@ -69,51 +69,52 @@ src="{% static 'img/blank_image.png' %}" {% trans "Description" %} - {{ part.description }} + {{ part.description }}{% include "clip.html"%} {% endif %} {% if part.link %} {% trans "External Link" %} - {{ part.link }} + {{ part.link }}{% include "clip.html"%} {% endif %} {% trans "Supplier" %} - {{ part.supplier.name }} + {{ part.supplier.name }}{% include "clip.html"%} {% trans "SKU" %} - {{ part.SKU }} + {{ part.SKU }}{% include "clip.html"%} {% if part.manufacturer_part.manufacturer %} {% trans "Manufacturer" %} - {{ part.manufacturer_part.manufacturer.name }} + + {{ part.manufacturer_part.manufacturer.name }}{% include "clip.html"%} {% endif %} {% if part.manufacturer_part.MPN %} {% trans "MPN" %} - {{ part.manufacturer_part.MPN }} + {{ part.manufacturer_part.MPN }}{% include "clip.html"%} {% endif %} {% if part.packaging %} {% trans "Packaging" %} - {{ part.packaging }} + {{ part.packaging }}{% include "clip.html"%} {% endif %} {% if part.note %} {% trans "Note" %} - {{ part.note }} + {{ part.note }}{% include "clip.html"%} {% endif %} diff --git a/InvenTree/company/templates/company/supplier_part_detail.html b/InvenTree/company/templates/company/supplier_part_detail.html index 285f81c326..fb73ca06f4 100644 --- a/InvenTree/company/templates/company/supplier_part_detail.html +++ b/InvenTree/company/templates/company/supplier_part_detail.html @@ -28,14 +28,14 @@ {% trans "External Link" %}{{ part.link }} {% endif %} {% if part.description %} - {% trans "Description" %}{{ part.description }} + {% trans "Description" %}{{ part.description }}{% include "clip.html"%} {% endif %} {% if part.manufacturer %} - {% trans "Manufacturer" %}{{ part.manufacturer }} - {% trans "MPN" %}{{ part.MPN }} + {% trans "Manufacturer" %}{{ part.manufacturer }}{% include "clip.html"%} + {% trans "MPN" %}{{ part.MPN }}{% include "clip.html"%} {% endif %} {% if part.note %} - {% trans "Note" %}{{ part.note }} + {% trans "Note" %}{{ part.note }}{% include "clip.html"%} {% endif %} diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index b29b62a4ad..642f866506 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -33,7 +33,7 @@ src="{% static 'img/blank_image.png' %}" {% endif %}
-

{{ order.description }}

+

{{ order.description }}{% include "clip.html"%}

+ + +
diff --git a/InvenTree/templates/version.html b/InvenTree/templates/version.html new file mode 100644 index 0000000000..c8ec6862b6 --- /dev/null +++ b/InvenTree/templates/version.html @@ -0,0 +1,5 @@ +# Version Information:{% load inventree_extras %} +InvenTree-Version: {% inventree_version %} +Django Version: {% django_version %} +{% inventree_commit_hash as hash %}{% if hash %}Commit Hash: {{ hash }}{% endif %} +{% inventree_commit_date as commit_date %}{% if commit_date %}Commit Date: {{ commit_date }}{% endif %} \ No newline at end of file From 5077419b689dd54da8d20371a1f800e13333b708 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 13 May 2021 00:20:51 +0200 Subject: [PATCH 6/9] fewer js-functions --- .../static/script/inventree/inventree.js | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index afc2a80755..4b43b342af 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -1,40 +1,31 @@ -function attachClipboard(selector) { +function attachClipboard(selector, containerselector, textElement) { + // set container + if (containerselector){ + containerselector = document.getElementById(containerselector); + } else { + containerselector = document.body; + } - var cis = new ClipboardJS(selector, { - text: function(trigger) { - var content = trigger.parentElement.parentElement.textContent; - - return content.trim(); + // set text-function + if (textElement){ + text = function() { + return document.getElementById(textElement).textContent; } + } else { + text = function() { + var content = trigger.parentElement.parentElement.textContent;return content.trim(); + } + } + + // create Clipboard + var cis = new ClipboardJS(selector, { + text: text, + container: containerselector }); console.log(cis); } -function attachmodalClipboard(selector) { - - new ClipboardJS(selector, { - text: function(trigger) { - var content = trigger.parentElement.parentElement.textContent; - return content.trim(); - }, - container: document.getElementById('modal-about') - }); -} - - -function AboutClipboard(selector) { - - new ClipboardJS(selector, { - text: function() { - console.log('about'); - return document.getElementById('about-copy-text').textContent; - }, - container: document.getElementById('modal-about') - }); -} - - function inventreeDocReady() { /* Run this function when the HTML document is loaded. * This will be called for every page that extends "base.html" @@ -88,8 +79,8 @@ function inventreeDocReady() { // Initialize clipboard-buttons attachClipboard('.clip-btn'); - attachmodalClipboard('.clip-btn'); - AboutClipboard('.clip-btn-version'); + attachClipboard('.clip-btn', 'modal-about'); // modals + attachClipboard('.clip-btn-version', 'modal-about', 'about-copy-text'); // version-text } From ba3f3108d7c7204c23f8ae5d6317c167668722b8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 13 May 2021 00:21:42 +0200 Subject: [PATCH 7/9] missing translation --- InvenTree/templates/about.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/about.html b/InvenTree/templates/about.html index 7d40388d3b..f190ab2755 100644 --- a/InvenTree/templates/about.html +++ b/InvenTree/templates/about.html @@ -77,7 +77,7 @@ - + From 6de44a59217d167d7547c790a39819446ed2c85b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 13 May 2021 13:23:51 +1000 Subject: [PATCH 8/9] Adds a "filename_template" field to reports - Allows users to define the naming scheme for generated reports - Templated, can use any context variable already available to the report instance - Adds some more context variables to various reports --- InvenTree/report/api.py | 10 ++++- .../migrations/0016_auto_20210513_1303.py | 38 +++++++++++++++++++ InvenTree/report/models.py | 26 ++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 InvenTree/report/migrations/0016_auto_20210513_1303.py diff --git a/InvenTree/report/api.py b/InvenTree/report/api.py index 351a988601..f09a52f272 100644 --- a/InvenTree/report/api.py +++ b/InvenTree/report/api.py @@ -208,16 +208,24 @@ class ReportPrintMixin: # In debug mode, generate single HTML output, rather than PDF debug_mode = common.models.InvenTreeSetting.get_setting('REPORT_DEBUG_MODE') + # Start with a default report name + report_name = "report.pdf" + # Merge one or more PDF files into a single download for item in items_to_print: report = self.get_object() report.object_to_print = item + report_name = report.generate_filename(request) + if debug_mode: outputs.append(report.render_as_string(request)) else: outputs.append(report.render(request)) + if not report_name.endswith('.pdf'): + report_name += '.pdf' + if debug_mode: """ Contatenate all rendered templates into a single HTML string, @@ -248,7 +256,7 @@ class ReportPrintMixin: return InvenTree.helpers.DownloadFile( pdf, - 'inventree_report.pdf', + report_name, content_type='application/pdf' ) diff --git a/InvenTree/report/migrations/0016_auto_20210513_1303.py b/InvenTree/report/migrations/0016_auto_20210513_1303.py new file mode 100644 index 0000000000..5b1e950dea --- /dev/null +++ b/InvenTree/report/migrations/0016_auto_20210513_1303.py @@ -0,0 +1,38 @@ +# Generated by Django 3.2 on 2021-05-13 03:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('report', '0015_auto_20210403_1837'), + ] + + operations = [ + migrations.AddField( + model_name='billofmaterialsreport', + name='filename_pattern', + field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'), + ), + migrations.AddField( + model_name='buildreport', + name='filename_pattern', + field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'), + ), + migrations.AddField( + model_name='purchaseorderreport', + name='filename_pattern', + field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'), + ), + migrations.AddField( + model_name='salesorderreport', + name='filename_pattern', + field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'), + ), + migrations.AddField( + model_name='testreport', + name='filename_pattern', + field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'), + ), + ] diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index fa7ae2b271..dfb7c09679 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -16,6 +16,7 @@ from django.conf import settings from django.core.exceptions import ValidationError, FieldError from django.template.loader import render_to_string +from django.template import Template, Context from django.core.files.storage import FileSystemStorage from django.core.validators import FileExtensionValidator @@ -224,6 +225,7 @@ class ReportTemplateBase(ReportBase): All context to be passed to the renderer. """ + # Generate custom context data based on the particular report subclass context = self.get_context_data(request) context['base_url'] = common.models.InvenTreeSetting.get_setting('INVENTREE_BASE_URL') @@ -238,9 +240,22 @@ class ReportTemplateBase(ReportBase): return context + def generate_filename(self, request, **kwargs): + """ + Generate a filename for this report + """ + + template_string = Template(self.filename_pattern) + + ctx = self.context(request) + + context = Context(ctx) + + return template_string.render(context) + def render_as_string(self, request, **kwargs): """ - Render the report to a HTML stiring. + Render the report to a HTML string. Useful for debug mode (viewing generated code) """ @@ -269,6 +284,13 @@ class ReportTemplateBase(ReportBase): self.context(request), **kwargs) + filename_pattern = models.CharField( + default="report.pdf", + verbose_name=_('Filename Pattern'), + help_text=_('Pattern for generating report filenames'), + max_length=100, + ) + enabled = models.BooleanField( default=True, verbose_name=_('Enabled'), @@ -326,6 +348,7 @@ class TestReport(ReportTemplateBase): return { 'stock_item': stock_item, + 'serial': stock_item.serial, 'part': stock_item.part, 'results': stock_item.testResultMap(include_installed=self.include_installed), 'result_list': stock_item.testResultList(include_installed=self.include_installed) @@ -367,6 +390,7 @@ class BuildReport(ReportTemplateBase): 'bom_items': my_build.part.get_bom_items(), 'reference': my_build.reference, 'quantity': my_build.quantity, + 'title': str(my_build), } From 82a3d9ca967f80d25e9bf09fe56d79acd81e779f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 13 May 2021 13:40:40 +1000 Subject: [PATCH 9/9] Implements custom naming for generated labels --- InvenTree/label/api.py | 9 +++++++- .../migrations/0007_auto_20210513_1327.py | 23 +++++++++++++++++++ InvenTree/label/models.py | 22 ++++++++++++++++++ InvenTree/report/models.py | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 InvenTree/label/migrations/0007_auto_20210513_1327.py diff --git a/InvenTree/label/api.py b/InvenTree/label/api.py index fc082e4a50..8522857e30 100644 --- a/InvenTree/label/api.py +++ b/InvenTree/label/api.py @@ -63,16 +63,23 @@ class LabelPrintMixin: # In debug mode, generate single HTML output, rather than PDF debug_mode = common.models.InvenTreeSetting.get_setting('REPORT_DEBUG_MODE') + label_name = "label.pdf" + # Merge one or more PDF files into a single download for item in items_to_print: label = self.get_object() label.object_to_print = item + label_name = label.generate_filename(request) + if debug_mode: outputs.append(label.render_as_string(request)) else: outputs.append(label.render(request)) + if not label_name.endswith(".pdf"): + label_name += ".pdf" + if debug_mode: """ Contatenate all rendered templates into a single HTML string, @@ -103,7 +110,7 @@ class LabelPrintMixin: return InvenTree.helpers.DownloadFile( pdf, - 'inventree_label.pdf', + label_name, content_type='application/pdf' ) diff --git a/InvenTree/label/migrations/0007_auto_20210513_1327.py b/InvenTree/label/migrations/0007_auto_20210513_1327.py new file mode 100644 index 0000000000..d49c83c92b --- /dev/null +++ b/InvenTree/label/migrations/0007_auto_20210513_1327.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2 on 2021-05-13 03:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('label', '0006_auto_20210222_1535'), + ] + + operations = [ + migrations.AddField( + model_name='stockitemlabel', + name='filename_pattern', + field=models.CharField(default='label.pdf', help_text='Pattern for generating label filenames', max_length=100, verbose_name='Filename Pattern'), + ), + migrations.AddField( + model_name='stocklocationlabel', + name='filename_pattern', + field=models.CharField(default='label.pdf', help_text='Pattern for generating label filenames', max_length=100, verbose_name='Filename Pattern'), + ), + ] diff --git a/InvenTree/label/models.py b/InvenTree/label/models.py index 71ccc73ac9..a5d8314193 100644 --- a/InvenTree/label/models.py +++ b/InvenTree/label/models.py @@ -15,6 +15,7 @@ from django.db import models from django.core.validators import FileExtensionValidator, MinValueValidator from django.core.exceptions import ValidationError, FieldError +from django.template import Template, Context from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ @@ -138,6 +139,13 @@ class LabelTemplate(models.Model): validators=[MinValueValidator(2)] ) + filename_pattern = models.CharField( + default="label.pdf", + verbose_name=_('Filename Pattern'), + help_text=_('Pattern for generating label filenames'), + max_length=100, + ) + @property def template_name(self): """ @@ -162,6 +170,19 @@ class LabelTemplate(models.Model): return {} + def generate_filename(self, request, **kwargs): + """ + Generate a filename for this label + """ + + template_string = Template(self.filename_pattern) + + ctx = self.context(request) + + context = Context(ctx) + + return template_string.render(context) + def context(self, request): """ Provides context data to the template. @@ -201,6 +222,7 @@ class LabelTemplate(models.Model): self.template_name, base_url=request.build_absolute_uri("/"), presentational_hints=True, + filename=self.generate_filename(request), **kwargs ) diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index dfb7c09679..ecb4d91492 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -278,6 +278,7 @@ class ReportTemplateBase(ReportBase): self.template_name, base_url=request.build_absolute_uri("/"), presentational_hints=True, + filename=self.generate_filename(request), **kwargs) return wp.render_to_response(