mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Replace PartAttachmentCreate form
This commit is contained in:
parent
8c439e52fd
commit
238dccc071
@ -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() {
|
||||
|
@ -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 """
|
||||
|
||||
|
@ -18,7 +18,6 @@ part_related_urls = [
|
||||
]
|
||||
|
||||
part_attachment_urls = [
|
||||
url(r'^new/?', views.PartAttachmentCreate.as_view(), name='part-attachment-create'),
|
||||
url(r'^(?P<pk>\d+)/edit/?', views.PartAttachmentEdit.as_view(), name='part-attachment-edit'),
|
||||
url(r'^(?P<pk>\d+)/delete/?', views.PartAttachmentDelete.as_view(), name='part-attachment-delete'),
|
||||
]
|
||||
|
@ -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=<pk>
|
||||
"""
|
||||
|
||||
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 """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user