Move PartParameterTemplate model to the API (#3123)

* Adds detail API view for the PartParameterTemplate model

* Use API methods rather than server-side forms

* Remove old views / forms

* Update API version
This commit is contained in:
Oliver 2022-06-03 17:11:19 +10:00 committed by GitHub
parent ebca787f71
commit 2e40f3ccf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 63 deletions

View File

@ -2,11 +2,14 @@
# InvenTree API version
INVENTREE_API_VERSION = 55
INVENTREE_API_VERSION = 56
"""
Increment this API version number whenever there is a significant change to the API that any clients need to know about
v56 -> 2022-06-02 : https://github.com/inventree/InvenTree/pull/3123
- Expose the PartParameterTemplate model to use the API
v55 -> 2022-06-02 : https://github.com/inventree/InvenTree/pull/3120
- Converts the 'StockItemReturn' functionality to make use of the API

View File

@ -1441,6 +1441,13 @@ class PartParameterTemplateList(generics.ListCreateAPIView):
return queryset
class PartParameterTemplateDetail(generics.RetrieveUpdateDestroyAPIView):
"""API endpoint for accessing the detail view for a PartParameterTemplate object"""
queryset = PartParameterTemplate.objects.all()
serializer_class = part_serializers.PartParameterTemplateSerializer
class PartParameterList(generics.ListCreateAPIView):
"""API endpoint for accessing a list of PartParameter objects.
@ -1894,7 +1901,10 @@ part_api_urls = [
# Base URL for PartParameter API endpoints
re_path(r'^parameter/', include([
path('template/', PartParameterTemplateList.as_view(), name='api-part-parameter-template-list'),
path('template/', include([
re_path(r'^(?P<pk>\d+)/', PartParameterTemplateDetail.as_view(), name='api-part-parameter-template-detail'),
re_path(r'^.*$', PartParameterTemplateList.as_view(), name='api-part-parameter-template-list'),
])),
re_path(r'^(?P<pk>\d+)/', PartParameterDetail.as_view(), name='api-part-parameter-detail'),
re_path(r'^.*$', PartParameterList.as_view(), name='api-part-parameter-list'),

View File

@ -11,8 +11,7 @@ from InvenTree.forms import HelperForm
from InvenTree.helpers import clean_decimal
from .models import (Part, PartCategory, PartCategoryParameterTemplate,
PartInternalPriceBreak, PartParameterTemplate,
PartSellPriceBreak)
PartInternalPriceBreak, PartSellPriceBreak)
class PartImageDownloadForm(HelperForm):
@ -60,18 +59,6 @@ class SetPartCategoryForm(forms.Form):
part_category = TreeNodeChoiceField(queryset=PartCategory.objects.all(), required=True, help_text=_('Select part category'))
class EditPartParameterTemplateForm(HelperForm):
"""Form for editing a PartParameterTemplate object."""
class Meta:
"""Metaclass defines fields for this form"""
model = PartParameterTemplate
fields = [
'name',
'units'
]
class EditCategoryParameterTemplateForm(HelperForm):
"""Form for editing a PartCategoryParameterTemplate object."""

View File

@ -10,12 +10,6 @@ from django.urls import include, re_path
from . import views
part_parameter_urls = [
re_path(r'^template/new/', views.PartParameterTemplateCreate.as_view(), name='part-param-template-create'),
re_path(r'^template/(?P<pk>\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='part-param-template-edit'),
re_path(r'^template/(?P<pk>\d+)/delete/', views.PartParameterTemplateDelete.as_view(), name='part-param-template-edit'),
]
part_detail_urls = [
re_path(r'^delete/?', views.PartDelete.as_view(), name='part-delete'),
re_path(r'^bom-download/?', views.BomDownload.as_view(), name='bom-download'),
@ -71,9 +65,6 @@ part_urls = [
# Part category
re_path(r'^category/', include(category_urls)),
# Part parameters
re_path(r'^parameter/', include(part_parameter_urls)),
# Change category for multiple parts
re_path(r'^set-category/?', views.PartSetCategory.as_view(), name='part-set-category'),

View File

@ -36,8 +36,7 @@ from stock.models import StockItem, StockLocation
from . import forms as part_forms
from . import settings as part_settings
from .bom import ExportBom, IsValidBOMFormat, MakeBomTemplate
from .models import (Part, PartCategory, PartCategoryParameterTemplate,
PartParameterTemplate)
from .models import Part, PartCategory, PartCategoryParameterTemplate
class PartIndex(InvenTreeRoleMixin, ListView):
@ -930,29 +929,6 @@ class PartPricing(AjaxView):
return self.renderJsonResponse(request, form, data=data, context=self.get_pricing(quantity, currency))
class PartParameterTemplateCreate(AjaxCreateView):
"""View for creating a new PartParameterTemplate."""
model = PartParameterTemplate
form_class = part_forms.EditPartParameterTemplateForm
ajax_form_title = _('Create Part Parameter Template')
class PartParameterTemplateEdit(AjaxUpdateView):
"""View for editing a PartParameterTemplate."""
model = PartParameterTemplate
form_class = part_forms.EditPartParameterTemplateForm
ajax_form_title = _('Edit Part Parameter Template')
class PartParameterTemplateDelete(AjaxDeleteView):
"""View for deleting an existing PartParameterTemplate."""
model = PartParameterTemplate
ajax_form_title = _("Delete Part Parameter Template")
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
"""Detail view for PartCategory."""

View File

@ -346,8 +346,14 @@ $("#param-table").inventreeTable({
});
$("#new-param").click(function() {
launchModalForm("{% url 'part-param-template-create' %}", {
success: function() {
constructForm('{% url "api-part-parameter-template-list" %}', {
fields: {
name: {},
units: {},
},
method: 'POST',
title: '{% trans "Create Part Parameter Template" %}',
onSuccess: function() {
$("#param-table").bootstrapTable('refresh');
},
});
@ -355,26 +361,43 @@ $("#new-param").click(function() {
$("#param-table").on('click', '.template-edit', function() {
var button = $(this);
var pk = button.attr('pk');
var url = "/part/parameter/template/" + button.attr('pk') + "/edit/";
launchModalForm(url, {
success: function() {
$("#param-table").bootstrapTable('refresh');
constructForm(
`/api/part/parameter/template/${pk}/`,
{
fields: {
name: {},
units: {},
},
title: '{% trans "Edit Part Parameter Template" %}',
onSuccess: function() {
$("#param-table").bootstrapTable('refresh');
},
}
});
);
});
$("#param-table").on('click', '.template-delete', function() {
var button = $(this);
var pk = button.attr('pk');
var url = "/part/parameter/template/" + button.attr('pk') + "/delete/";
var html = `
<div class='alert alert-block alert-danger'>
{% trans "Any parameters which reference this template will also be deleted" %}
</div>`;
launchModalForm(url, {
success: function() {
$("#param-table").bootstrapTable('refresh');
constructForm(
`/api/part/parameter/template/${pk}/`,
{
method: 'DELETE',
preFormContent: html,
title: '{% trans "Delete Part Parameter Template" %}',
onSuccess: function() {
$("#param-table").bootstrapTable('refresh');
},
}
});
);
});
$("#import-part").click(function() {