changeset 362:c5ae0a276e33

Fixing #170; clean old user and anonymous last visit records.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 Mar 2011 03:43:32 +0000 (2011-03-05)
parents 6d6fdc58487c
children 9d470c7a2b93
files gpp/core/management/commands/clean_last_visit.py
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/core/management/commands/clean_last_visit.py	Sat Mar 05 03:43:32 2011 +0000
@@ -0,0 +1,27 @@
+"""
+clean_last_visit is a custom manage.py command.
+It is intended to be called from a cron job to clean out old user and anonymous
+last visit records.
+
+"""
+import datetime
+
+from django.core.management.base import NoArgsCommand
+
+from core.models import UserLastVisit, AnonLastVisit
+
+USER_LV_AGE = datetime.timedelta(weeks=4)
+ANON_LV_AGE = datetime.timedelta(days=1)
+
+
+class Command(NoArgsCommand):
+    help = "Run periodically to clean out old last visit records."
+
+    def handle_noargs(self, **options):
+
+        now = datetime.datetime.now()
+        user_cut_off = now - USER_LV_AGE
+        anon_cut_off = now - ANON_LV_AGE
+
+        UserLastVisit.objects.filter(last_visit__lte=user_cut_off).delete()
+        AnonLastVisit.objects.filter(last_visit__lte=anon_cut_off).delete()