diff --git a/avisstage/views_search.py b/avisstage/views_search.py index 5614055..448a2d3 100644 --- a/avisstage/views_search.py +++ b/avisstage/views_search.py @@ -11,12 +11,15 @@ from django.http import JsonResponse, HttpResponseBadRequest from django.shortcuts import render, redirect, get_object_or_404 import json +import logging from .documents import StageDocument from .models import Stage from .statics import TYPE_LIEU_OPTIONS, TYPE_STAGE_OPTIONS, NIVEAU_SCOL_OPTIONS +logger = logging.getLogger("recherche") + # Recherche class SearchForm(forms.Form): generique = forms.CharField(required=False) @@ -146,7 +149,9 @@ def recherche_resultats(request): search_args = form.cleaned_data # Gestion du cache - cache_key = json.dumps(search_args, sort_keys=True) + lsearch_args = {key: val for key, val in search_args.items() + if val != "" and val is not None} + cache_key = json.dumps(lsearch_args, sort_keys=True) cached = cache.get(cache_key) if cached is None: # RequĂȘte effective @@ -157,11 +162,13 @@ def recherche_resultats(request): # Sauvegarde dans le cache to_cache = {"stages": stageids, "lieux": lieux, "tri": tri} cache.set(cache_key, to_cache, 600) + logger.info(cache_key) else: # Lecture du cache stageids = cached["stages"] lieux = cached["lieux"] tri = cached["tri"] + logger.info("recherche en cache") # Pagination paginator = Paginator(stageids, 25) diff --git a/experiENS/settings_base.py b/experiENS/settings_base.py index ca52a5e..ce60550 100644 --- a/experiENS/settings_base.py +++ b/experiENS/settings_base.py @@ -115,3 +115,23 @@ CAS_VERSION = 'CAS_2_SAML_1_0' LOGIN_URL = reverse_lazy('login') LOGOUT_URL = reverse_lazy('logout') + + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'file': { + 'level': 'INFO', + 'class': 'logging.FileHandler', + 'filename': os.path.join(BASE_DIR, 'recherche.log'), + }, + }, + 'loggers': { + 'recherche': { + 'handlers': ['file'], + 'level': 'INFO', + 'propagate': True, + }, + }, +}