diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py
index 9cdfecbd8a..e1258385a5 100644
--- a/InvenTree/InvenTree/views.py
+++ b/InvenTree/InvenTree/views.py
@@ -115,9 +115,12 @@ class AjaxMixin(object):
# (this can be overridden by a child class)
ajax_template_name = 'modal_form.html'
- ajax_form_action = ''
ajax_form_title = ''
+ def get_form_title(self):
+ """ Default implementation - return the ajax_form_title variable """
+ return self.ajax_form_title
+
def get_param(self, name, method='GET'):
""" Get a request query parameter value from URL e.g. ?part=3
@@ -169,7 +172,7 @@ class AjaxMixin(object):
else:
context['form'] = None
- data['title'] = self.ajax_form_title
+ data['title'] = self.get_form_title()
data['html_form'] = render_to_string(
self.ajax_template_name,
diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html
index e264c376c9..f337019409 100644
--- a/InvenTree/company/templates/company/index.html
+++ b/InvenTree/company/templates/company/index.html
@@ -14,7 +14,7 @@ InvenTree | {% trans "Supplier List" %}
@@ -26,11 +26,9 @@ InvenTree | {% trans "Supplier List" %}
{% block js_ready %}
{{ block.super }}
$('#new-company').click(function () {
- launchModalForm(
- "{% url 'company-create' %}",
- {
- follow: true
- });
+ launchModalForm("{{ create_url }}", {
+ follow: true
+ });
});
loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
diff --git a/InvenTree/company/urls.py b/InvenTree/company/urls.py
index 848463610c..045ad94140 100644
--- a/InvenTree/company/urls.py
+++ b/InvenTree/company/urls.py
@@ -29,6 +29,9 @@ company_detail_urls = [
company_urls = [
+ url(r'new/supplier/', views.CompanyCreate.as_view(), name='supplier-create'),
+ url(r'new/manufacturer/', views.CompanyCreate.as_view(), name='manufacturer-create'),
+ url(r'new/customer/', views.CompanyCreate.as_view(), name='customer-create'),
url(r'new/?', views.CompanyCreate.as_view(), name='company-create'),
url(r'^(?P\d+)/', include(company_detail_urls)),
diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py
index 36e1e7bd91..e4242e5f4c 100644
--- a/InvenTree/company/views.py
+++ b/InvenTree/company/views.py
@@ -43,29 +43,50 @@ class CompanyIndex(ListView):
ctx = super().get_context_data(**kwargs)
- url = self.request.path
+ # Provide custom context data to the template,
+ # based on the URL we use to access this page
- print(url)
- print(reverse('supplier-index'))
- print(reverse('manufacturer-index'))
- print(reverse('customer-index'))
+ lookup = {
+ reverse('supplier-index'): {
+ 'title': _('Suppliers'),
+ 'button_text': _('New Supplier'),
+ 'filters': {'is_supplier': 'true'},
+ 'create_url': reverse('supplier-create'),
+ },
+ reverse('manufacturer-index'): {
+ 'title': _('Manufacturers'),
+ 'button_text': _('New Manufacturer'),
+ 'filters': {'is_manufacturer': 'true'},
+ 'create_url': reverse('manufacturer-create'),
+ },
+ reverse('customer-index'): {
+ 'title': _('Customers'),
+ 'button_text': _('New Customer'),
+ 'filters': {'is_customer': 'true'},
+ 'create_url': reverse('customer-create'),
+ }
+ }
- if url == reverse('supplier-index'):
- ctx["title"] = _("Suppliers")
- ctx['new_button_text'] = _("New Supplier")
- ctx["filters"] = {"is_supplier": "true"}
- elif url == reverse('manufacturer-index'):
- ctx["title"] = _("Manufacturers")
- ctx['new_button_text'] = _("New Manufacturer")
- ctx["filters"] = {"is_manufacturer": "true"}
- elif url == reverse('customer-index'):
- ctx["title"] = _("Customers")
- ctx['new_button_text'] = _("New Customer")
- ctx["filters"] = {"is_customer": "true"}
- else:
- ctx["title"] = _("Companies")
- ctx["new_button_text"] = _("New Company")
- ctx["filters"] = {}
+ default = {
+ 'title': _('Companies'),
+ 'button_text': _('New Company'),
+ 'filters': {},
+ 'create_url': reverse('company-create'),
+ }
+
+ context = None
+
+ for item in lookup:
+ print(self.request.path, item)
+ if self.request.path == item:
+ context = lookup[item]
+ break
+
+ if context is None:
+ context = default
+
+ for key,value in context.items():
+ ctx[key] = value
return ctx
@@ -156,7 +177,44 @@ class CompanyCreate(AjaxCreateView):
context_object_name = 'company'
form_class = EditCompanyForm
ajax_template_name = 'modal_form.html'
- ajax_form_title = _("Create new Company")
+
+ def get_form_title(self):
+
+ url = self.request.path
+
+ if url == reverse('supplier-create'):
+ return _("Create new Supplier")
+
+ if url == reverse('manufacturer-create'):
+ return _('Create new Manufacturer')
+
+ if url == reverse('customer-create'):
+ return _('Create new Customer')
+
+ return _('Create new Company')
+
+ def get_initial(self):
+ """ Initial values for the form data """
+ initials = super().get_initial().copy()
+
+ url = self.request.path
+
+ if url == reverse('supplier-create'):
+ initials['is_supplier'] = True
+ initials['is_customer'] = False
+ initials['is_manufacturer'] = False
+
+ elif url == reverse('manufacturer-create'):
+ initials['is_manufacturer'] = True
+ initials['is_supplier'] = True
+ initials['is_customer'] = False
+
+ elif url == reverse('customer-create'):
+ initials['is_customer'] = True
+ initials['is_manufacturer'] = False
+ initials['is_supplier'] = False
+
+ return initials
def get_data(self):
return {