Mercurial > public > sg101
comparison gpp/core/management/commands/clean_last_visit.py @ 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 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
361:6d6fdc58487c | 362:c5ae0a276e33 |
---|---|
1 """ | |
2 clean_last_visit is a custom manage.py command. | |
3 It is intended to be called from a cron job to clean out old user and anonymous | |
4 last visit records. | |
5 | |
6 """ | |
7 import datetime | |
8 | |
9 from django.core.management.base import NoArgsCommand | |
10 | |
11 from core.models import UserLastVisit, AnonLastVisit | |
12 | |
13 USER_LV_AGE = datetime.timedelta(weeks=4) | |
14 ANON_LV_AGE = datetime.timedelta(days=1) | |
15 | |
16 | |
17 class Command(NoArgsCommand): | |
18 help = "Run periodically to clean out old last visit records." | |
19 | |
20 def handle_noargs(self, **options): | |
21 | |
22 now = datetime.datetime.now() | |
23 user_cut_off = now - USER_LV_AGE | |
24 anon_cut_off = now - ANON_LV_AGE | |
25 | |
26 UserLastVisit.objects.filter(last_visit__lte=user_cut_off).delete() | |
27 AnonLastVisit.objects.filter(last_visit__lte=anon_cut_off).delete() |