From d9bfb40bfcc5035aeb5ae264fb1b94f3e75bed76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?moritz=20m=C3=BCnch?= Date: Sat, 29 May 2021 09:53:42 +0200 Subject: [PATCH] #13 intermediate --- coinmanager/coinc/cache.py | 32 +------------------ .../coinc/templates/coinc/controlbar.html | 7 ++-- coinmanager/coinc/templates/header.html | 3 ++ coinmanager/coinc/views.py | 16 ++++------ coinmanager/coinmanager/settings.py | 5 +-- 5 files changed, 18 insertions(+), 45 deletions(-) diff --git a/coinmanager/coinc/cache.py b/coinmanager/coinc/cache.py index 92eeabd..79a5ef0 100644 --- a/coinmanager/coinc/cache.py +++ b/coinmanager/coinc/cache.py @@ -24,13 +24,7 @@ from random import random from django.core.cache import cache from django.http import Http404 -#todo we dont need this, no db queries from .models import Coin -from .models import Country - - -def get_etag_index(request): - return cache.get(f'etag_index', set_etag_index()) def get_last_modified_index(request): @@ -46,6 +40,7 @@ def set_last_modified_index(): cache.set(f'last_modified_index', last_modified) return last_modified + def get_last_modified_country(request, name_iso): return cache.get(f'last_modified_{name_iso}', set_last_modified_country(name_iso)) @@ -58,28 +53,3 @@ def set_last_modified_country(name_iso): raise Http404(f'Das Land "{name_iso}" existiert nicht') cache.set(f'last_modified_{name_iso}', last_modified) return last_modified - - -def set_etag_index(): - etag = '' - for country in Country.objects.order_by('name_iso'): - etag += get_etag_country_(country.name_iso) - etag = sha256(etag.encode('utf-8')).hexdigest()[0:9] - cache.set(f'etag_index', etag) - return etag - - -def get_etag_country_(name_iso): - return cache.get(f'etag_{name_iso}', set_etag_country(name_iso)) - - -def get_etag_country(request, name_iso): - return get_etag_country_(name_iso) - - -def set_etag_country(name_iso): - print(name_iso, end='') - print(cache.get(f'etag_{name_iso}', f'error {name_iso}')) - etag = sha256(str(random()).encode('utf-8')).hexdigest()[0:9] - cache.set(f'etag_{name_iso}', etag) - return etag diff --git a/coinmanager/coinc/templates/coinc/controlbar.html b/coinmanager/coinc/templates/coinc/controlbar.html index 0dd940f..d46291e 100644 --- a/coinmanager/coinc/templates/coinc/controlbar.html +++ b/coinmanager/coinc/templates/coinc/controlbar.html @@ -1,9 +1,11 @@ +{% load cache %} +{% csrf_token %} +{% cache None controlbar user %}
- {% csrf_token %} {% if user.is_authenticated %} @@ -14,7 +16,6 @@
- +{% endcache %} {% if not user.is_authenticated %}