diff --git a/shimatta_kenkyusho/parts/forms.py b/shimatta_kenkyusho/parts/forms.py new file mode 100644 index 0000000..1733841 --- /dev/null +++ b/shimatta_kenkyusho/parts/forms.py @@ -0,0 +1,8 @@ +from django import forms + +class MyTestForm(forms.Form): + pass + +class AddSubStorageForm(forms.Form): + storage_name = forms.CharField(label="storage_name", initial='') + responsible = forms.CharField(label='responsible_user') diff --git a/shimatta_kenkyusho/parts/views.py b/shimatta_kenkyusho/parts/views.py index bcf8e89..bec709b 100644 --- a/shimatta_kenkyusho/parts/views.py +++ b/shimatta_kenkyusho/parts/views.py @@ -13,6 +13,9 @@ from .models import Storage, Stock from .qr_parser import QrCodeValidator from django.core.paginator import Paginator from django.core.exceptions import ValidationError +from .forms import MyTestForm, AddSubStorageForm +from django.db.models import Q +import uuid class QrSearchForm(forms.Form): my_qr_validator = QrCodeValidator() @@ -100,10 +103,6 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): base_title = 'Components' navbar_selected = 'Components' -class AddSubStorageForm(forms.Form): - storage_name = forms.CharField(label="storage_name", initial='') - responsible = forms.CharField(label='responsible_user') - class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): template_name = 'parts/stocks.html' base_title = 'Stocks' @@ -179,17 +178,44 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): crumbs = crumbs[::-1][:-1] return crumbs + def search_stock_queryset(self, search): + stocks_in_storage = Stock.objects.filter(storage=self.object) + + if search is None or search == '': + return stocks_in_storage + + # Check if the searhc equals a UUID + test_uuid = None + try: + test_uuid = uuid.UUID(search) + except: + pass + + if test_uuid is not None: + stocks_in_storage = stocks_in_storage.filter(component__id = test_uuid) + else: + stocks_in_storage = stocks_in_storage.filter(Q(component__name__contains = search) | + Q(component__package__name__contains = search)) + + return stocks_in_storage + def get_context_data(self, **kwargs): self.base_title = 'Stocks / ' + self.object.name context = super().get_context_data(**kwargs) context['breadcrumbs'] = self.get_breadcrumbs() - storage_page = self.request.GET.get('storage_page') - if storage_page is None: - storage_page = 1 + storage_page = self.request.GET.get('storage_page', default=1) storage_paginator = Paginator(Storage.objects.filter(parent_storage=self.object), self.default_pagination_size) + stock_search_input = self.request.GET.get('search') + + componente_stock_page = self.request.GET.get('stock_page', default=1) + + + stock_paginator = Paginator(self.search_stock_queryset(stock_search_input), self.default_pagination_size) context['storages'] = storage_paginator.get_page(storage_page) + context['stocks'] = stock_paginator.get_page(componente_stock_page) + context['stock_search'] = stock_search_input add_storage_form = AddSubStorageForm() add_storage_form.fields['responsible'].initial = self.request.user.username context['add_storage_form'] = add_storage_form diff --git a/shimatta_kenkyusho/shimatta_kenkyusho/settings.py b/shimatta_kenkyusho/shimatta_kenkyusho/settings.py index a0ea56a..8aa2312 100644 --- a/shimatta_kenkyusho/shimatta_kenkyusho/settings.py +++ b/shimatta_kenkyusho/shimatta_kenkyusho/settings.py @@ -40,7 +40,9 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'parts.apps.PartsConfig', 'qr_code', - 'rest_framework' + 'rest_framework', + 'crispy_forms', + 'crispy_bootstrap5', ] MIDDLEWARE = [ @@ -170,4 +172,8 @@ LOGIN_URL = '/login' LOGIN_REDIRECT_URL = '/' -SHIMATTA_KENKYUSHO_TITLE = 'しまった・研究所' \ No newline at end of file +SHIMATTA_KENKYUSHO_TITLE = 'しまった・研究所' + +CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" + +CRISPY_TEMPLATE_PACK = "bootstrap5" \ No newline at end of file diff --git a/shimatta_kenkyusho/templates/parts/stocks-detail.html b/shimatta_kenkyusho/templates/parts/stocks-detail.html index 4cb061d..481d8a5 100644 --- a/shimatta_kenkyusho/templates/parts/stocks-detail.html +++ b/shimatta_kenkyusho/templates/parts/stocks-detail.html @@ -14,31 +14,68 @@
-
- {% qr_from_text object.get_qr_code size="m" image_format="svg" %} +
+
+ {% qr_from_text object.get_qr_code size="m" image_format="svg" %} +
+
+ {% if object.parent_storage %} +

Sub-Storages Parent Storage {% else %} +

Sub-Storages Stock Overview + {% endif %} + + +

+ + {% include 'paginator.html' with paginator=storages get_param='storage_page' aria_label='Storage Page Navigation' %} +
- {% if object.parent_storage %} -

Sub-Storages Parent Storage {% else %} -

Sub-Storages Stock Overview - {% endif %} - - -

+

Stocked Components

+
+
+ + +
+
- {% include 'paginator.html' with paginator=storages get_param='storage_page' aria_label='Storage Page Navigation' %} + {% include 'paginator.html' with paginator=stocks get_param='stock_page' aria_label='Stock Page Navigation' %}
diff --git a/shimatta_kenkyusho/templates/parts/stocks.html b/shimatta_kenkyusho/templates/parts/stocks.html index d6d2267..f6bbef0 100644 --- a/shimatta_kenkyusho/templates/parts/stocks.html +++ b/shimatta_kenkyusho/templates/parts/stocks.html @@ -8,7 +8,7 @@

Low Stocks

{% for low in low_stocks %} - +
  • {% if low.component.get_resolved_image %} @@ -19,7 +19,7 @@ {% endif %}
    -
    {{ low.component.name }} in {{ low.component.package }}
    +
    {{ low.component.name }}{% if low.component.package %} in {{ low.component.package }}{% endif %}
    {{ low.storage }}