Le cache des pages ne contient pas le formulaire

This commit is contained in:
Jean-Marie Favreau 2024-11-14 22:38:39 +01:00
parent 1f60bf0c39
commit df27949036
4 changed files with 41 additions and 32 deletions

View File

@ -8,6 +8,8 @@ from django.urls import reverse
from colorfield.fields import ColorField from colorfield.fields import ColorField
from django_ckeditor_5.fields import CKEditor5Field from django_ckeditor_5.fields import CKEditor5Field
from urllib.parse import urlparse from urllib.parse import urlparse
from django.core.cache import cache
import urllib.request import urllib.request
import os import os
from django.core.files import File from django.core.files import File
@ -213,38 +215,43 @@ class Tag(models.Model):
return reverse("view_tag", kwargs={"t": self.name}) return reverse("view_tag", kwargs={"t": self.name})
def get_tag_groups(nb_suggestions=10, exclude=False, include=False): def get_tag_groups(nb_suggestions=10, exclude=False, include=False):
free_tags = Event.get_all_tags(False) id_cache = 'all_tags ' + str(exclude) + ' ' + str(include) + ' ' + str(nb_suggestions)
result = cache.get(id_cache)
if not result: #
obj_tags = Tag.objects free_tags = Event.get_all_tags(False)
try: obj_tags = Tag.objects
if exclude:
obj_tags = obj_tags.filter(Q(in_excluded_suggestions=True))
if include:
obj_tags = obj_tags.filter(Q(in_included_suggestions=True)|Q(principal=True))
except FieldDoesNotExist:
pass
if not exclude and not include: try:
obj_tags = obj_tags.filter(principal=True) if exclude:
obj_tags = obj_tags.filter(Q(in_excluded_suggestions=True))
if include:
obj_tags = obj_tags.filter(Q(in_included_suggestions=True)|Q(principal=True))
except FieldDoesNotExist:
pass
obj_tags = obj_tags.values_list("name", flat=True) if not exclude and not include:
obj_tags = obj_tags.filter(principal=True)
if len(obj_tags) > nb_suggestions: obj_tags = obj_tags.values_list("name", flat=True)
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] if len(obj_tags) > nb_suggestions:
nb_suggestions = len(obj_tags)
tags.sort(key=lambda x: -x["count"]) tags = [{"tag": t["tag"], "count": 1000000 if t["tag"] in obj_tags else t["count"]} for t in free_tags]
tags1 = tags[0:nb_suggestions] tags.sort(key=lambda x: -x["count"])
tags1.sort(key=lambda x: remove_accents(x["tag"]).lower())
tags2 = tags[nb_suggestions:]
tags2.sort(key=lambda x: remove_accents(x["tag"]).lower())
result = ((_('Suggestions'), [(t["tag"], t["tag"]) for t in tags1]), tags1 = tags[0:nb_suggestions]
(_('Others'), [(t["tag"], t["tag"]) for t in tags2])) tags1.sort(key=lambda x: remove_accents(x["tag"]).lower())
tags2 = tags[nb_suggestions:]
tags2.sort(key=lambda x: remove_accents(x["tag"]).lower())
result = ((_('Suggestions'), [(t["tag"], t["tag"]) for t in tags1]),
(_('Others'), [(t["tag"], t["tag"]) for t in tags2]))
cache.set(id_cache, result, 300) # 5mn
return result return result

View File

@ -25,12 +25,12 @@
{% block content %} {% block content %}
{% get_current_language as LANGUAGE_CODE %}
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
{% cache cache_timeout month user.is_authenticated calendar.firstdate filter.to_str LANGUAGE_CODE %}
{% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=0 %} {% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=0 %}
{% get_current_language as LANGUAGE_CODE %}
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
{% cache cache_timeout month user.is_authenticated calendar.firstdate filter.to_str LANGUAGE_CODE %}
<article> <article>
<header> <header>

View File

@ -21,9 +21,6 @@
{% block content %} {% block content %}
{% get_current_language as LANGUAGE_CODE %}
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
{% cache cache_timeout upcoming user.is_authenticated calendar.firstdate filter.to_str calendar.calendar_days_list|length LANGUAGE_CODE %}
<article id="filters"> <article id="filters">
<header><h1 id="index-avenir">{% block title %}{% block og_title %} <header><h1 id="index-avenir">{% block title %}{% block og_title %}
@ -40,6 +37,10 @@
{% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=1 %} {% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=1 %}
{% get_current_language as LANGUAGE_CODE %}
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
{% cache cache_timeout upcoming user.is_authenticated calendar.firstdate filter.to_str calendar.calendar_days_list|length LANGUAGE_CODE %}
<footer> <footer>
<a href="{% if calendar.calendar_days_list|length == 1 %}{% url 'day_view' date_pred.year date_pred.month date_pred.day %}{% else %}{% url 'a_venir_jour' date_pred.year date_pred.month date_pred.day %}{% endif %}" aria-label="dates précédentes" role="button"> <a href="{% if calendar.calendar_days_list|length == 1 %}{% url 'day_view' date_pred.year date_pred.month date_pred.day %}{% else %}{% url 'a_venir_jour' date_pred.year date_pred.month date_pred.day %}{% endif %}" aria-label="dates précédentes" role="button">
{% picto_from_name "chevrons-left" %} {% picto_from_name "chevrons-left" %}

View File

@ -21,12 +21,13 @@
{% block content %} {% block content %}
{% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=0 %}
{% get_current_language as LANGUAGE_CODE %} {% get_current_language as LANGUAGE_CODE %}
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %} {% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
{% cache cache_timeout week user.is_authenticated calendar.firstdate filter.to_str LANGUAGE_CODE %} {% cache cache_timeout week user.is_authenticated calendar.firstdate filter.to_str LANGUAGE_CODE %}
{% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=0 %}
<article> <article>
<header> <header>
<div class="title small"><h1> <div class="title small"><h1>