From bf5db35e57c8c9d5441daee5f6de8bd649276139 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Tue, 19 Nov 2024 23:36:33 +0100 Subject: [PATCH] On trie les emoji en premier Fix #212 --- src/agenda_culturel/models.py | 7 ++++--- src/agenda_culturel/static/style.scss | 2 ++ src/agenda_culturel/views.py | 5 +++-- src/requirements.txt | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index f817b32..04f2bff 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -9,6 +9,7 @@ from colorfield.fields import ColorField from django_ckeditor_5.fields import CKEditor5Field from urllib.parse import urlparse from django.core.cache import cache +import emoji import hashlib import urllib.request @@ -247,9 +248,9 @@ class Tag(models.Model): tags.sort(key=lambda x: -x["count"]) tags1 = tags[0:nb_suggestions] - tags1.sort(key=lambda x: remove_accents(x["tag"]).lower()) + tags1.sort(key=lambda x: emoji.demojize(remove_accents(x["tag"]).lower(), delimiters=('000', ''))) tags2 = tags[nb_suggestions:] - tags2.sort(key=lambda x: remove_accents(x["tag"]).lower()) + tags2.sort(key=lambda x: emoji.demojize(remove_accents(x["tag"]).lower(), delimiters=('000', ''))) result = ((_('Suggestions'), [(t["tag"], t["tag"]) for t in tags1]), (_('Others'), [(t["tag"], t["tag"]) for t in tags2])) @@ -697,7 +698,7 @@ class Event(models.Model): cursor.execute(raw_query) result = [{"tag": row[0], "count": row[1]} for row in cursor] if sort: - result.sort(key=lambda x: remove_accents(x["tag"].lower())) + result.sort(key=lambda x: emoji.demojize(remove_accents(x["tag"].lower()), delimiters=('000', ''))) return result def is_draft(self): diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index c105ca7..88a6c6c 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -199,6 +199,8 @@ details[role="list"] summary + ul li.selected>a:hover { font-size: 90%; padding: 0.15em 0.4em 0.3em 0.4em; overflow: hidden; + float: left; + text-align: left; } .suggested-tags .small-cat { diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 7afdf39..d7683d7 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -17,6 +17,7 @@ from django.contrib.gis.measure import D from django.http import HttpResponseRedirect, HttpResponse from django.urls import reverse from collections import Counter +import emoji from django.forms import formset_factory @@ -928,7 +929,7 @@ def event_search(request, full=False): categories = Category.objects.filter(name__icontains=request.GET['q']) s_q = remove_accents(request.GET['q'].lower()) tags = Event.objects.extra(where=['%s ILIKE ANY (tags)'], params=[request.GET['q']]).annotate(arr_tags=Func(F('tags'), function='unnest')).values_list('arr_tags', flat=True).distinct() - tags = [(t, remove_accents(t).lower()) for t in tags] + tags = [(t, emoji.demojize(remove_accents(t).lower(), delimiters=('000', ''))) for t in tags] tags = [t for t in tags if s_q == t[1]] tags.sort(key=lambda x: x[1]) tags = [t[0] for t in tags] @@ -1886,7 +1887,7 @@ def tag_list(request): tags = [t | {'obj': d_objects[t["tag"]]} if t["tag"] in d_objects else t for t in tags] - context = {"tags": sorted(tags, key=lambda x: remove_accents(x["tag"]).lower())} + context = {"tags": sorted(tags, key=lambda x: emoji.demojize(remove_accents(x["tag"]).lower(), delimiters=('000', '')))} return render(request, "agenda_culturel/tags.html", context) @login_required(login_url="/accounts/login/") diff --git a/src/requirements.txt b/src/requirements.txt index 09ae951..4f71636 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -41,4 +41,5 @@ json5==0.9.25 django-location-field==2.7.3 django-robots==6.1 django-debug-toolbar==4.4.6 -django-cache-cleaner==0.1.0 \ No newline at end of file +django-cache-cleaner==0.1.0 +emoji==2.14.0 \ No newline at end of file