2017-04-14 02:14:50 +00:00
|
|
|
|
2018-04-13 12:36:59 +00:00
|
|
|
# Template stuff (WIP)
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.template import loader
|
|
|
|
|
2017-04-14 03:09:24 +00:00
|
|
|
from InvenTree.models import FilterChildren
|
2018-04-12 06:27:26 +00:00
|
|
|
from .models import PartCategory, Part
|
|
|
|
|
2018-04-13 12:36:59 +00:00
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.views import generic
|
|
|
|
|
|
|
|
def index(request):
|
2018-04-13 14:08:30 +00:00
|
|
|
template = loader.get_template('part/index.html')
|
2018-04-13 12:36:59 +00:00
|
|
|
|
|
|
|
parts = Part.objects.all()
|
|
|
|
|
|
|
|
cat = None
|
|
|
|
|
|
|
|
if 'category' in request.GET:
|
|
|
|
cat_id = request.GET['category']
|
|
|
|
|
|
|
|
cat = get_object_or_404(PartCategory, pk=cat_id)
|
2018-04-14 05:13:16 +00:00
|
|
|
|
2018-04-13 12:36:59 +00:00
|
|
|
parts = parts.filter(category = cat_id)
|
2018-04-14 05:13:16 +00:00
|
|
|
children = PartCategory.objects.filter(parent = cat_id)
|
|
|
|
|
|
|
|
else:
|
|
|
|
parts = parts.filter(category__isnull=True)
|
|
|
|
children = PartCategory.objects.filter(parent__isnull=True)
|
2018-04-13 12:36:59 +00:00
|
|
|
|
|
|
|
context = {
|
|
|
|
'parts' : parts.order_by('category__name'),
|
2018-04-14 05:13:16 +00:00
|
|
|
'category' : cat,
|
|
|
|
'children' : children,
|
2018-04-13 12:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return HttpResponse(template.render(context, request))
|
|
|
|
|
|
|
|
|
|
|
|
def detail(request, pk):
|
|
|
|
#template = loader.get_template('detail.html')
|
|
|
|
|
|
|
|
part = get_object_or_404(Part, pk=pk)
|
|
|
|
|
2018-04-13 14:08:30 +00:00
|
|
|
return render(request, 'part/detail.html', {'part' : part})
|
2018-04-13 12:36:59 +00:00
|
|
|
|
|
|
|
#return HttpResponse("You're looking at part %s." % pk)
|
|
|
|
|
2018-04-13 14:08:30 +00:00
|
|
|
|
|
|
|
def bom(request, pk):
|
|
|
|
part = get_object_or_404(Part, pk=pk)
|
|
|
|
|
|
|
|
return render(request, 'part/bom.html', {'part': part})
|
|
|
|
|
2018-04-14 11:58:01 +00:00
|
|
|
def used(request, pk):
|
|
|
|
part = get_object_or_404(Part, pk=pk)
|
|
|
|
|
|
|
|
return render(request, 'part/used_in.html', {'part': part})
|
|
|
|
|
2018-04-13 14:08:30 +00:00
|
|
|
def stock(request, pk):
|
|
|
|
part = get_object_or_404(Part, pk=pk)
|
|
|
|
|
|
|
|
return render(request, 'part/stock.html', {'part': part})
|
|
|
|
|
2018-04-13 14:46:18 +00:00
|
|
|
def track(request, pk):
|
|
|
|
part = get_object_or_404(Part, pk=pk)
|
|
|
|
|
|
|
|
return render(request, 'part/track.html', {'part': part})
|
|
|
|
|
2018-04-14 06:26:26 +00:00
|
|
|
|
|
|
|
def suppliers(request, pk):
|
|
|
|
part = get_object_or_404(Part, pk=pk)
|
|
|
|
|
|
|
|
return render(request, 'part/supplier.html', {'part' : part})
|