view gpp/core/management/commands/clean_last_visit.py @ 390:e0523e17ea43

Fixing #175; add an auto-subscribe and auto-favorite forum topic feature. Added 2 flags to the user profile. Added 2 functions that are called on the post post-save signal that auto-favorite and auto-subscribe the post creator if they have requested this service.
author Brian Neal <bgneal@gmail.com>
date Mon, 21 Mar 2011 00:39:52 +0000
parents c5ae0a276e33
children
line wrap: on
line source
"""
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()