diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index b3209ca267..4b43b342af 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -1,14 +1,31 @@ -function attachClipboard(selector) { +function attachClipboard(selector, containerselector, textElement) { + // set container + if (containerselector){ + containerselector = document.getElementById(containerselector); + } else { + containerselector = document.body; + } - 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 inventreeDocReady() { /* Run this function when the HTML document is loaded. * This will be called for every page that extends "base.html" @@ -62,6 +79,8 @@ function inventreeDocReady() { // Initialize clipboard-buttons attachClipboard('.clip-btn'); + attachClipboard('.clip-btn', 'modal-about'); // modals + attachClipboard('.clip-btn-version', 'modal-about', 'about-copy-text'); // version-text } 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..1eefade272 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 }} + {% include "tel.html" with tel=company.phone %} {% endif %} {% if company.email %} {% trans "Email" %} - {{ company.email }} + {% include "mail.html" with mail=company.email %} {% 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/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/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/mail.html b/InvenTree/templates/mail.html new file mode 100644 index 0000000000..98990fb31b --- /dev/null +++ b/InvenTree/templates/mail.html @@ -0,0 +1 @@ +{{ mail }}{% include "clip.html"%} \ No newline at end of file diff --git a/InvenTree/templates/tel.html b/InvenTree/templates/tel.html new file mode 100644 index 0000000000..14f978ad87 --- /dev/null +++ b/InvenTree/templates/tel.html @@ -0,0 +1 @@ +{{ tel }}{% include "clip.html"%} \ No newline at end of file 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