annotate gpp/forums/management/commands/forum_stats.py @ 172:0fa78ef80356

Implementing #55 - Add function to view a users posts from their profile.
author Brian Neal <bgneal@gmail.com>
date Sun, 28 Feb 2010 22:20:15 +0000
parents f7a6b8fe4556
children
rev   line source
bgneal@164 1 """
bgneal@164 2 forum_stats is a custom manage.py command for the forums application.
bgneal@164 3 It is intended to be called from a cron job to calculate various forum
bgneal@164 4 statistics.
bgneal@164 5 """
bgneal@164 6 from django.core.management.base import NoArgsCommand
bgneal@164 7 from django.core.cache import cache
bgneal@164 8
bgneal@164 9 from forums.models import Statistic
bgneal@164 10 import forums.middleware
bgneal@164 11
bgneal@164 12
bgneal@164 13 class Command(NoArgsCommand):
bgneal@164 14 help = "Run periodically to gather forum statistics."
bgneal@164 15
bgneal@164 16 def handle_noargs(self, **options):
bgneal@164 17 # update maximum users online statistic
bgneal@164 18 users_online = cache.get(forums.middleware.USERS_ONLINE_KEY)
bgneal@164 19 if users_online:
bgneal@164 20 try:
bgneal@164 21 stats = Statistic.objects.get(pk=1)
bgneal@164 22 except Statistic.DoesNotExist:
bgneal@164 23 stats = Statistic(max_users=0)
bgneal@164 24
bgneal@164 25 curr_users = len(users_online)
bgneal@164 26
bgneal@164 27 if curr_users > stats.max_users:
bgneal@164 28 stats.max_users = curr_users
bgneal@164 29 stats.save()