2013-07-29 21:50:58 +08:00
|
|
|
from importlib import import_module
|
|
|
|
|
2012-10-28 05:12:08 +08:00
|
|
|
from django.conf import settings
|
2014-06-18 07:07:54 +08:00
|
|
|
from django.core.management.base import BaseCommand
|
2012-10-28 05:12:08 +08:00
|
|
|
|
2012-10-27 17:49:46 +08:00
|
|
|
|
2014-06-18 07:07:54 +08:00
|
|
|
class Command(BaseCommand):
|
2014-09-04 20:15:09 +08:00
|
|
|
help = (
|
|
|
|
"Can be run as a cronjob or directly to clean out expired sessions "
|
|
|
|
"(only with the database backend at the moment)."
|
|
|
|
)
|
2012-10-27 17:49:46 +08:00
|
|
|
|
2014-06-18 07:07:54 +08:00
|
|
|
def handle(self, **options):
|
2012-10-28 05:12:08 +08:00
|
|
|
engine = import_module(settings.SESSION_ENGINE)
|
|
|
|
try:
|
|
|
|
engine.SessionStore.clear_expired()
|
|
|
|
except NotImplementedError:
|
|
|
|
self.stderr.write("Session engine '%s' doesn't support clearing "
|
|
|
|
"expired sessions.\n" % settings.SESSION_ENGINE)
|