From 97d22fece6a88a6a36e07e1fbd55aa491f3f685f Mon Sep 17 00:00:00 2001 From: quimmrc Date: Tue, 17 Dec 2024 12:05:58 +0100 Subject: [PATCH] make tag browsing case-insensitive and unique --- search/views.py | 4 ++-- tags/views.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/search/views.py b/search/views.py index 707c49aec..4d1c63894 100644 --- a/search/views.py +++ b/search/views.py @@ -63,7 +63,7 @@ def search_view_helper(request): request.user.profile.use_compact_mode = request_preference request.user.profile.save() - # Parpare variables for map view (prepare some URLs for loading sounds and providing links to map) + # Prepare variables for map view (prepare some URLs for loading sounds and providing links to map) open_in_map_url = None map_mode_query_results_cache_key = None map_bytearray_url = '' @@ -152,7 +152,7 @@ def search_view_helper(request): 'tags_mode': sqp.tags_mode_active(), 'query_time': results.q_time })) - + # Compile template variables return { 'sqp': sqp, diff --git a/tags/views.py b/tags/views.py index 246e7b42b..ae9878f1b 100644 --- a/tags/views.py +++ b/tags/views.py @@ -34,12 +34,13 @@ def tags(request, multiple_tags=None): - + if multiple_tags: multiple_tags = multiple_tags.split('/') else: multiple_tags = [] - multiple_tags = sorted([x for x in multiple_tags if x]) + #Make all tags lower-cased and unique to get a case-insensitive search filter and shortened browse url + multiple_tags = sorted(set([x.lower() for x in multiple_tags if x])) if multiple_tags: # We re-write tags as query filter and redirect search_filter = "+".join('tag:"' + tag + '"' for tag in multiple_tags) @@ -51,7 +52,7 @@ def tags(request, multiple_tags=None): if pack_flt is not None: # If username is passed as a GET parameter, add it as well to the filter search_filter += f'+grouping_pack:{pack_flt}' - + return HttpResponseRedirect(f"{reverse('tags')}?f={search_filter}") else: # Share same view code as for the search view, but "tags mode" will be on