comparison gpp/forums/management/commands/forum_stats.py @ 164:f7a6b8fe4556

Implement #46, add a forums stat feature like phpBB.
author Brian Neal <bgneal@gmail.com>
date Mon, 28 Dec 2009 16:52:42 +0000
parents
children
comparison
equal deleted inserted replaced
163:4f07047e0a40 164:f7a6b8fe4556
1 """
2 forum_stats is a custom manage.py command for the forums application.
3 It is intended to be called from a cron job to calculate various forum
4 statistics.
5 """
6 from django.core.management.base import NoArgsCommand
7 from django.core.cache import cache
8
9 from forums.models import Statistic
10 import forums.middleware
11
12
13 class Command(NoArgsCommand):
14 help = "Run periodically to gather forum statistics."
15
16 def handle_noargs(self, **options):
17 # update maximum users online statistic
18 users_online = cache.get(forums.middleware.USERS_ONLINE_KEY)
19 if users_online:
20 try:
21 stats = Statistic.objects.get(pk=1)
22 except Statistic.DoesNotExist:
23 stats = Statistic(max_users=0)
24
25 curr_users = len(users_online)
26
27 if curr_users > stats.max_users:
28 stats.max_users = curr_users
29 stats.save()