bgneal@362: """ bgneal@362: clean_last_visit is a custom manage.py command. bgneal@362: It is intended to be called from a cron job to clean out old user and anonymous bgneal@362: last visit records. bgneal@362: bgneal@362: """ bgneal@362: import datetime bgneal@362: bgneal@362: from django.core.management.base import NoArgsCommand bgneal@362: bgneal@362: from core.models import UserLastVisit, AnonLastVisit bgneal@362: bgneal@362: USER_LV_AGE = datetime.timedelta(weeks=4) bgneal@362: ANON_LV_AGE = datetime.timedelta(days=1) bgneal@362: bgneal@362: bgneal@362: class Command(NoArgsCommand): bgneal@362: help = "Run periodically to clean out old last visit records." bgneal@362: bgneal@362: def handle_noargs(self, **options): bgneal@362: bgneal@362: now = datetime.datetime.now() bgneal@362: user_cut_off = now - USER_LV_AGE bgneal@362: anon_cut_off = now - ANON_LV_AGE bgneal@362: bgneal@362: UserLastVisit.objects.filter(last_visit__lte=user_cut_off).delete() bgneal@362: AnonLastVisit.objects.filter(last_visit__lte=anon_cut_off).delete()