Mercurial > public > sg101
comparison gpp/forums/stats.py @ 520:e94570675664
Created stats for users (number of users and list of newest users).
Better separated the forums, who's online, and user stats.
Use a Celery task to execute the new user stats processing.
This addresses #194 and #238.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 17 Dec 2011 23:19:15 +0000 |
parents | e10fa0d8e7ad |
children |
comparison
equal
deleted
inserted
replaced
519:f72ace06658a | 520:e94570675664 |
---|---|
1 """ | 1 """ |
2 This module is responsible for managing various forum statistics. | 2 This module is responsible for managing various forum statistics. |
3 | 3 |
4 """ | 4 """ |
5 from django.core.cache import cache | 5 from django.core.cache import cache |
6 from django.contrib.auth.models import User | |
7 | 6 |
8 from forums.models import Post | 7 from forums.models import Post |
9 | 8 |
10 | 9 |
11 CACHE_KEY = 'forums-stats' | 10 CACHE_KEY = 'forums-stats-2' |
12 CACHE_TIMEOUT = 4 * 60 * 60 # seconds | 11 CACHE_TIMEOUT = 4 * 60 * 60 # seconds |
13 | 12 |
14 | 13 |
15 def calc_stats(): | 14 def calc_stats(): |
16 """ | 15 """ |
17 This function is responsible for computing the forum statistics. | 16 This function is responsible for computing the forum statistics. |
18 A tuple is returned: (forums post count, active user count, latest username) | 17 The forums post count is returned. |
19 | 18 |
20 """ | 19 """ |
21 post_count = Post.objects.all().count() | 20 post_count = Post.objects.all().count() |
22 user_count = User.objects.all().count() | 21 return post_count |
23 | |
24 if user_count > 0: | |
25 latest_user = User.objects.filter(is_active=True).values_list( | |
26 'username', flat=True).order_by('-date_joined')[0] | |
27 else: | |
28 latest_user = None | |
29 | |
30 return post_count, user_count, latest_user | |
31 | 22 |
32 | 23 |
33 def update_stats(): | 24 def update_stats(): |
34 """ | 25 """ |
35 This function is responsible for computing the forum statistics and | 26 This function is responsible for computing the forum statistics and |