bgneal@164: """ bgneal@164: forum_stats is a custom manage.py command for the forums application. bgneal@164: It is intended to be called from a cron job to calculate various forum bgneal@164: statistics. bgneal@164: """ bgneal@164: from django.core.management.base import NoArgsCommand bgneal@164: from django.core.cache import cache bgneal@164: bgneal@164: from forums.models import Statistic bgneal@164: import forums.middleware bgneal@164: bgneal@164: bgneal@164: class Command(NoArgsCommand): bgneal@164: help = "Run periodically to gather forum statistics." bgneal@164: bgneal@164: def handle_noargs(self, **options): bgneal@164: # update maximum users online statistic bgneal@164: users_online = cache.get(forums.middleware.USERS_ONLINE_KEY) bgneal@164: if users_online: bgneal@164: try: bgneal@164: stats = Statistic.objects.get(pk=1) bgneal@164: except Statistic.DoesNotExist: bgneal@164: stats = Statistic(max_users=0) bgneal@164: bgneal@164: curr_users = len(users_online) bgneal@164: bgneal@164: if curr_users > stats.max_users: bgneal@164: stats.max_users = curr_users bgneal@164: stats.save()