2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-12 07:54:14 +00:00

Update PartCreate form

- Display list of close matches
- Invalidate form (for now)
This commit is contained in:
Oliver Walters
2019-05-11 11:55:17 +10:00
parent 4e4ee2742b
commit d9c0d2f5e3
4 changed files with 65 additions and 7 deletions

View File

@ -16,6 +16,7 @@ from company.models import Company
from .models import PartCategory, Part, PartAttachment
from .models import BomItem
from .models import SupplierPart
from .models import match_part_names
from . import forms as part_forms
@ -135,7 +136,7 @@ class PartCreate(AjaxCreateView):
form_class = part_forms.EditPartForm
ajax_form_title = 'Create new part'
ajax_template_name = 'modal_form.html'
ajax_template_name = 'part/create_part.html'
def get_data(self):
return {
@ -174,6 +175,28 @@ class PartCreate(AjaxCreateView):
return form
def post(self, request, *args, **kwargs):
form = self.get_form()
name = request.POST.get('name', None)
context = {}
if name:
matches = match_part_names(name)
if len(matches) > 0:
context['matches'] = matches
form.non_field_errors = 'Check matches'
data = {
'form_valid': False
}
return self.renderJsonResponse(request, form, data, context=context)
def get_initial(self):
""" Get initial data for the new Part object: