Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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...
commit b760503a270484679ad0e06b73e3ed417a113221 1 parent 15ea36d
Aymeric Augustin authored October 27, 2012
8  django/bin/daily_cleanup.py
@@ -7,7 +7,13 @@
7 7
 sessions at the moment).
8 8
 """
9 9
 
  10
+import warnings
  11
+
10 12
 from django.core import management
11 13
 
12 14
 if __name__ == "__main__":
13  
-    management.call_command('cleanup')
  15
+    warnings.warn(
  16
+        "The `daily_cleanup` script has been deprecated "
  17
+        "in favor of `django-admin.py clearsessions`.",
  18
+        PendingDeprecationWarning)
  19
+    management.call_command('clearsessions')
11  django/contrib/sessions/management/commands/clearsessions.py
... ...
@@ -0,0 +1,11 @@
  1
+from django.core.management.base import NoArgsCommand
  2
+from django.utils import timezone
  3
+
  4
+class Command(NoArgsCommand):
  5
+    help = "Can be run as a cronjob or directly to clean out expired sessions (only with the database backend at the moment)."
  6
+
  7
+    def handle_noargs(self, **options):
  8
+        from django.db import transaction
  9
+        from django.contrib.sessions.models import Session
  10
+        Session.objects.filter(expire_date__lt=timezone.now()).delete()
  11
+        transaction.commit_unless_managed()
16  django/core/management/commands/cleanup.py
... ...
@@ -1,11 +1,11 @@
1  
-from django.core.management.base import NoArgsCommand
2  
-from django.utils import timezone
  1
+import warnings
3 2
 
4  
-class Command(NoArgsCommand):
5  
-    help = "Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment)."
  3
+from django.contrib.sessions.management.commands import clearsessions
6 4
 
  5
+
  6
+class Command(clearsessions.Command):
7 7
     def handle_noargs(self, **options):
8  
-        from django.db import transaction
9  
-        from django.contrib.sessions.models import Session
10  
-        Session.objects.filter(expire_date__lt=timezone.now()).delete()
11  
-        transaction.commit_unless_managed()
  8
+        warnings.warn(
  9
+            "The `cleanup` command has been deprecated in favor of `clearsessions`.",
  10
+            PendingDeprecationWarning)
  11
+        super(Command, self).handle_noargs(**options)
5  docs/internals/deprecation.txt
@@ -293,6 +293,11 @@ these changes.
293 293
 * The ``AUTH_PROFILE_MODULE`` setting, and the ``get_profile()`` method on
294 294
   the User model, will be removed.
295 295
 
  296
+* The ``cleanup`` management command will be removed. It's replaced by
  297
+  ``clearsessions``.
  298
+
  299
+* The ``daily_cleanup.py`` script will be removed.
  300
+
296 301
 2.0
297 302
 ---
298 303
 
15  docs/ref/django-admin.txt
@@ -96,6 +96,9 @@ cleanup
96 96
 Can be run as a cronjob or directly to clean out old data from the database
97 97
 (only expired sessions at the moment).
98 98
 
  99
+.. versionchanged:: 1.5
  100
+    :djadmin:`cleanup` is deprecated. Use :djadmin:`clearsessions` instead.
  101
+
99 102
 compilemessages
100 103
 ---------------
101 104
 
@@ -1187,6 +1190,18 @@ This command is only available if :doc:`GeoDjango </ref/contrib/gis/index>`
1187 1190
 Please refer to its :djadmin:`description <ogrinspect>` in the GeoDjango
1188 1191
 documentation.
1189 1192
 
  1193
+``django.contrib.sessions``
  1194
+---------------------------
  1195
+
  1196
+clearsessions
  1197
+~~~~~~~~~~~~~~~
  1198
+
  1199
+.. django-admin:: clearsessions
  1200
+
  1201
+Can be run as a cron job or directly to clean out expired sessions.
  1202
+
  1203
+This is only supported by the database backend at the moment.
  1204
+
1190 1205
 ``django.contrib.sitemaps``
1191 1206
 ---------------------------
1192 1207
 
13  docs/releases/1.5.txt
@@ -613,7 +613,6 @@ Define a ``__str__`` method and apply the
613 613
 The :func:`~django.utils.itercompat.product` function has been deprecated. Use
614 614
 the built-in :func:`itertools.product` instead.
615 615
 
616  
-
617 616
 ``django.utils.markup``
618 617
 ~~~~~~~~~~~~~~~~~~~~~~~
619 618
 
@@ -621,3 +620,15 @@ The markup contrib module has been deprecated and will follow an accelerated
621 620
 deprecation schedule. Direct use of python markup libraries or 3rd party tag
622 621
 libraries is preferred to Django maintaining this functionality in the
623 622
 framework.
  623
+
  624
+``cleanup`` management command
  625
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626
+
  627
+The :djadmin:`cleanup` management command has been deprecated and replaced by
  628
+:djadmin:`clearsessions`.
  629
+
  630
+``daily_cleanup.py`` script
  631
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
  632
+
  633
+The undocumented ``daily_cleanup.py`` script has been deprecated. Use the
  634
+:djadmin:`clearsessions` management command instead.
2  docs/topics/http/sessions.txt
@@ -460,7 +460,7 @@ table. Django updates this row each time the session data changes. If the user
460 460
 logs out manually, Django deletes the row. But if the user does *not* log out,
461 461
 the row never gets deleted.
462 462
 
463  
-Django provides a sample clean-up script: ``django-admin.py cleanup``.
  463
+Django provides a sample clean-up script: ``django-admin.py clearsessions``.
464 464
 That script deletes any session in the session table whose ``expire_date`` is
465 465
 in the past -- but your application may have different requirements.
466 466
 
0  sessions/management/__init__.py b/django/contrib/sessions/management/__init__.py
No changes.
0  sessions/management/commands/__init__.py b/django/contrib/sessions/management/commands/__init__.py
No changes.

0 notes on commit b760503

Please sign in to comment.
Something went wrong with that request. Please try again.