Add package overview, search, and create modal
This commit is contained in:
parent
503ede44e3
commit
3bbc05db1e
@ -34,6 +34,7 @@ class NavBar():
|
||||
items = {
|
||||
'Main': BsNavBarItem('Main', reverse('parts-main'), False),
|
||||
'Components':BsNavBarItem('Components', reverse('parts-components'), False),
|
||||
'Packages': BsNavBarItem('Packages', reverse('parts-packages'), False),
|
||||
'Stocks':BsNavBarItem('Stocks', reverse('parts-stocks'), False),
|
||||
}
|
||||
|
||||
@ -45,6 +46,7 @@ class NavBar():
|
||||
navitems = [
|
||||
items['Main'],
|
||||
items['Components'],
|
||||
items['Packages'],
|
||||
items['Stocks'],
|
||||
#items['Login'],
|
||||
]
|
||||
|
@ -4,6 +4,7 @@ from . import views as parts_views
|
||||
urlpatterns = [
|
||||
path('', parts_views.MainView.as_view(), name='parts-main'),
|
||||
path('components/', parts_views.ComponentView.as_view(), name='parts-components'),
|
||||
path('packages/', parts_views.PackageView.as_view(), name='parts-packages'),
|
||||
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'),
|
||||
|
@ -137,22 +137,70 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||
template_name = 'parts/components.html'
|
||||
base_title = 'Components'
|
||||
navbar_selected = 'Components'
|
||||
default_page_size = 10
|
||||
|
||||
default_page_size = 25
|
||||
|
||||
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 PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||
template_name = 'parts/packages.html'
|
||||
base_title = 'Packages'
|
||||
navbar_selected = 'Packages'
|
||||
default_page_size = 25
|
||||
|
||||
def search_packages(self, search):
|
||||
qs = Package.objects.all()
|
||||
|
||||
if not search:
|
||||
return qs
|
||||
|
||||
search = search.strip()
|
||||
|
||||
qs = qs.filter(Q(name__contains = search))
|
||||
return qs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
page_num = self.request.GET.get('page', default=1)
|
||||
search_string = self.request.GET.get('search', default=None)
|
||||
|
||||
package_queryset = self.search_packages(search_string)
|
||||
|
||||
paginator = Paginator(package_queryset, self.default_page_size)
|
||||
|
||||
|
||||
context['search_string'] = search_string
|
||||
context['packages'] = paginator.get_page(page_num)
|
||||
context['new_pkg_form'] = PackageForm()
|
||||
|
||||
return context
|
||||
|
||||
def handle_add_new_package(self, request):
|
||||
|
||||
form = PackageForm(data=request.POST, files=request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
|
||||
context = self.get_context_data()
|
||||
|
||||
if not form.is_valid():
|
||||
context['new_pkg_form'] = form
|
||||
|
||||
return self.render_to_response(context)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'submit-pkg-add-new' in request.POST:
|
||||
return self.handle_add_new_package(request)
|
||||
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
|
||||
class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||
template_name = 'parts/stocks.html'
|
||||
@ -522,7 +570,7 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
model = Package
|
||||
pk_url_kwarg = 'uuid'
|
||||
base_title = ''
|
||||
navbar_selected = 'Components'
|
||||
navbar_selected = 'Packages'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.base_title = 'Package / '+self.object.name
|
||||
@ -551,7 +599,7 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
context['protected_components'] = protected_objects
|
||||
return self.render_to_response(context)
|
||||
else:
|
||||
return redirect('parts-main')
|
||||
return redirect('parts-packages')
|
||||
|
||||
def edit_package(self, request):
|
||||
edit_form = PackageForm(data=request.POST, files=request.FILES, instance=self.object)
|
||||
|
@ -33,32 +33,6 @@
|
||||
</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 %}
|
||||
<a href="{% url 'parts-packages-detail' uuid=pkg.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 pkg.image %}
|
||||
<img src="{{pkg.image.url}}" class="component-img-small" alt="{{ pkg.name }}" class="mr-3">
|
||||
{% else %}
|
||||
{% load static %}
|
||||
<img src="{% static 'css/icons/card-image.svg' %}" class="component-img-def-small" 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>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% include 'paginator.html' with paginator=packages get_param='pkg_page' aria_label='Package Page Navigation' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
78
shimatta_kenkyusho/templates/parts/packages.html
Normal file
78
shimatta_kenkyusho/templates/parts/packages.html
Normal file
@ -0,0 +1,78 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% load static %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<h2>Packages</h2>
|
||||
<form action="" method="get">
|
||||
<div class="input-group mb-3">
|
||||
<input class="form-control" name="search" type="search" placeholder="Search Package..." {% if search_string %}value="{{search_string}}"{% endif %}>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
<button class="btn btn-success" type="button" data-bs-toggle="modal" data-bs-target="#add-pkg-modal"><i class="bi bi-plus-circle"></i> Add Package</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="mb-3">
|
||||
{% include 'paginator.html' with paginator=packages get_param='page' aria_label='Package Page Navigation' %}
|
||||
</div>
|
||||
<div class="list-group mb-3">
|
||||
{% for pkg in packages %}
|
||||
<a href="{% url 'parts-packages-detail' uuid=pkg.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 pkg.image %}
|
||||
<img src="{{pkg.image.url}}" class="component-img-small" alt="{{ pkg.name }}" class="mr-3">
|
||||
{% else %}
|
||||
<img src="{% static 'css/icons/card-image.svg' %}" class="component-img-def-small" 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>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% include 'paginator.html' with paginator=packages get_param='page' aria_label='Package Page Navigation' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="add-pkg-modal" tabindex="-1" aria-labelledby="Add Package Modal" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Add New Package</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="modal-body">
|
||||
{{new_pkg_form|crispy}}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input type="submit" class="btn btn-primary" name="submit-pkg-add-new" value="Add Package">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
{% block custom_scripts %}
|
||||
<script type="text/javascript">
|
||||
{% if new_pkg_form.errors %}
|
||||
bootstrap.Modal.getOrCreateInstance(document.getElementById('add-pkg-modal')).show()
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endblock custom_scripts %}
|
@ -52,11 +52,11 @@
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
<button class="btn btn-success" type="button" data-bs-toggle="modal" data-bs-target="#add-stock-modal">
|
||||
<i class="bi bi-plus-circle"></i> Add Stock
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#add-stock-modal">
|
||||
<i class="bi bi-plus-circle"></i> Add Stock
|
||||
</button>
|
||||
<div class="list-group">
|
||||
{% for stock in stocks %}
|
||||
<li class="list-group-item list-group-item-action d-flex align-items-center">
|
||||
|
Loading…
Reference in New Issue
Block a user