Mercurial > public > sg101
view gpp/forums/management/commands/forum_stats.py @ 235:d302c498560e
Fix problem when deleting multiple topics from a forum in bulk. We getting a list of topics from the database, then deleting each topic. But after you delete a topic, the forum.last_post on the remaining non-deleted topics can be stale. This was causing a weird DoesNotExist. Now just get the topics one at a time from the database.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Aug 2010 04:01:58 +0000 |
parents | f7a6b8fe4556 |
children |
line wrap: on
line source
""" forum_stats is a custom manage.py command for the forums application. It is intended to be called from a cron job to calculate various forum statistics. """ from django.core.management.base import NoArgsCommand from django.core.cache import cache from forums.models import Statistic import forums.middleware class Command(NoArgsCommand): help = "Run periodically to gather forum statistics." def handle_noargs(self, **options): # update maximum users online statistic users_online = cache.get(forums.middleware.USERS_ONLINE_KEY) if users_online: try: stats = Statistic.objects.get(pk=1) except Statistic.DoesNotExist: stats = Statistic(max_users=0) curr_users = len(users_online) if curr_users > stats.max_users: stats.max_users = curr_users stats.save()