diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 2212743c2b..d9fa77afd4 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -232,6 +232,15 @@ class PartAttachmentList(generics.ListCreateAPIView, AttachmentMixin): ] +class PartAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMixin): + """ + Detail endpoint for PartAttachment model + """ + + queryset = PartAttachment.objects.all() + serializer_class = part_serializers.PartAttachmentSerializer + + class PartTestTemplateList(generics.ListCreateAPIView): """ API endpoint for listing (and creating) a PartTestTemplate. @@ -1032,6 +1041,7 @@ part_api_urls = [ # Base URL for PartAttachment API endpoints url(r'^attachment/', include([ + url(r'^(?P\d+)/', PartAttachmentDetail.as_view(), name='api-part-attachment-detail'), url(r'^$', PartAttachmentList.as_view(), name='api-part-attachment-list'), ])), diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html index 78bd621254..cff6f25892 100644 --- a/InvenTree/part/templates/part/attachments.html +++ b/InvenTree/part/templates/part/attachments.html @@ -56,12 +56,18 @@ $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); - var url = `/part/attachment/${button.attr('pk')}/edit/`; + var pk = button.attr('pk'); - launchModalForm(url, - { - reload: true, - }); + var url = `/api/part/attachment/${pk}/`; + + constructForm(url, { + fields: { + attachment: {}, + comment: {}, + }, + title: '{% trans "Edit Attachment" %}', + reload: true, + }); }); $("#attachment-table").on('click', '.attachment-delete-button', function() { diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index cd18fc0f7e..eeb1a08be4 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -18,7 +18,6 @@ part_related_urls = [ ] part_attachment_urls = [ - url(r'^(?P\d+)/edit/?', views.PartAttachmentEdit.as_view(), name='part-attachment-edit'), url(r'^(?P\d+)/delete/?', views.PartAttachmentDelete.as_view(), name='part-attachment-delete'), ] diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index c9d767d835..b2d12a72ab 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -154,27 +154,6 @@ class PartRelatedDelete(AjaxDeleteView): role_required = 'part.change' -class PartAttachmentEdit(AjaxUpdateView): - """ View for editing a PartAttachment object """ - - model = PartAttachment - form_class = part_forms.EditPartAttachmentForm - ajax_template_name = 'modal_form.html' - ajax_form_title = _('Edit attachment') - - def get_data(self): - return { - 'success': _('Part attachment updated') - } - - def get_form(self): - form = super(AjaxUpdateView, self).get_form() - - form.fields['part'].widget = HiddenInput() - - return form - - class PartAttachmentDelete(AjaxDeleteView): """ View for deleting a PartAttachment """ diff --git a/InvenTree/stock/templates/stock/item_attachments.html b/InvenTree/stock/templates/stock/item_attachments.html index f5e9f8c4fc..13e886d8a5 100644 --- a/InvenTree/stock/templates/stock/item_attachments.html +++ b/InvenTree/stock/templates/stock/item_attachments.html @@ -25,7 +25,6 @@ enableDragAndDrop( { data: { stock_item: {{ item.id }}, - user: {{ user.pk }}, }, label: 'attachment', success: function(data, status, xhr) { @@ -47,10 +46,6 @@ $("#new-attachment").click(function() { value: {{ item.pk }}, hidden: true, }, - user: { - value: {{ user.pk }}, - hidden: true, - } }, reload: true, title: '{% trans "Add Attachment" %}',