mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 21:20:56 +00:00
Modal forms for stock app
This commit is contained in:
@ -4,6 +4,8 @@ from django.http import HttpResponseRedirect
|
||||
from django.views.generic import DetailView, ListView
|
||||
from django.views.generic.edit import UpdateView, DeleteView, CreateView
|
||||
|
||||
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||
|
||||
from part.models import Part
|
||||
from .models import StockItem, StockLocation
|
||||
|
||||
@ -14,18 +16,16 @@ from .forms import EditStockItemForm
|
||||
class StockIndex(ListView):
|
||||
model = StockItem
|
||||
template_name = 'stock/index.html'
|
||||
context_obect_name = 'items'
|
||||
paginate_by = 50
|
||||
|
||||
def get_queryset(self):
|
||||
return StockItem.objects.filter(location=None)
|
||||
context_obect_name = 'locations'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(StockIndex, self).get_context_data(**kwargs).copy()
|
||||
|
||||
# Return all top-level locations
|
||||
locations = StockLocation.objects.filter(parent=None)
|
||||
|
||||
context['locations'] = locations
|
||||
context['items'] = StockItem.objects.all()
|
||||
|
||||
return context
|
||||
|
||||
@ -44,25 +44,31 @@ class StockItemDetail(DetailView):
|
||||
model = StockItem
|
||||
|
||||
|
||||
class StockLocationEdit(UpdateView):
|
||||
class StockLocationEdit(AjaxUpdateView):
|
||||
model = StockLocation
|
||||
form_class = EditStockLocationForm
|
||||
template_name = 'stock/location_edit.html'
|
||||
context_object_name = 'location'
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = 'Edit Stock Location'
|
||||
|
||||
|
||||
class StockItemEdit(UpdateView):
|
||||
class StockItemEdit(AjaxUpdateView):
|
||||
model = StockItem
|
||||
form_class = EditStockItemForm
|
||||
template_name = 'stock/item_edit.html'
|
||||
context_object_name = 'item'
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = 'Edit Stock Item'
|
||||
|
||||
|
||||
class StockLocationCreate(CreateView):
|
||||
class StockLocationCreate(AjaxCreateView):
|
||||
model = StockLocation
|
||||
form_class = EditStockLocationForm
|
||||
template_name = 'stock/location_create.html'
|
||||
context_object_name = 'location'
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = 'Create new Stock Location'
|
||||
|
||||
def get_initial(self):
|
||||
initials = super(StockLocationCreate, self).get_initial().copy()
|
||||
@ -75,11 +81,13 @@ class StockLocationCreate(CreateView):
|
||||
return initials
|
||||
|
||||
|
||||
class StockItemCreate(CreateView):
|
||||
class StockItemCreate(AjaxCreateView):
|
||||
model = StockItem
|
||||
form_class = EditStockItemForm
|
||||
template_name = 'stock/item_create.html'
|
||||
context_object_name = 'item'
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = 'Create new Stock Item'
|
||||
|
||||
def get_initial(self):
|
||||
initials = super(StockItemCreate, self).get_initial().copy()
|
||||
@ -100,27 +108,17 @@ class StockItemCreate(CreateView):
|
||||
return initials
|
||||
|
||||
|
||||
class StockLocationDelete(DeleteView):
|
||||
class StockLocationDelete(AjaxDeleteView):
|
||||
model = StockLocation
|
||||
success_url = '/stock'
|
||||
template_name = 'stock/location_delete.html'
|
||||
context_object_name = 'location'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'confirm' in request.POST:
|
||||
return super(StockLocationDelete, self).post(request, *args, **kwargs)
|
||||
else:
|
||||
return HttpResponseRedirect(self.get_object().get_absolute_url())
|
||||
ajax_form_title = 'Delete Stock Location'
|
||||
|
||||
|
||||
class StockItemDelete(DeleteView):
|
||||
class StockItemDelete(AjaxDeleteView):
|
||||
model = StockItem
|
||||
success_url = '/stock/'
|
||||
template_name = 'stock/item_delete.html'
|
||||
context_object_name = 'item'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'confirm' in request.POST:
|
||||
return super(StockItemDelete, self).post(request, *args, **kwargs)
|
||||
else:
|
||||
return HttpResponseRedirect(self.get_object().get_absolute_url())
|
||||
ajax_form_title = 'Delete Stock Item'
|
||||
|
Reference in New Issue
Block a user