Start Component pages
This commit is contained in:
parent
323e857aa5
commit
ed733b8bb7
@ -183,6 +183,13 @@ class Component(models.Model):
|
||||
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):
|
||||
class Meta:
|
||||
|
@ -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'),
|
||||
]
|
||||
|
@ -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'
|
||||
@ -365,3 +379,20 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
return self.handle_add_stock_post(request, **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
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
<li class="nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle text-primary" id="navbar-user-dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">{{ base.navbar.username }}</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbar-user-dropdown">
|
||||
<li><a class="dropdown-item" href="{% url 'change-pw' %}">Change Password</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'logout' %}">Logout</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'api-root' %}">REST API</a></li>
|
||||
{% if base.navbar.show_admin %}
|
||||
|
@ -0,0 +1,8 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
Meow
|
||||
{{component}}
|
||||
</div>
|
||||
{% endblock content %}
|
@ -1,5 +1,62 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Components</h1>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<h2>Components</h2>
|
||||
<div class="list-group">
|
||||
{% for comp in components %}
|
||||
<a href="{% url 'parts-components-detail' uuid=comp.id %}" class="text-decoration-none">
|
||||
<li class="list-group-item list-group-item-action d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
{% if comp.get_resolved_image %}
|
||||
<img src="{{comp.get_resolved_image}}" style="max-width:64px;max-height:64px;" alt="{{ comp.name }}" class="mr-3">
|
||||
{% else %}
|
||||
{% load static %}
|
||||
<img src="{% static 'css/icons/card-image.svg' %}" style="width:64px;max-height:64px;" alt="{{ comp.name }}" class="mr-3">
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-3">
|
||||
<h6 class="mt-0 text-primary">{{ comp.name }}</h6>
|
||||
{% if comp.package %}
|
||||
Package: {{comp.package}}<br>
|
||||
{% endif %}
|
||||
{% if comp.manufacturer %}
|
||||
Manufacturer: {{comp.manufacturer}}
|
||||
{% endif %}
|
||||
</div>
|
||||
<span class="badge bg-primary rounded-pill">{{comp.get_total_amount}}</span>
|
||||
</li>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% include 'paginator.html' with paginator=components get_param='comp_page' aria_label='Component Page Navigation' %}
|
||||
</div>
|
||||
<div class="col-md">
|
||||
<h2>Packages</h2>
|
||||
{% for pkg in packages %}
|
||||
<li class="list-group-item list-group-item-action d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
{% if pkg.image %}
|
||||
<img src="{{pkg.image.url}}" style="max-width:64px;max-height:64px;" alt="{{ pkg.name }}" class="mr-3">
|
||||
{% else %}
|
||||
{% load static %}
|
||||
<img src="{% static 'css/icons/card-image.svg' %}" style="width:64px;max-height:64px;" alt="{{ pkg.name }}" class="mr-3">
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-3">
|
||||
<h6 class="mt-0 text-primary">{{ pkg.name }}</h6>
|
||||
{% if pkg.smd %}
|
||||
SMD Package<br>
|
||||
{% endif %}
|
||||
Pin Count: {{pkg.pin_count}}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% include 'paginator.html' with paginator=packages get_param='pkg_page' aria_label='Package Page Navigation' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user