From 84618deac02d9bad947603c983a0ef8b59f18fda Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Fri, 19 Jun 2020 11:01:19 +0100 Subject: [PATCH] FEAT: Improve 'omni'search - Partialised template - Added to assets header - Added ability to search assets/suppliers - Improved selection logic - Have it display current query --- PyRIGS/urls.py | 2 + PyRIGS/views.py | 4 ++ RIGS/templates/base_rigs.html | 32 +--------------- RIGS/urls.py | 1 - RIGS/views.py | 4 -- assets/forms.py | 2 +- assets/templates/asset_list.html | 9 ++--- assets/templates/base_assets.html | 1 + assets/views.py | 2 +- templates/base.html | 20 +++++----- templates/partials/search.html | 38 +++++++++++++++++++ .../templates => templates}/search_help.html | 18 ++++++++- 12 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 templates/partials/search.html rename {RIGS/templates => templates}/search_help.html (81%) diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index 4e859361..564cf31c 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -23,6 +23,8 @@ urlpatterns = [ path('api///', login_required(views.SecureAPIRequest.as_view()), name="api_secure"), + path('search_help/', views.SearchHelp.as_view(), name='search_help'), + path('admin/', admin.site.urls), ] diff --git a/PyRIGS/views.py b/PyRIGS/views.py index 4afed9d5..0582873b 100644 --- a/PyRIGS/views.py +++ b/PyRIGS/views.py @@ -159,3 +159,7 @@ class GenericListView(generic.ListView): if orderBy != "": object_list = object_list.order_by(orderBy) return object_list + + +class SearchHelp(generic.TemplateView): + template_name = 'search_help.html' diff --git a/RIGS/templates/base_rigs.html b/RIGS/templates/base_rigs.html index 609d923e..6bda8547 100644 --- a/RIGS/templates/base_rigs.html +++ b/RIGS/templates/base_rigs.html @@ -53,28 +53,11 @@ {% if perms.RIGS.view_venue %} {% endif %} -
-
-
- -
- -
- - -
{% endif %} {% endblock %} {% block titleelements_right %} +{% include 'partials/search.html' %} {% include 'partials/navbar_user.html' %} {% endblock %} @@ -86,17 +69,4 @@ $('[data-toggle="tooltip"]').tooltip(); }) - {% endblock %} diff --git a/RIGS/urls.py b/RIGS/urls.py index 2b7220f8..b7f29378 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -13,7 +13,6 @@ urlpatterns = [ path('', login_required(views.Index.as_view()), name='index'), path('closemodal/', views.CloseModal.as_view(), name='closemodal'), - path('search_help/', views.SearchHelp.as_view(), name='search_help'), # People path('people/', permission_required_with_403('RIGS.view_person')(views.PersonList.as_view()), diff --git a/RIGS/views.py b/RIGS/views.py index ea948883..24b2e53e 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -41,10 +41,6 @@ class Index(generic.TemplateView): return context -class SearchHelp(generic.TemplateView): - template_name = 'search_help.html' - - """ Called from a modal window (e.g. when an item is submitted to an event/invoice). May optionally also include some javascript in a success message to cause a load of diff --git a/assets/forms.py b/assets/forms.py index 04959c5f..098a90c8 100644 --- a/assets/forms.py +++ b/assets/forms.py @@ -29,7 +29,7 @@ class AssetAuditForm(AssetForm): class AssetSearchForm(forms.Form): - query = forms.CharField(required=False) + q = forms.CharField(required=False) category = forms.ModelMultipleChoiceField(models.AssetCategory.objects.all(), required=False) status = forms.ModelMultipleChoiceField(models.AssetStatus.objects.all(), required=False) diff --git a/assets/templates/asset_list.html b/assets/templates/asset_list.html index 27e14490..09d52168 100644 --- a/assets/templates/asset_list.html +++ b/assets/templates/asset_list.html @@ -16,11 +16,11 @@ {% block content %}

Asset List

-
-
+ +
- {% render_field form.query|add_class:'form-control' placeholder='Search by Asset ID/Desc/Serial' style="width: 250px"%} - + {% render_field form.q|add_class:'form-control' placeholder='Search by Asset ID/Desc/Serial' style="width: 250px"%} +
@@ -49,5 +49,4 @@ {% paginator %}
{% endif %} - {% endblock %} diff --git a/assets/templates/base_assets.html b/assets/templates/base_assets.html index 8d34c766..cd5f0cfe 100644 --- a/assets/templates/base_assets.html +++ b/assets/templates/base_assets.html @@ -40,5 +40,6 @@ {% endblock %} {% block titleelements_right %} +{% include 'partials/search.html' %} {% include 'partials/navbar_user.html' %} {% endblock %} diff --git a/assets/views.py b/assets/views.py index 18fc75a0..eff92d02 100644 --- a/assets/views.py +++ b/assets/views.py @@ -41,7 +41,7 @@ class AssetList(LoginRequiredMixin, generic.ListView): return self.model.objects.none() # TODO Feedback to user when search fails - query_string = form.cleaned_data['query'] or "" + query_string = form.cleaned_data['q'] or "" if len(query_string) == 0: queryset = self.model.objects.all() elif len(query_string) >= 3: diff --git a/templates/base.html b/templates/base.html index e44703bb..5d119db8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -28,16 +28,6 @@ {% endblock %} {% block extra-head %}{% endblock %} - @@ -132,6 +122,16 @@ }); + {% block js %} {% endblock %} diff --git a/templates/partials/search.html b/templates/partials/search.html new file mode 100644 index 00000000..3e203109 --- /dev/null +++ b/templates/partials/search.html @@ -0,0 +1,38 @@ +{% if user.is_authenticated %} + +
+
+ +
+ +
+ + +
+{% endif %} + +{% block js %} + +{% endblock %} diff --git a/RIGS/templates/search_help.html b/templates/search_help.html similarity index 81% rename from RIGS/templates/search_help.html rename to templates/search_help.html index 8a40d6f2..41ec63c3 100644 --- a/RIGS/templates/search_help.html +++ b/templates/search_help.html @@ -26,7 +26,7 @@

Events are sorted in reverse start_date order (most recent events at the top)

-

Searching People/Organisations/Venues

+

Searching People/Organisations/Venues/Suppliers

@@ -54,7 +54,21 @@

Entering a raw integer will search by both invoice_id and event_id

Entries are sorted in reverse invoice_date order

- {% endif %} + {% endif %} +
+

Searching Assets

+
+
+

+ Searches for entire search phrase in: + description and + serial number +

+

+ Will also attempt to exact match asset ID +

+

Entries are sorted in alphanumerical order by asset ID

+