annotate gpp/core/management/commands/clean_last_visit.py @ 408:7e0997b08b50

Fixes for #200; fix bug in deciding which forums have unread posts.
author Brian Neal <bgneal@gmail.com>
date Sat, 02 Apr 2011 00:12:40 +0000
parents c5ae0a276e33
children
rev   line source
bgneal@362 1 """
bgneal@362 2 clean_last_visit is a custom manage.py command.
bgneal@362 3 It is intended to be called from a cron job to clean out old user and anonymous
bgneal@362 4 last visit records.
bgneal@362 5
bgneal@362 6 """
bgneal@362 7 import datetime
bgneal@362 8
bgneal@362 9 from django.core.management.base import NoArgsCommand
bgneal@362 10
bgneal@362 11 from core.models import UserLastVisit, AnonLastVisit
bgneal@362 12
bgneal@362 13 USER_LV_AGE = datetime.timedelta(weeks=4)
bgneal@362 14 ANON_LV_AGE = datetime.timedelta(days=1)
bgneal@362 15
bgneal@362 16
bgneal@362 17 class Command(NoArgsCommand):
bgneal@362 18 help = "Run periodically to clean out old last visit records."
bgneal@362 19
bgneal@362 20 def handle_noargs(self, **options):
bgneal@362 21
bgneal@362 22 now = datetime.datetime.now()
bgneal@362 23 user_cut_off = now - USER_LV_AGE
bgneal@362 24 anon_cut_off = now - ANON_LV_AGE
bgneal@362 25
bgneal@362 26 UserLastVisit.objects.filter(last_visit__lte=user_cut_off).delete()
bgneal@362 27 AnonLastVisit.objects.filter(last_visit__lte=anon_cut_off).delete()