mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor BuildAttachment views
This commit is contained in:
@ -1060,76 +1060,6 @@ class BuildItemEdit(AjaxUpdateView):
|
||||
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):
|
||||
"""
|
||||
View for deleting a BuildAttachment
|
||||
|
Reference in New Issue
Block a user