Refactor activity data-gathering a bit

(imported from commit 6d36bf19c5ba70cc4d29bf7340e4c6a7349f1083)
This commit is contained in:
Zev Benjamin 2013-04-02 11:15:09 -04:00
parent fa20696230
commit 99f98f77b6
1 changed files with 16 additions and 12 deletions

View File

@ -1182,19 +1182,23 @@ class ActivityTable(object):
self.default_tab = default_tab self.default_tab = default_tab
self.has_pointer = False self.has_pointer = False
self.rows = {} self.rows = {}
for url, query_name in queries:
if 'pointer' in query_name: def do_url(query_name, url):
self.has_pointer = True
for record in UserActivity.objects.filter( for record in UserActivity.objects.filter(
query=url, query=url,
client__name__startswith=client_name).select_related(): client__name__startswith=client_name).select_related():
row = self.rows.setdefault(record.user_profile.email, {}) row = self.rows.setdefault(record.user_profile.email,
row['realm'] = record.user_profile.realm.domain {'realm': record.user_profile.realm.domain,
row['full_name'] = record.user_profile.full_name 'full_name': record.user_profile.full_name,
row['email'] = record.user_profile.email 'email': record.user_profile.email})
row[query_name + '_count'] = record.count row[query_name + '_count'] = record.count
row[query_name + '_last' ] = record.last_visit row[query_name + '_last' ] = record.last_visit
for query_name, url in queries:
if 'pointer' in query_name:
self.has_pointer = True
do_url(query_name, url)
for row in self.rows.values(): for row in self.rows.values():
# kind of a hack # kind of a hack
last_action = max(v for v in row.values() if isinstance(v, datetime.datetime)) last_action = max(v for v in row.values() if isinstance(v, datetime.datetime))
@ -1217,14 +1221,14 @@ def get_activity(request):
return HttpResponseRedirect(reverse('zephyr.views.login_page')) return HttpResponseRedirect(reverse('zephyr.views.login_page'))
web_queries = ( web_queries = (
("/json/get_updates", "get_updates"), ("get_updates", "/json/get_updates"),
("/json/send_message", "send_message"), ("send_message", "/json/send_message"),
("/json/update_pointer", "update_pointer"), ("update_pointer", "/json/update_pointer"),
) )
api_queries = ( api_queries = (
("/api/v1/get_messages", "get_updates"), ("get_updates", "/api/v1/get_messages"),
("/api/v1/send_message", "send_message"), ("send_message", "/api/v1/send_message"),
) )
return render_to_response('zephyr/activity.html', return render_to_response('zephyr/activity.html',