mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +00:00
Refactor BuildAttachment views
This commit is contained in:
parent
a7d60cf5ad
commit
9ea3e511b9
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
enableDragAndDrop(
|
enableDragAndDrop(
|
||||||
'#attachment-dropzone',
|
'#attachment-dropzone',
|
||||||
'{% url "build-attachment-create" %}',
|
'{% url "api-build-attachment-list" %}',
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
build: {{ build.id }},
|
build: {{ build.id }},
|
||||||
@ -36,29 +36,34 @@ enableDragAndDrop(
|
|||||||
|
|
||||||
// Callback for creating a new attachment
|
// Callback for creating a new attachment
|
||||||
$('#new-attachment').click(function() {
|
$('#new-attachment').click(function() {
|
||||||
launchModalForm(
|
|
||||||
'{% url "build-attachment-create" %}',
|
constructForm('{% url "api-build-attachment-list" %}', {
|
||||||
{
|
fields: {
|
||||||
|
attachment: {},
|
||||||
|
comment: {},
|
||||||
|
build: {
|
||||||
|
value: {{ build.pk }},
|
||||||
|
hidden: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
method: 'POST',
|
||||||
reload: true,
|
reload: true,
|
||||||
data: {
|
title: '{% trans "Add Attachment" %}',
|
||||||
build: {{ build.pk }},
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Callback for editing an attachment
|
// Callback for editing an attachment
|
||||||
$("#attachment-table").on('click', '.attachment-edit-button', function() {
|
$("#attachment-table").on('click', '.attachment-edit-button', function() {
|
||||||
var pk = $(this).attr('pk');
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
var url = `/build/attachment/${pk}/edit/`;
|
constructForm(`/api/build/attachment/${pk}/`, {
|
||||||
|
fields: {
|
||||||
launchModalForm(
|
attachment: {},
|
||||||
url,
|
comment: {},
|
||||||
{
|
},
|
||||||
reload: true,
|
reload: true,
|
||||||
}
|
title: '{% trans "Edit Attachment" %}',
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Callback for deleting an attachment
|
// Callback for deleting an attachment
|
||||||
|
@ -37,8 +37,6 @@ build_urls = [
|
|||||||
])),
|
])),
|
||||||
|
|
||||||
url('^attachment/', include([
|
url('^attachment/', include([
|
||||||
url('^new/', views.BuildAttachmentCreate.as_view(), name='build-attachment-create'),
|
|
||||||
url(r'^(?P<pk>\d+)/edit/', views.BuildAttachmentEdit.as_view(), name='build-attachment-edit'),
|
|
||||||
url(r'^(?P<pk>\d+)/delete/', views.BuildAttachmentDelete.as_view(), name='build-attachment-delete'),
|
url(r'^(?P<pk>\d+)/delete/', views.BuildAttachmentDelete.as_view(), name='build-attachment-delete'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
@ -1060,76 +1060,6 @@ class BuildItemEdit(AjaxUpdateView):
|
|||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
class BuildAttachmentCreate(AjaxCreateView):
|
|
||||||
"""
|
|
||||||
View for creating a BuildAttachment
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = BuildOrderAttachment
|
|
||||||
form_class = forms.EditBuildAttachmentForm
|
|
||||||
ajax_form_title = _('Add Build Order Attachment')
|
|
||||||
|
|
||||||
def save(self, form, **kwargs):
|
|
||||||
"""
|
|
||||||
Add information on the user that uploaded the 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 creating an attachment
|
|
||||||
"""
|
|
||||||
|
|
||||||
initials = super().get_initial()
|
|
||||||
|
|
||||||
try:
|
|
||||||
initials['build'] = Build.objects.get(pk=self.request.GET.get('build', -1))
|
|
||||||
except (ValueError, Build.DoesNotExist):
|
|
||||||
pass
|
|
||||||
|
|
||||||
return initials
|
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
"""
|
|
||||||
Hide the 'build' field if specified
|
|
||||||
"""
|
|
||||||
|
|
||||||
form = super().get_form()
|
|
||||||
|
|
||||||
form.fields['build'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
|
|
||||||
class BuildAttachmentEdit(AjaxUpdateView):
|
|
||||||
"""
|
|
||||||
View for editing a BuildAttachment object
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = BuildOrderAttachment
|
|
||||||
form_class = forms.EditBuildAttachmentForm
|
|
||||||
ajax_form_title = _('Edit Attachment')
|
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
form = super().get_form()
|
|
||||||
form.fields['build'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
return {
|
|
||||||
'success': _('Attachment updated')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class BuildAttachmentDelete(AjaxDeleteView):
|
class BuildAttachmentDelete(AjaxDeleteView):
|
||||||
"""
|
"""
|
||||||
View for deleting a BuildAttachment
|
View for deleting a BuildAttachment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user