diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html index 93440e13ed..78bd621254 100644 --- a/InvenTree/part/templates/part/attachments.html +++ b/InvenTree/part/templates/part/attachments.html @@ -21,7 +21,7 @@ enableDragAndDrop( '#attachment-dropzone', - "{% url 'part-attachment-create' %}", + '{% url "api-part-attachment-list" %}', { data: { part: {{ part.id }}, @@ -34,10 +34,23 @@ ); $("#new-attachment").click(function() { - launchModalForm("{% url 'part-attachment-create' %}?part={{ part.id }}", + + constructForm( + '{% url "api-part-attachment-list" %}', { - reload: true, - }); + method: 'POST', + fields: { + attachment: {}, + comment: {}, + part: { + value: {{ part.pk }}, + hidden: true, + } + }, + reload: true, + title: '{% trans "Add Attachment" %}', + } + ) }); $("#attachment-table").on('click', '.attachment-edit-button', function() { diff --git a/InvenTree/part/test_views.py b/InvenTree/part/test_views.py index 231eed7896..3b6b245231 100644 --- a/InvenTree/part/test_views.py +++ b/InvenTree/part/test_views.py @@ -232,29 +232,6 @@ class PartRelatedTests(PartViewTestCase): self.assertEqual(n, 1) -class PartAttachmentTests(PartViewTestCase): - - def test_valid_create(self): - """ test creation of an attachment for a valid part """ - - response = self.client.get(reverse('part-attachment-create'), {'part': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # TODO - Create a new attachment using this view - - def test_invalid_create(self): - """ test creation of an attachment for an invalid part """ - - # TODO - pass - - def test_edit(self): - """ test editing an attachment """ - - # TODO - pass - - class PartQRTest(PartViewTestCase): """ Tests for the Part QR Code AJAX view """ diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 80351b8dba..cd18fc0f7e 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -18,7 +18,6 @@ part_related_urls = [ ] part_attachment_urls = [ - url(r'^new/?', views.PartAttachmentCreate.as_view(), name='part-attachment-create'), 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 9998a12783..c9d767d835 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -154,60 +154,6 @@ class PartRelatedDelete(AjaxDeleteView): role_required = 'part.change' -class PartAttachmentCreate(AjaxCreateView): - """ View for creating a new PartAttachment object - - - The view only makes sense if a Part object is passed to it - """ - model = PartAttachment - form_class = part_forms.EditPartAttachmentForm - ajax_form_title = _("Add part attachment") - ajax_template_name = "modal_form.html" - - def save(self, form, **kwargs): - """ - Record the user that uploaded this attachment - """ - - attachment = form.save(commit=False) - attachment.user = self.request.user - attachment.save() - - def get_data(self): - return { - 'success': _('Added attachment') - } - - def get_initial(self): - """ Get initial data for new PartAttachment object. - - - Client should have requested this form with a parent part in mind - - e.g. ?part= - """ - - initials = super(AjaxCreateView, self).get_initial() - - # TODO - If the proper part was not sent, return an error message - try: - initials['part'] = Part.objects.get(id=self.request.GET.get('part', None)) - except (ValueError, Part.DoesNotExist): - pass - - return initials - - def get_form(self): - """ Create a form to upload a new PartAttachment - - - Hide the 'part' field - """ - - form = super(AjaxCreateView, self).get_form() - - form.fields['part'].widget = HiddenInput() - - return form - - class PartAttachmentEdit(AjaxUpdateView): """ View for editing a PartAttachment object """