From 59e37b2526940b6ddb2bdee0f1e8a8e07a2d0235 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 19 Jan 2021 08:15:50 +1100 Subject: [PATCH 1/3] Improve filter validation for test report --- .../migrations/0005_auto_20210119_0815.py | 35 +++++++++++++++++++ InvenTree/report/models.py | 32 ++++++++++++----- 2 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 InvenTree/report/migrations/0005_auto_20210119_0815.py diff --git a/InvenTree/report/migrations/0005_auto_20210119_0815.py b/InvenTree/report/migrations/0005_auto_20210119_0815.py new file mode 100644 index 0000000000..717176e390 --- /dev/null +++ b/InvenTree/report/migrations/0005_auto_20210119_0815.py @@ -0,0 +1,35 @@ +# Generated by Django 3.0.7 on 2021-01-18 21:15 + +import django.core.validators +from django.db import migrations, models +import report.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('report', '0004_auto_20200823_1104'), + ] + + operations = [ + migrations.AlterField( + model_name='testreport', + name='description', + field=models.CharField(help_text='Report template description', max_length=250, verbose_name='Description'), + ), + migrations.AlterField( + model_name='testreport', + name='filters', + field=models.CharField(blank=True, help_text='Part query filters (comma-separated list of key=value pairs)', max_length=250, validators=[report.models.validate_stock_item_report_filters], verbose_name='Filters'), + ), + migrations.AlterField( + model_name='testreport', + name='name', + field=models.CharField(help_text='Template name', max_length=100, unique=True, verbose_name='Name'), + ), + migrations.AlterField( + model_name='testreport', + name='template', + field=models.FileField(help_text='Report template file', upload_to=report.models.rename_template, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html', 'htm', 'tex'])], verbose_name='Template'), + ), + ] diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 4dd5fbfa5c..224f2800d8 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -57,6 +57,11 @@ def rename_template(instance, filename): return os.path.join('report', 'report_template', instance.getSubdir(), filename) +def validate_stock_item_report_filters(filters): + + return validateFilterString(filters, model=stock.models.StockItem) + + class WeasyprintReportMixin(WeasyTemplateResponseMixin): """ Class for rendering a HTML template to a PDF. @@ -144,29 +149,28 @@ class ReportTemplateBase(models.Model): name = models.CharField( blank=False, max_length=100, + verbose_name=_('Name'), help_text=_('Template name'), unique=True, ) template = models.FileField( upload_to=rename_template, + verbose_name=_('Template'), help_text=_("Report template file"), validators=[FileExtensionValidator(allowed_extensions=['html', 'htm', 'tex'])], ) - description = models.CharField(max_length=250, help_text=_("Report template description")) + description = models.CharField( + max_length=250, + verbose_name=_('Description'), + help_text=_("Report template description") + ) enabled = models.BooleanField( default=True, + verbose_name=_('Enabled'), help_text=_('Report template is enabled'), - verbose_name=_('Enabled') - ) - - filters = models.CharField( - blank=True, - max_length=250, - help_text=_("Part query filters (comma-separated list of key=value pairs)"), - validators=[validateFilterString] ) class Meta: @@ -184,6 +188,16 @@ class TestReport(ReportTemplateBase): # Requires a stock_item object to be given to it before rendering stock_item = None + filters = models.CharField( + blank=True, + max_length=250, + verbose_name=_('Filters'), + help_text=_("Part query filters (comma-separated list of key=value pairs)"), + validators=[ + validate_stock_item_report_filters + ] + ) + def matches_stock_item(self, item): """ Test if this report template matches a given StockItem objects From 5c2012f873a15b31f1f88481da7dac380116db87 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 19 Jan 2021 11:05:50 +1100 Subject: [PATCH 2/3] Update version.py --- InvenTree/InvenTree/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index ed9b000f9b..773fb985ad 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -7,7 +7,7 @@ import django import common.models -INVENTREE_SW_VERSION = "0.1.5 pre" +INVENTREE_SW_VERSION = "0.1.5" def inventreeInstanceName(): From d17cb47e3cfa5f3e748872db66feb2fb6dcb23fd Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 19 Jan 2021 11:06:08 +1100 Subject: [PATCH 3/3] Update version.py --- InvenTree/InvenTree/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index 773fb985ad..970b2ba92e 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -7,7 +7,7 @@ import django import common.models -INVENTREE_SW_VERSION = "0.1.5" +INVENTREE_SW_VERSION = "0.1.6 pre" def inventreeInstanceName():