Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.5.x] Fixed #18978 -- Moved cleanup command to sessions.
This removes a dependency of 'core' on 'contrib'. Backport of 83ba0a9 from master. This deprecation occurs after the alpha, but it's a prerequisite for fixing decently #18194 which is a release blocker.
- Loading branch information
Showing
9 changed files
with
59 additions
and
11 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
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions
11
django/contrib/sessions/management/commands/clearsessions.py
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
from django.core.management.base import NoArgsCommand | |||
from django.utils import timezone | |||
|
|||
class Command(NoArgsCommand): | |||
help = "Can be run as a cronjob or directly to clean out expired sessions (only with the database backend at the moment)." | |||
|
|||
def handle_noargs(self, **options): | |||
from django.db import transaction | |||
from django.contrib.sessions.models import Session | |||
Session.objects.filter(expire_date__lt=timezone.now()).delete() | |||
transaction.commit_unless_managed() |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,11 +1,11 @@ | |||
from django.core.management.base import NoArgsCommand | import warnings | ||
from django.utils import timezone | |||
|
|
||
class Command(NoArgsCommand): | from django.contrib.sessions.management.commands import clearsessions | ||
help = "Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment)." | |||
|
|
||
|
|||
class Command(clearsessions.Command): | |||
def handle_noargs(self, **options): | def handle_noargs(self, **options): | ||
from django.db import transaction | warnings.warn( | ||
from django.contrib.sessions.models import Session | "The `cleanup` command has been deprecated in favor of `clearsessions`.", | ||
Session.objects.filter(expire_date__lt=timezone.now()).delete() | PendingDeprecationWarning) | ||
transaction.commit_unless_managed() | super(Command, self).handle_noargs(**options) |
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
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