2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 21:20:56 +00:00

Improvements to stock page

- Fixed URL / view (use class views)
- Better slug lookup
- Better table rendering using ol' mate bootstrap
This commit is contained in:
Oliver
2018-04-15 20:10:49 +10:00
parent ab4b91cd46
commit 9d89db34b2
17 changed files with 264 additions and 94 deletions

View File

@ -1,43 +1,95 @@
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from .models import StockItem, StockLocation
def index(request):
template = loader.get_template('stock/index.html')
from .forms import EditStockLocationForm
from .forms import EditStockItemForm
items = StockItem.objects.all()
class StockIndex(ListView):
model = StockItem
template_name = 'stock/index.html'
context_obect_name = 'items'
paginate_by = 50
location = None
def get_queryset(self):
return StockItem.objects.filter(location=None)
if 'location' in request.GET:
loc_id = request.GET['location']
def get_context_data(self, **kwargs):
context = super(StockIndex, self).get_context_data(**kwargs).copy()
location = get_object_or_404(StockLocation, pk=loc_id)
locations = StockLocation.objects.filter(parent=None)
items = items.filter(location = loc_id)
context['locations'] = locations
children = StockLocation.objects.filter(parent = loc_id)
return context
else:
# No stock items can exist without a location
items = None
location = None
children = StockLocation.objects.filter(parent__isnull=True)
context = {
'items' : items,
'location' : location,
'children' : children,
}
return HttpResponse(template.render(context, request))
class StockLocationDetail(DetailView):
context_object_name = 'location'
template_name = 'stock/location.html'
queryset = StockLocation.objects.all()
model = StockLocation
def detail(request, pk):
class StockItemDetail(DetailView):
context_object_name = 'item'
template_name = 'stock/item.html'
queryset = StockItem.objects.all()
model = StockItem
stock = get_object_or_404(StockItem, pk=pk)
return render(request, 'stock/detail.html', {'item' : stock})
class StockLocationEdit(UpdateView):
model = StockLocation
form_class = EditStockLocationForm
template_name = '/stock/location-edit.html'
context_object_name = 'location'
class StockItemEdit(UpdateView):
model = StockItem
form_class = EditStockItemForm
template_name = '/stock/item-edit.html'
context_object_name = 'item'
class StockLocationCreate(CreateView):
model = StockLocation
form_class = EditStockLocationForm
template_name = '/stock/location-create.html'
context_object_name = 'location'
class StockItemCreate(CreateView):
model = StockItem
form_class = EditStockItemForm
template_name = '/stock/item-create.html'
context_object_name = 'item'
class StockLocationDelete(DeleteView):
model = StockLocation
success_url = '/stock/'
template_name = '/stock/location-delete.html'
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())
class StockItemDelete(DeleteView):
model = StockLocation
success_url = '/stock/'
template_name = '/stock/item-delete.html'
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())