-
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.
Add management command to clear sessions
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 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,19 @@ | ||
from django.conf import settings | ||
from django.contrib.sessions.models import Session | ||
from django.core.cache import cache | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Force logout all users by clearing sessions" | ||
|
||
def handle(self, *args, **kwargs): | ||
# Clear database sessions | ||
self.stderr.write("Clearing all sessions.") | ||
Session.objects.all().delete() | ||
self.stderr.write(self.style.SUCCESS("All sessions cleared.")) | ||
if "cached_db" in settings.SESSION_ENGINE: | ||
# Clear cached sessions | ||
self.stderr.write("Using cached_db session engine. Clearing cache.") | ||
cache.clear() | ||
self.stderr.write(self.style.SUCCESS("Cache is cleared.")) |