-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from importlib import import_module | ||
|
||
from django.conf import settings | ||
from django.contrib import admin | ||
|
||
from sessionprofile.models import SessionProfile | ||
|
||
|
||
@admin.register(SessionProfile) | ||
class SessionProfileAdmin(admin.ModelAdmin): | ||
list_display = ["session_key", "user", "expiration_time", "exists"] | ||
|
||
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 | ||
|
||
@admin.display(boolean=True) | ||
def exists(self, obj): | ||
return self.SessionStore().exists(obj.session_key) | ||
|
||
def expiration_time(self, obj): | ||
|
||
if self.SessionStore().exists(obj.session_key): | ||
session = self.SessionStore(obj.session_key) | ||
return session.get_expiry_date() | ||
return None | ||
|
||
def delete_model(self, request, obj): | ||
self.SessionStore().flush(obj.session_key) | ||
super().delete_model(request, obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters