2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Replace StockItemAttachmentCreate form

- Also replace drag-and-drop
- Add 'hidden' option for form fields
- Adds renderer for StockItem model
This commit is contained in:
Oliver
2021-06-30 09:17:28 +10:00
parent 7d53bcb27c
commit 87235b7e6f
6 changed files with 66 additions and 58 deletions

View File

@ -255,52 +255,6 @@ class StockLocationQRCode(QRCodeView):
return None
class StockItemAttachmentCreate(AjaxCreateView):
"""
View for adding a new attachment for a StockItem
"""
model = StockItemAttachment
form_class = StockForms.EditStockItemAttachmentForm
ajax_form_title = _("Add Stock Item Attachment")
ajax_template_name = "modal_form.html"
def save(self, form, **kwargs):
""" Record 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 the new StockItem attachment object.
- Client must provide a valid StockItem ID
"""
initials = super().get_initial()
try:
initials['stock_item'] = StockItem.objects.get(id=self.request.GET.get('item', None))
except (ValueError, StockItem.DoesNotExist):
pass
return initials
def get_form(self):
form = super().get_form()
form.fields['stock_item'].widget = HiddenInput()
return form
class StockItemAttachmentEdit(AjaxUpdateView):
"""
View for editing a StockItemAttachment object.