diff --git a/.editorconfig b/.editorconfig index 60320e3..6bf52c9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,5 @@ root = true -[*.html] +[*.{html,js}] indent_size = 4 indent_style = space diff --git a/lelcsc/core/context_processors.py b/lelcsc/core/context_processors.py index 4aa79bf..923d0f9 100644 --- a/lelcsc/core/context_processors.py +++ b/lelcsc/core/context_processors.py @@ -1,3 +1,4 @@ +from .forms import SearchForm from .signals import populate_nav @@ -10,3 +11,7 @@ def nav(request): ] return {"nav_items": nav_items} + + +def search(request): + return {"search_form": SearchForm()} diff --git a/lelcsc/core/forms.py b/lelcsc/core/forms.py index 939765b..9036a55 100644 --- a/lelcsc/core/forms.py +++ b/lelcsc/core/forms.py @@ -15,3 +15,21 @@ class AddStockForm(forms.Form): AddStockFormSet = forms.formset_factory(AddStockForm, extra=0) + + +class SearchForm(forms.Form): + PER_PAGE_CHOICES = [ + (10, "10"), + (25, "25"), + (50, "50"), + (100, "100"), + ] + + q = forms.CharField(label=_("Search"), required=False) + per_page = forms.TypedChoiceField( + choices=PER_PAGE_CHOICES, + coerce=int, + empty_value=25, + label=_("Results per page"), + widget=forms.Select(attrs={"form": "searchForm"}), + ) diff --git a/lelcsc/core/static/core/search_results.js b/lelcsc/core/static/core/search_results.js new file mode 100644 index 0000000..3c17c93 --- /dev/null +++ b/lelcsc/core/static/core/search_results.js @@ -0,0 +1,3 @@ +document.getElementById('id_per_page').addEventListener('change', event => { + event.target.form.requestSubmit(); +}); diff --git a/lelcsc/core/templates/core/search_results.html b/lelcsc/core/templates/core/search_results.html new file mode 100644 index 0000000..92daaa9 --- /dev/null +++ b/lelcsc/core/templates/core/search_results.html @@ -0,0 +1,55 @@ +{% extends "base.html" %} + +{% load django_bootstrap5 %} +{% load i18n %} +{% load properties %} +{% load static %} + +{% block page_title %}{% translate "Search results for" %} "{{ query }}"{% endblock %} + +{% block content %} +
+ {% translate "Part number" %}
+ {% translate "Total stock" %}
+ |
+ {% translate "Total stock" %} | +{% for property in properties %} +{{ property.name }} | +{% endfor %} +|
---|---|---|---|
+ {{ component.part_number }}
+
|
+ {{ component.total_stock }} | +{% for _, value in properties %} +{% if value %} +{{ value|format_value }} | +{% else %} +{% translate "n/a" %} | +{% endif %} +{% endfor %} +