Journalisation des recherches

This commit is contained in:
Evarin 2018-12-26 20:23:20 +01:00
parent bdca70964a
commit 78d4d7c624
2 changed files with 28 additions and 1 deletions

View file

@ -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)

View file

@ -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,
},
},
}