Ticket #18978: 18978-1.diff

File 18978-1.diff, 4.4 KB (added by Tomáš Ehrlich, 12 years ago)

Cleansessions command and documentation

  • new file django/contrib/sessions/management/commands/cleansessions.py

    diff --git a/django/contrib/sessions/management/__init__.py b/django/contrib/sessions/management/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/sessions/management/commands/__init__.py b/django/contrib/sessions/management/commands/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/sessions/management/commands/cleansessions.py b/django/contrib/sessions/management/commands/cleansessions.py
    new file mode 100644
    index 0000000..f5783ba
    - +  
     1from django.core.management.base import NoArgsCommand
     2from django.utils import timezone
     3
     4
     5class Command(NoArgsCommand):
     6    help = "Clean expired sessions."
     7
     8    def handle_noargs(self, **options):
     9        from django.db import transaction
     10        from django.contrib.sessions.models import Session
     11        Session.objects.filter(expire_date__lt=timezone.now()).delete()
     12        transaction.commit_unless_managed()
  • django/core/management/commands/cleanup.py

    diff --git a/django/core/management/commands/cleanup.py b/django/core/management/commands/cleanup.py
    index e19d164..45f3bec 100644
    a b  
     1from django.core import management
    12from django.core.management.base import NoArgsCommand
    2 from django.utils import timezone
     3
    34
    45class Command(NoArgsCommand):
    56    help = "Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment)."
    67
    78    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()
     9        management.call_command('cleansessions', **options)
  • docs/ref/django-admin.txt

    diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
    index 7fa7539..ec8b74e 100644
    a b  
    11=============================
     2
     3
     4..
    25django-admin.py and manage.py
    36=============================
    47
    cleanup  
    9396
    9497.. django-admin:: cleanup
    9598
    96 Can be run as a cronjob or directly to clean out old data from the database
    97 (only expired sessions at the moment).
     99Can be run as a cronjob or directly to clean out old data from the database.
     100Right now it only calls :djadmin:`cleansessions` management command from
     101``django.contrib.sessions``.
     102
     103.. versionchanged:: 1.5
    98104
    99105compilemessages
    100106---------------
    This command is only available if the :doc:`Sitemaps framework  
    11991205Please refer to its :djadmin:`description <ping_google>` in the Sitemaps
    12001206documentation.
    12011207
     1208``django.contrib.sessions``
     1209---------------------------
     1210
     1211cleansessions
     1212~~~~~~~~~~~~~
     1213
     1214This command is only available if the :doc:`Sessions </topics/http/sessions>`
     1215(``django.contrib.sessions``) are installed.
     1216
     1217Please refer to its :djadmin:`description <cleansessions>` in the Sessions
     1218documentation.
     1219
     1220.. versionadded:: 1.5
     1221
    12021222``django.contrib.staticfiles``
    12031223------------------------------
    12041224
  • docs/releases/1.5.txt

    diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt
    index 11b3488..f5d5862 100644
    a b a User account, this will be an appropriate design pattern to follow. However,  
    486486the :setting:`AUTH_PROFILE_MODULE` setting, and the
    487487:meth:`~django.contrib.auth.models.User.get_profile()` method for accessing
    488488the user profile model, should not be used any longer.
     489
     490Cleaned :djadmin:`cleanup` management command
     491~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     492
     493This command have contained only expired sessions clean up for years.
     494Therefore new command :djadmin:`cleansessions` in ``django.contrib.sessions``
     495do the job and :djadmin:`cleanup` command just call it.
  • docs/topics/http/sessions.txt

    diff --git a/docs/topics/http/sessions.txt b/docs/topics/http/sessions.txt
    index 1f55293..ad9bbd6 100644
    a b that is, if any of its dictionary values have been assigned or deleted.  
    573573
    574574.. _Django settings: ../settings/
    575575
     576Management commands
     577===================
     578
     579.. highlight:: console
     580
     581``django.contrib.sessions`` exposes one management commands.
     582
     583cleansessions
     584-------------
     585
     586.. django-admin:: cleansessions
     587
     588Cleans expired sessions from database.
     589
     590.. versionadded:: 1.5
     591
    576592Technical details
    577593=================
    578594
Back to Top