Start Component pages

This commit is contained in:
2021-11-09 16:35:11 +01:00
parent 323e857aa5
commit ed733b8bb7
6 changed files with 112 additions and 7 deletions

View File

@@ -182,6 +182,13 @@ class Component(models.Model):
def get_qr_code(self):
qrdata = '[comp_uuid]' + str(self.id)
return qrdata
def get_total_amount(self):
stocks = Stock.objects.filter(component=self)
sum = stocks.aggregate(Sum('amount'))['amount__sum']
if sum is None:
sum = 0
return sum
class ComponentParameter(models.Model):

View File

@@ -7,6 +7,7 @@ urlpatterns = [
path('stocks/', parts_views.StockView.as_view(), name='parts-stocks'),
path('logout/', parts_views.logout_view, name='logout'),
path('login/', parts_views.login_view, name='login'),
path('changepw/', parts_views.ChangePasswordView.as_view(), name='parts-change-pw'),
path('stocks/<slug:uuid>', parts_views.StockViewDetail.as_view(), name='parts-stocks-detail'),
path('changepw/', parts_views.ChangePasswordView.as_view(), name='change-pw'),
path('stocks/<slug:uuid>/', parts_views.StockViewDetail.as_view(), name='parts-stocks-detail'),
path('components/<slug:uuid>/', parts_views.ComponentDetailView.as_view(), name='parts-components-detail'),
]

View File

@@ -11,7 +11,7 @@ from django.views import View
import django.forms as forms
from django.views.generic import TemplateView, DetailView
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from .models import Storage, Stock
from .models import Storage, Stock, Component, Distributor, Manufacturer, Package
from .qr_parser import QrCodeValidator
from django.core.paginator import Paginator
from django.core.exceptions import ValidationError
@@ -66,8 +66,6 @@ class ChangePasswordView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
return context
def post(self, request, *args, **kwargs):
if 'submit-change-pw' not in request.POST:
return super().post(request, *args, **kwargs)
@@ -137,6 +135,22 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
template_name = 'parts/components.html'
base_title = 'Components'
navbar_selected = 'Components'
default_page_size = 10
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
comp_page_num = self.request.GET.get('comp_page', default=1)
pkg_page_num = self.request.GET.get('pkg_page', default= 1)
comp_paginator = Paginator(Component.objects.all(), self.default_page_size)
pkg_paginator = Paginator(Package.objects.all(), self.default_page_size)
context['components'] = comp_paginator.get_page(comp_page_num)
context['packages'] = pkg_paginator.get_page(pkg_page_num)
return context
class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
template_name = 'parts/stocks.html'
@@ -364,4 +378,21 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
elif 'submit-add-stock' in request.POST:
return self.handle_add_stock_post(request, **kwargs)
return super().post(request, *args, **kwargs)
return super().post(request, *args, **kwargs)
class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
template_name = 'parts/components-detail.html'
model = Component
pk_url_kwarg = 'uuid'
base_title = ''
navbar_selected = 'Components'
def get_context_data(self, **kwargs):
self.base_title = 'Component / '+self.object.name
context = super().get_context_data(**kwargs)
context['component'] = self.object
return context