Kantan log is a simple Django helper app. This app supports logging to Django Model's created_by, updated_by. At http requests interception, too.
shell>pip install djangokantanlog
Installed apps:
INSTALLED_APPS = [
...
'kantanlog.apps.KantanlogConfig',
]
Middleware:
MIDDLEWARE = [
...
'kantanlog.middlewares.KantanlogMiddleware',
]
Default: ()
Target apps, settings as app-label:
KLOG_TARGET_APP_LABELS = (
...
'myapp',
)
Default: kantanlog.backends.KantanlogDefaultBackend
As interface, getting user.
e.g.
# at settings.py
KLOG_BACKEND = 'dotted.path.to.MyappBackend'
...
# -*- coding: utf8 -*-
from logging import getLogger
from kantanlog.backends import KantanlogDefaultBackend
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from rest_framework_jwt.settings import api_settings
logger = getLogger(__name__)
payload_handler = api_settings.JWT_PAYLOAD_HANDLER
encode_handler = api_settings.JWT_ENCODE_HANDLER
class MyappBackend(KantanlogDefaultBackend):
def __init__(self):
super().__init__()
def get_user(self, request):
user = super().get_user(request)
if user.is_authenticated:
return user
ja = JSONWebTokenAuthentication()
if ja.get_jwt_value(request):
user, jwt = ja.authenticate(request)
return user
return user