Mercurial > public > sg101
diff forums/management/commands/forum_cleanup.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/forums/management/commands/forum_cleanup.py@7e19180b128d |
children | f3fded5df64b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/forums/management/commands/forum_cleanup.py Sat May 05 17:10:48 2012 -0500 @@ -0,0 +1,26 @@ +""" +forum_cleanup.py - A management command to cleanup forum model objects. Right +now this entails deleting old forum and topic last visit records. + +""" +import datetime + +from django.core.management.base import NoArgsCommand, CommandError + +from forums.models import ForumLastVisit, TopicLastVisit +import forums.unread + + +class Command(NoArgsCommand): + help = "This command deletes old forum and topic last visit records." + + def handle_noargs(self, **opts): + + now = datetime.datetime.now() + threshold = now - forums.unread.THRESHOLD * 2 + + # delete old topic last visit records + TopicLastVisit.objects.filter(last_visit__lt=threshold).delete() + + # delete old forum visit records + ForumLastVisit.objects.filter(end_date__lt=threshold).delete()