From 56f05e260455df01050a9175ea1fe9eae855081f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Nov 2020 10:42:01 +1100 Subject: [PATCH 1/3] Fixes for 'non field' errors in forms - Fixes issue where non-model fields would not show error text --- InvenTree/InvenTree/forms.py | 6 +----- InvenTree/templates/modal_form.html | 16 +++------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py index 4be8a28acb..56a1a116da 100644 --- a/InvenTree/InvenTree/forms.py +++ b/InvenTree/InvenTree/forms.py @@ -28,6 +28,7 @@ class HelperForm(forms.ModelForm): self.helper = FormHelper() self.helper.form_tag = False + self.helper.form_show_errors = True """ Create a default 'layout' for this form. @@ -43,11 +44,6 @@ class HelperForm(forms.ModelForm): valid = super(HelperForm, self).is_valid() - # Check for errors from model validation - # If none, disable crispy form errors - if not self.errors: - self.helper.form_show_errors = False - return valid def rebuild_layout(self): diff --git a/InvenTree/templates/modal_form.html b/InvenTree/templates/modal_form.html index 0a5ae59916..94bf032579 100644 --- a/InvenTree/templates/modal_form.html +++ b/InvenTree/templates/modal_form.html @@ -1,3 +1,5 @@ +{% load i18n %} +
{% if form.pre_form_info %} {% endif %} -{% block non_field_error %} -{% if form.non_field_errors %} - -{% endif %} -{% endblock %}
{% block pre_form_content %} @@ -41,4 +31,4 @@ {% endblock %} {% block post_form_content %} -{% endblock %} \ No newline at end of file +{% endblock %} From 5f8f0232a9d556b6c6622ce6efa9488efd7eed68 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Nov 2020 11:17:55 +1100 Subject: [PATCH 2/3] Add extra context to SupplierPartCreate form --- .../company/supplier_part_create.html | 17 ++++++++++++++ InvenTree/company/views.py | 23 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 InvenTree/company/templates/company/supplier_part_create.html diff --git a/InvenTree/company/templates/company/supplier_part_create.html b/InvenTree/company/templates/company/supplier_part_create.html new file mode 100644 index 0000000000..21c23f9075 --- /dev/null +++ b/InvenTree/company/templates/company/supplier_part_create.html @@ -0,0 +1,17 @@ +{% extends "modal_form.html" %} + +{% load i18n %} + +{% block pre_form_content %} +{{ block.super }} + +{% if part %} +
+ {% include "hover_image.html" with image=part.image %} + {{ part.full_name}} +
+ {{ part.description }} +
+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index 2720f4ccac..e863fa1d72 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -291,7 +291,7 @@ class SupplierPartCreate(AjaxCreateView): model = SupplierPart form_class = EditSupplierPartForm - ajax_template_name = 'modal_form.html' + ajax_template_name = 'company/supplier_part_create.html' ajax_form_title = _('Create new Supplier Part') context_object_name = 'part' role_required = 'purchase_order.add' @@ -304,6 +304,27 @@ class SupplierPartCreate(AjaxCreateView): # TODO - What validation steps can be performed on the single_pricing field? pass + def get_context_data(self): + """ + Supply context data to the form + """ + + ctx = super().get_context_data() + + # Add 'part' object + form = self.get_form() + + part = form['part'].value() + + try: + part = Part.objects.get(pk=part) + except (ValueError, Part.DoesNotExist): + part = None + + ctx['part'] = part + + return ctx + def save(self, form): """ If single_pricing is defined, add a price break for quantity=1 From 50a88e482605fd539322bc6d3f971a160a12cde6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Nov 2020 11:19:16 +1100 Subject: [PATCH 3/3] Revert "Add extra context to SupplierPartCreate form" This reverts commit 5f8f0232a9d556b6c6622ce6efa9488efd7eed68. --- .../company/supplier_part_create.html | 17 -------------- InvenTree/company/views.py | 23 +------------------ 2 files changed, 1 insertion(+), 39 deletions(-) delete mode 100644 InvenTree/company/templates/company/supplier_part_create.html diff --git a/InvenTree/company/templates/company/supplier_part_create.html b/InvenTree/company/templates/company/supplier_part_create.html deleted file mode 100644 index 21c23f9075..0000000000 --- a/InvenTree/company/templates/company/supplier_part_create.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends "modal_form.html" %} - -{% load i18n %} - -{% block pre_form_content %} -{{ block.super }} - -{% if part %} -
- {% include "hover_image.html" with image=part.image %} - {{ part.full_name}} -
- {{ part.description }} -
-{% endif %} - -{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index e863fa1d72..2720f4ccac 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -291,7 +291,7 @@ class SupplierPartCreate(AjaxCreateView): model = SupplierPart form_class = EditSupplierPartForm - ajax_template_name = 'company/supplier_part_create.html' + ajax_template_name = 'modal_form.html' ajax_form_title = _('Create new Supplier Part') context_object_name = 'part' role_required = 'purchase_order.add' @@ -304,27 +304,6 @@ class SupplierPartCreate(AjaxCreateView): # TODO - What validation steps can be performed on the single_pricing field? pass - def get_context_data(self): - """ - Supply context data to the form - """ - - ctx = super().get_context_data() - - # Add 'part' object - form = self.get_form() - - part = form['part'].value() - - try: - part = Part.objects.get(pk=part) - except (ValueError, Part.DoesNotExist): - part = None - - ctx['part'] = part - - return ctx - def save(self, form): """ If single_pricing is defined, add a price break for quantity=1