From 6234581fab18e247f01265db17264757caf73695 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 7 Aug 2021 11:16:37 +1000 Subject: [PATCH 01/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a23ab608e..7ace518175 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ However, powerful business logic works in the background to ensure that stock tr InvenTree is [available via Docker](https://hub.docker.com/r/inventree/inventree). Read the [docker guide](https://inventree.readthedocs.io/en/latest/start/docker/) for full details. -# Companion App +# Mobile App InvenTree is supported by a [companion mobile app](https://inventree.readthedocs.io/en/latest/app/app/) which allows users access to stock control information and functionality. From 2e5d5bcc840da18f14871cff71b895efbb4e8735 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 20:50:32 +1000 Subject: [PATCH 02/21] Fix part settings page --- .../templates/InvenTree/settings/part.html | 77 ------------------- .../InvenTree/settings/settings.html | 73 ++++++++++++++++++ 2 files changed, 73 insertions(+), 77 deletions(-) diff --git a/InvenTree/templates/InvenTree/settings/part.html b/InvenTree/templates/InvenTree/settings/part.html index 3fa20820b1..14a18a1aa5 100644 --- a/InvenTree/templates/InvenTree/settings/part.html +++ b/InvenTree/templates/InvenTree/settings/part.html @@ -68,80 +68,3 @@ {% endblock %} - -{% block js_ready %} -{{ block.super }} - - $("#param-table").inventreeTable({ - url: "{% url 'api-part-parameter-template-list' %}", - queryParams: { - ordering: 'name', - }, - formatNoMatches: function() { return '{% trans "No part parameter templates found" %}'; }, - columns: [ - { - field: 'pk', - title: 'ID', - visible: false, - switchable: false, - }, - { - field: 'name', - title: 'Name', - sortable: 'true', - }, - { - field: 'units', - title: 'Units', - sortable: 'true', - }, - { - formatter: function(value, row, index, field) { - var bEdit = ""; - var bDel = ""; - - var html = "
" + bEdit + bDel + "
"; - - return html; - } - } - ] - }); - - $("#new-param").click(function() { - launchModalForm("{% url 'part-param-template-create' %}", { - success: function() { - $("#param-table").bootstrapTable('refresh'); - }, - }); - }); - - $("#param-table").on('click', '.template-edit', function() { - var button = $(this); - - var url = "/part/parameter/template/" + button.attr('pk') + "/edit/"; - - launchModalForm(url, { - success: function() { - $("#param-table").bootstrapTable('refresh'); - } - }); - }); - - $("#param-table").on('click', '.template-delete', function() { - var button = $(this); - - var url = "/part/parameter/template/" + button.attr('pk') + "/delete/"; - - launchModalForm(url, { - success: function() { - $("#param-table").bootstrapTable('refresh'); - } - }); - }); - - $("#import-part").click(function() { - launchModalForm("{% url 'api-part-import' %}?reset", {}); - }); - -{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/settings/settings.html b/InvenTree/templates/InvenTree/settings/settings.html index 9fd069af52..40125019ff 100644 --- a/InvenTree/templates/InvenTree/settings/settings.html +++ b/InvenTree/templates/InvenTree/settings/settings.html @@ -241,6 +241,79 @@ $("#cat-param-table").on('click', '.template-delete', function() { }); }); +$("#param-table").inventreeTable({ + url: "{% url 'api-part-parameter-template-list' %}", + queryParams: { + ordering: 'name', + }, + formatNoMatches: function() { return '{% trans "No part parameter templates found" %}'; }, + columns: [ + { + field: 'pk', + title: 'ID', + visible: false, + switchable: false, + }, + { + field: 'name', + title: 'Name', + sortable: 'true', + }, + { + field: 'units', + title: 'Units', + sortable: 'true', + }, + { + formatter: function(value, row, index, field) { + var bEdit = ""; + var bDel = ""; + + var html = "
" + bEdit + bDel + "
"; + + return html; + } + } + ] +}); + +$("#new-param").click(function() { + launchModalForm("{% url 'part-param-template-create' %}", { + success: function() { + $("#param-table").bootstrapTable('refresh'); + }, + }); +}); + +$("#param-table").on('click', '.template-edit', function() { + var button = $(this); + + var url = "/part/parameter/template/" + button.attr('pk') + "/edit/"; + + launchModalForm(url, { + success: function() { + $("#param-table").bootstrapTable('refresh'); + } + }); +}); + +$("#param-table").on('click', '.template-delete', function() { + var button = $(this); + + var url = "/part/parameter/template/" + button.attr('pk') + "/delete/"; + + launchModalForm(url, { + success: function() { + $("#param-table").bootstrapTable('refresh'); + } + }); +}); + +$("#import-part").click(function() { + launchModalForm("{% url 'api-part-import' %}?reset", {}); +}); + + enableNavbar({ label: 'settings', toggleId: '#item-menu-toggle', From e72e34413d3b09e06474bcfe6d914dd4539e26b2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:21:09 +1000 Subject: [PATCH 03/21] Check release tag before publishing docker image --- .github/workflows/docker_publish.yaml | 3 +++ ci/check_version_number.py | 38 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 ci/check_version_number.py diff --git a/.github/workflows/docker_publish.yaml b/.github/workflows/docker_publish.yaml index 53ec505003..9f3f3d6912 100644 --- a/.github/workflows/docker_publish.yaml +++ b/.github/workflows/docker_publish.yaml @@ -13,6 +13,9 @@ jobs: steps: - name: Check out repo uses: actions/checkout@v2 + - name: Check Release tag + run: | + python3 ci/check_version_number.py ${{ github.event.release.tag_name }} - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx diff --git a/ci/check_version_number.py b/ci/check_version_number.py new file mode 100644 index 0000000000..55a42e2484 --- /dev/null +++ b/ci/check_version_number.py @@ -0,0 +1,38 @@ +""" +On release, ensure that the release tag matches the InvenTree version number! +""" + +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import sys +import re +import os +import argparse + +if __name__ == '__main__': + + here = os.path.abspath(os.path.dirname(__file__)) + + version_file = os.path.join(here, '..', 'InvenTree', 'InvenTree', 'version.py') + + with open(version_file, 'r') as f: + + results = re.findall(r'INVENTREE_SW_VERSION = "(.*)"', f.read()) + + if not len(results) == 1: + print(f"Could not find INVENTREE_SW_VERSION in {version_file}") + sys.exit(1) + + version = results[0] + + parser = argparse.ArgumentParser() + parser.add_argument('tag', help='Version tag', action='store') + + args = parser.parse_args() + + if not args.tag == version: + print(f"Release tag '{args.tag}' does not match INVENTREE_SW_VERSION '{version}'") + sys.exit(1) + +sys.exit(0) \ No newline at end of file From 6d42cfab7588298b4df5babdf3ff616198fc696f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:08:08 +1000 Subject: [PATCH 04/21] Add model validator to prevent illegal names for PartParameterTemplate (cherry picked from commit 93805a87e011b45a446b1faeae6ab80257420879) --- InvenTree/part/models.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 28fd3ce793..50d3044771 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2143,6 +2143,16 @@ class PartTestTemplate(models.Model): ) +def validate_template_name(name): + """ + Prevent illegal characters in "name" field for PartParameterTemplate + """ + + for c in "!@#$%^&*()<>{}[].,?/\|~`_+-=\'\"": + if c in str(name): + raise ValidationError(_(f"Illegal character in template name ({c})")) + + class PartParameterTemplate(models.Model): """ A PartParameterTemplate provides a template for key:value pairs for extra @@ -2181,7 +2191,15 @@ class PartParameterTemplate(models.Model): except PartParameterTemplate.DoesNotExist: pass - name = models.CharField(max_length=100, verbose_name=_('Name'), help_text=_('Parameter Name'), unique=True) + name = models.CharField( + max_length=100, + verbose_name=_('Name'), + help_text=_('Parameter Name'), + unique=True, + validators=[ + validate_template_name, + ] + ) units = models.CharField(max_length=25, verbose_name=_('Units'), help_text=_('Parameter Units'), blank=True) From 24638a72297be323ac61955c7cc1af5817cee608 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:41:45 +1000 Subject: [PATCH 05/21] Add migration file --- .../0071_alter_partparametertemplate_name.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 InvenTree/part/migrations/0071_alter_partparametertemplate_name.py diff --git a/InvenTree/part/migrations/0071_alter_partparametertemplate_name.py b/InvenTree/part/migrations/0071_alter_partparametertemplate_name.py new file mode 100644 index 0000000000..fef49e73f6 --- /dev/null +++ b/InvenTree/part/migrations/0071_alter_partparametertemplate_name.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.4 on 2021-08-07 11:40 + +from django.db import migrations, models +import part.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0070_alter_part_variant_of'), + ] + + operations = [ + migrations.AlterField( + model_name='partparametertemplate', + name='name', + field=models.CharField(help_text='Parameter Name', max_length=100, unique=True, validators=[part.models.validate_template_name], verbose_name='Name'), + ), + ] From 174ac642359692ed8215269bd9cc2fae8020cb23 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:45:18 +1000 Subject: [PATCH 06/21] Allow downloaded files to be inline or attachments --- InvenTree/InvenTree/helpers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 628fd2e646..319b88cb09 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -344,13 +344,15 @@ def GetExportFormats(): ] -def DownloadFile(data, filename, content_type='application/text'): - """ Create a dynamic file for the user to download. +def DownloadFile(data, filename, content_type='application/text', inline=False): + """ + Create a dynamic file for the user to download. Args: data: Raw file data (string or bytes) filename: Filename for the file download content_type: Content type for the download + inline: Download "inline" or as attachment? (Default = attachment) Return: A StreamingHttpResponse object wrapping the supplied data @@ -365,7 +367,10 @@ def DownloadFile(data, filename, content_type='application/text'): response = StreamingHttpResponse(wrapper, content_type=content_type) response['Content-Length'] = len(data) - response['Content-Disposition'] = 'attachment; filename={f}'.format(f=filename) + + disposition = "inline" if inline else "attachment" + + response['Content-Disposition'] = f'{disposition}; filename={filename}' return response From d77b99c0ca2adcf7d4e73e681d818ded3fe78084 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:57:41 +1000 Subject: [PATCH 07/21] Add user settings for report and labels --- InvenTree/common/models.py | 14 +++++++++++ .../templates/InvenTree/settings/navbar.html | 12 ++++++++++ .../InvenTree/settings/settings.html | 2 ++ .../InvenTree/settings/user_labels.html | 23 +++++++++++++++++++ .../InvenTree/settings/user_reports.html | 23 +++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 InvenTree/templates/InvenTree/settings/user_labels.html create mode 100644 InvenTree/templates/InvenTree/settings/user_reports.html diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 839780d5b4..e2486c41df 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -926,6 +926,20 @@ class InvenTreeUserSetting(BaseInvenTreeSetting): 'validator': bool, }, + "LABEL_INLINE": { + 'name': _('Inline label display'), + 'description': _('Display PDF labels in the browser, instead of downloading as a file'), + 'default': True, + 'validator': bool, + }, + + "REPORT_INLINE": { + 'name': _('Inline report display'), + 'description': _('Display PDF reports in the browser, instead of downloading as a file'), + 'default': False, + 'validator': bool, + }, + 'SEARCH_PREVIEW_RESULTS': { 'name': _('Search Preview Results'), 'description': _('Number of results to show in search preview window'), diff --git a/InvenTree/templates/InvenTree/settings/navbar.html b/InvenTree/templates/InvenTree/settings/navbar.html index 83bbc10fe9..e7ea17f91f 100644 --- a/InvenTree/templates/InvenTree/settings/navbar.html +++ b/InvenTree/templates/InvenTree/settings/navbar.html @@ -30,6 +30,18 @@ +
  • + + {% trans "Labels" %} + +
  • + +
  • + + {% trans "Reports" %} + +
  • +