From b6bd4c1390a4da7b04862189b0af70166d0caf02 Mon Sep 17 00:00:00 2001
From: willipink
Date: Mon, 5 Jul 2021 14:57:22 +0000
Subject: [PATCH] begin most recent function
---
.gitignore | 1 +
coinmanager/coinc/templates/coinc/index.html | 4 ++++
coinmanager/coinc/urls.py | 6 +++---
coinmanager/coinc/views.py | 6 +++++-
coinmanager/coinmanager/production_settings.py | 17 ++++++++++++-----
5 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/.gitignore b/.gitignore
index 600fbe2..0b39e12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ Pipfile.lock
**/__pycache__/*
coinmanager/static/*
*.sqlite3
+**/pyenv/*
diff --git a/coinmanager/coinc/templates/coinc/index.html b/coinmanager/coinc/templates/coinc/index.html
index c97bc28..fdbd127 100644
--- a/coinmanager/coinc/templates/coinc/index.html
+++ b/coinmanager/coinc/templates/coinc/index.html
@@ -2,6 +2,10 @@
{% if countrys %}
Gesamtwert {{ coin_sum }}
{% include 'coinc/filter_country.html' with countrys=countrys %}
+ Zuletzt hinzugefügt
+ {% for coin in recent_coins %}
+ {{ coin.found_on|date:"d.m.Y" }}: {{ coin.value }}€ {{ coin.name }} von {{ coin.found_by }}
+ {% endfor %}
{% else %}
Trage zuerst Länder im Adminbereich ein.
{% endif %}
{% include 'footer.html' %}
diff --git a/coinmanager/coinc/urls.py b/coinmanager/coinc/urls.py
index bfeefc4..caf2f41 100644
--- a/coinmanager/coinc/urls.py
+++ b/coinmanager/coinc/urls.py
@@ -19,15 +19,15 @@
from django.urls import path, include
+from django.views.decorators.cache import cache_page
from . import views
app_name = 'coinc'
urlpatterns = [
- path('', views.index, name='index'),
- #path('statistik', views.statistic, name='statistic'),
- path('', views.detail_country, name='country'),
+ path('', cache_page(None)(views.index), name='index'),
+ path('', cache_page(None)(views.detail_country), name='country'),
path('add/user//color/', views.add_user, name='add_user'),
path('add/coin', views.add_coin, name='add_coin'),
path('accounts/', include('django.contrib.auth.urls')),
diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py
index 90f2e2e..2765735 100644
--- a/coinmanager/coinc/views.py
+++ b/coinmanager/coinc/views.py
@@ -41,10 +41,14 @@ def index(request):
countrys = Country.objects.order_by('name')
users = User.objects.order_by('id')
coin_sum = total_coin_sum()
+ recent_coins = Coin.objects.order_by('-found_on')[:10]
+ for coin in recent_coins:
+ recent_coins[coin][value] /= 100
context = {
'countrys': countrys,
'users': users,
- 'coin_sum': f'{coin_sum:.2f} €'
+ 'coin_sum': f'{coin_sum:.2f} €',
+ 'recent_coins': recent_coins,
}
return HttpResponse(template.render(context, request))
diff --git a/coinmanager/coinmanager/production_settings.py b/coinmanager/coinmanager/production_settings.py
index 7b06358..2eac413 100644
--- a/coinmanager/coinmanager/production_settings.py
+++ b/coinmanager/coinmanager/production_settings.py
@@ -43,9 +43,9 @@ INSTALLED_APPS = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.cache.UpdateCacheMiddleware',
+# 'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
- 'django.middleware.cache.FetchFromCacheMiddleware',
+# 'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -136,12 +136,19 @@ LOGIN_REDIRECT_URL = './'
# caching
CACHES = {
'default': {
+ # file-based
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
- 'LOCATION': '/var/tmp/django_cache',
+ 'LOCATION': '/var/tmp/django-cache',
'TIMEOUT': None,
+ # memory-based
+ #'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ #'LOCATION': 'coinc',
+ #'TIMEOUT': None,
}
}
# caching
-CACHE_MIDDLEWARE_ALIAS = 'default'
-CACHE_MIDDLEWARE_SECONDS = 60*60*24*7
+# CACHE_MIDDLEWARE_ALIAS = 'default'
+CACHE_MIDDLEWARE_SECONDS = 60*60*24*365
+
+CACHEOPS_REDIS = "unix://var/run/redis/redis-server.sock"