On intègre les étiquettes récemment créées aux étiquettes proposées
Fix #280
This commit is contained in:
parent
bc147016e5
commit
e46116fe0f
@ -232,6 +232,15 @@ class Tag(models.Model):
|
||||
def get_absolute_url(self):
|
||||
return reverse("view_tag", kwargs={"t": self.name})
|
||||
|
||||
|
||||
def clear_cache():
|
||||
for exclude in [False, True]:
|
||||
for include in [False, True]:
|
||||
for nb_suggestions in [10]:
|
||||
id_cache = 'all_tags ' + str(exclude) + ' ' + str(include) + ' ' + str(nb_suggestions)
|
||||
id_cache = hashlib.md5(id_cache.encode("utf8")).hexdigest()
|
||||
cache.delete(id_cache)
|
||||
|
||||
def get_tag_groups(nb_suggestions=10, exclude=False, include=False, all=False):
|
||||
id_cache = 'all_tags ' + str(exclude) + ' ' + str(include) + ' ' + str(nb_suggestions)
|
||||
id_cache = hashlib.md5(id_cache.encode("utf8")).hexdigest()
|
||||
@ -240,6 +249,7 @@ class Tag(models.Model):
|
||||
if not result:
|
||||
|
||||
free_tags = Event.get_all_tags(False)
|
||||
f_tags = [t["tag"] for t in free_tags]
|
||||
|
||||
obj_tags = Tag.objects
|
||||
|
||||
@ -260,6 +270,8 @@ class Tag(models.Model):
|
||||
nb_suggestions = len(obj_tags)
|
||||
|
||||
tags = [{"tag": t["tag"], "count": 1000000 if t["tag"] in obj_tags else t["count"]} for t in free_tags]
|
||||
tags += [{"tag": o, "count": 0} for o in Tag.objects.filter(~Q(name__in=f_tags)).values_list("name", flat=True)]
|
||||
|
||||
|
||||
tags.sort(key=lambda x: -x["count"])
|
||||
|
||||
|
@ -2097,6 +2097,10 @@ class TagCreateView(PermissionRequiredMixin, SuccessMessageMixin, CreateView):
|
||||
initial["name"] = self.request.GET.get("name")
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
Tag.clear_cache()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class TagDeleteView(PermissionRequiredMixin, DeleteView):
|
||||
model = Tag
|
||||
@ -2135,12 +2139,14 @@ def view_tag(request, t, past=False):
|
||||
|
||||
def tag_list(request):
|
||||
tags = Event.get_all_tags()
|
||||
r_tags = [t["tag"] for t in tags]
|
||||
objects = Tag.objects.order_by("name").all()
|
||||
d_objects = dict()
|
||||
for o in objects:
|
||||
d_objects[o.name] = o
|
||||
|
||||
tags = [t | {'obj': d_objects[t["tag"]]} if t["tag"] in d_objects else t for t in tags]
|
||||
tags += [{'obj': o, "tag": o.name, "count": 0} for o in objects if o.name not in r_tags]
|
||||
|
||||
context = {"tags": sorted(tags, key=lambda x: emoji.demojize(remove_accents(x["tag"]).lower(), delimiters=('000', '')))}
|
||||
return render(request, "agenda_culturel/tags.html", context)
|
||||
|
Loading…
x
Reference in New Issue
Block a user