From 7006247b295ed14aa4bfb40859234bc89e3b2b84 Mon Sep 17 00:00:00 2001 From: Michael Herrmann Date: Mon, 25 Mar 2024 18:37:14 +0100 Subject: [PATCH] Improve admin --- core/middlewares.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/middlewares.py b/core/middlewares.py index 71f5397..39c4df5 100644 --- a/core/middlewares.py +++ b/core/middlewares.py @@ -1,6 +1,10 @@ from base64 import b64decode +from datetime import datetime from django.contrib.messages import get_messages, add_message from django.utils.deprecation import MiddlewareMixin +from django.utils.safestring import mark_safe +from functools import lru_cache +from os.path import getmtime # Before you remove this middleware, consider the consequences if your server # gets hacked. The attacker will be able to install malicious software on all @@ -12,12 +16,17 @@ class RequestMiddleware(MiddlewareMixin): _MESSAGE = _decode( b'VGhpcyB2ZXJzaW9uIG9mIHdpbmdldC5Qcm8gaXMgaW5zZWN1cmUuIEFzIG9mIHRoaXMgd' b'3JpdGluZywgdGhlcmUgYXJlIDMgdW5wYXRjaGVkIHZ1bG5lcmFiaWxpdGllcy4gUGxlYX' - b'NlIHN1YnNjcmliZSB0byBzZWN1cml0eSBmaXhlcyB2aWEgdGhlIGxpbmsgb24gR2l0SHV' - b'iLg==' + b'NlIHN1YnNjcmliZSB0byBzZWN1cml0eSBmaXhlcyA8YSBocmVmPSJodHRwczovL2J1eS5' + b'zdHJpcGUuY29tL2NOMjRrOWNyejkxcmU4VTlBTyI+aGVyZTwvYT4=' ) def process_request(self, request): if request.path.startswith(self._ROUTE_PREFIX): for m in get_messages(request): if m.message == self._MESSAGE: return - add_message(request, 40, self._MESSAGE) \ No newline at end of file + if (datetime.now() - _get_mtime()).days > 90: + add_message(request, 40, mark_safe(self._MESSAGE)) + +@lru_cache(maxsize=1) +def _get_mtime(): + return datetime.fromtimestamp(getmtime(__file__)) \ No newline at end of file