Skip to content

Commit

Permalink
✨[#46] add session profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Coperh committed Sep 24, 2024
1 parent 19839d7 commit 2d0b8d0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions open_api_framework/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.contrib import admin
from importlib import import_module
from django.conf import settings

from sessionprofile.models import SessionProfile


@admin.register(SessionProfile)
class SessionProfileAdmin(admin.ModelAdmin):
list_display = ["session_key", "user", "expiration_time"]

def __init__(self, model, admin_site):
engine = import_module(settings.SESSION_ENGINE)
self.SessionStore = engine.SessionStore
super().__init__(model, admin_site)

def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.filter(user=request.user)

def has_add_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False

def expiration_time(self, obj):
session = self.SessionStore(obj.session_key)
return session.get_expiry_date()

def delete_model(self, request, obj):

self.SessionStore(obj.session_key).flush()
obj.delete()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies = [
"flower>=2.0.1",
"maykin-2fa>=1.0.1",
"django-setup-configuration>=0.1.0",
"django-sessionprofile>=3.0.0",
]

[project.urls]
Expand Down
2 changes: 2 additions & 0 deletions testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
"django.contrib.messages",
"django.contrib.admin",
"open_api_framework",
"sessionprofile",
"testapp",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"sessionprofile.middleware.SessionProfileMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand Down

0 comments on commit 2d0b8d0

Please sign in to comment.