Improve admin

This commit is contained in:
Michael Herrmann
2024-03-25 18:37:14 +01:00
parent 59c71cd5e1
commit 7006247b29
+12 -3
View File
@@ -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)
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__))