app/django/bin/daily_cleanup.py
changeset 54 03e267d67478
child 323 ff1a9aa48cfd
equal deleted inserted replaced
53:57b4279d8c4e 54:03e267d67478
       
     1 #!/usr/bin/env python
       
     2 
       
     3 """
       
     4 Daily cleanup job.
       
     5 
       
     6 Can be run as a cronjob to clean out old data from the database (only expired
       
     7 sessions at the moment).
       
     8 """
       
     9 
       
    10 import datetime
       
    11 from django.db import transaction
       
    12 from django.contrib.sessions.models import Session
       
    13 
       
    14 def clean_up():
       
    15     """Clean up expired sessions."""
       
    16     Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
       
    17     transaction.commit_unless_managed()
       
    18 
       
    19 if __name__ == "__main__":
       
    20     clean_up()