comparison gpp/forums/management/commands/forum_cleanup.py @ 307:7e19180b128d

Fixing #97; adding a management command to remove old forum and topic last visit records.
author Brian Neal <bgneal@gmail.com>
date Sun, 16 Jan 2011 20:18:26 +0000
parents
children
comparison
equal deleted inserted replaced
306:6ca2c474d92f 307:7e19180b128d
1 """
2 forum_cleanup.py - A management command to cleanup forum model objects. Right
3 now this entails deleting old forum and topic last visit records.
4
5 """
6 import datetime
7
8 from django.core.management.base import NoArgsCommand, CommandError
9
10 from forums.models import ForumLastVisit, TopicLastVisit
11 import forums.unread
12
13
14 class Command(NoArgsCommand):
15 help = "This command deletes old forum and topic last visit records."
16
17 def handle_noargs(self, **opts):
18
19 now = datetime.datetime.now()
20 threshold = now - forums.unread.THRESHOLD * 2
21
22 # delete old topic last visit records
23 TopicLastVisit.objects.filter(last_visit__lt=threshold).delete()
24
25 # delete old forum visit records
26 ForumLastVisit.objects.filter(end_date__lt=threshold).delete()