Mercurial > public > sg101
annotate gpp/forums/management/commands/forum_cleanup.py @ 374:dd673fae508d
Fixing #156. Making it possible to goto the first unread post in a thread. Made the 'New' icon a link; when displayed on a topic, takes you to the first unread post.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 07 Mar 2011 01:22:49 +0000 |
parents | 7e19180b128d |
children |
rev | line source |
---|---|
bgneal@307 | 1 """ |
bgneal@307 | 2 forum_cleanup.py - A management command to cleanup forum model objects. Right |
bgneal@307 | 3 now this entails deleting old forum and topic last visit records. |
bgneal@307 | 4 |
bgneal@307 | 5 """ |
bgneal@307 | 6 import datetime |
bgneal@307 | 7 |
bgneal@307 | 8 from django.core.management.base import NoArgsCommand, CommandError |
bgneal@307 | 9 |
bgneal@307 | 10 from forums.models import ForumLastVisit, TopicLastVisit |
bgneal@307 | 11 import forums.unread |
bgneal@307 | 12 |
bgneal@307 | 13 |
bgneal@307 | 14 class Command(NoArgsCommand): |
bgneal@307 | 15 help = "This command deletes old forum and topic last visit records." |
bgneal@307 | 16 |
bgneal@307 | 17 def handle_noargs(self, **opts): |
bgneal@307 | 18 |
bgneal@307 | 19 now = datetime.datetime.now() |
bgneal@307 | 20 threshold = now - forums.unread.THRESHOLD * 2 |
bgneal@307 | 21 |
bgneal@307 | 22 # delete old topic last visit records |
bgneal@307 | 23 TopicLastVisit.objects.filter(last_visit__lt=threshold).delete() |
bgneal@307 | 24 |
bgneal@307 | 25 # delete old forum visit records |
bgneal@307 | 26 ForumLastVisit.objects.filter(end_date__lt=threshold).delete() |