mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Extract make_table() in analytics/views.py.
(imported from commit f1457763ac491d32de19221fb9a2d11e43d58106)
This commit is contained in:
@@ -11,6 +11,16 @@ import datetime
|
|||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
def make_table(title, cols, rows):
|
||||||
|
data = dict(title=title, cols=cols, rows=rows)
|
||||||
|
|
||||||
|
content = loader.render_to_string(
|
||||||
|
'analytics/ad_hoc_query.html',
|
||||||
|
dict(data=data)
|
||||||
|
)
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
def dictfetchall(cursor):
|
def dictfetchall(cursor):
|
||||||
"Returns all rows from a cursor as a dict"
|
"Returns all rows from a cursor as a dict"
|
||||||
desc = cursor.description
|
desc = cursor.description
|
||||||
@@ -227,18 +237,7 @@ def sent_messages_report(realm):
|
|||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
data = dict(
|
return make_table(title, cols, rows)
|
||||||
rows=rows,
|
|
||||||
cols=cols,
|
|
||||||
title=title
|
|
||||||
)
|
|
||||||
|
|
||||||
content = loader.render_to_string(
|
|
||||||
'analytics/ad_hoc_query.html',
|
|
||||||
dict(data=data)
|
|
||||||
)
|
|
||||||
|
|
||||||
return content
|
|
||||||
|
|
||||||
def ad_hoc_queries():
|
def ad_hoc_queries():
|
||||||
def get_page(query, cols, title):
|
def get_page(query, cols, title):
|
||||||
@@ -247,16 +246,7 @@ def ad_hoc_queries():
|
|||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
data = dict(
|
content = make_table(title, cols, rows)
|
||||||
rows=rows,
|
|
||||||
cols=cols,
|
|
||||||
title=title
|
|
||||||
)
|
|
||||||
|
|
||||||
content = loader.render_to_string(
|
|
||||||
'analytics/ad_hoc_query.html',
|
|
||||||
dict(data=data)
|
|
||||||
)
|
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
content=content,
|
content=content,
|
||||||
@@ -549,20 +539,8 @@ def raw_user_activity_table(records):
|
|||||||
]
|
]
|
||||||
|
|
||||||
rows = map(row, records)
|
rows = map(row, records)
|
||||||
|
|
||||||
title = 'Raw Data'
|
title = 'Raw Data'
|
||||||
|
return make_table(title, cols, rows)
|
||||||
data = dict(
|
|
||||||
rows=rows,
|
|
||||||
cols=cols,
|
|
||||||
title=title
|
|
||||||
)
|
|
||||||
|
|
||||||
content = loader.render_to_string(
|
|
||||||
'analytics/ad_hoc_query.html',
|
|
||||||
dict(data=data)
|
|
||||||
)
|
|
||||||
return content
|
|
||||||
|
|
||||||
def get_user_activity_summary(records):
|
def get_user_activity_summary(records):
|
||||||
summary = {}
|
summary = {}
|
||||||
@@ -650,17 +628,7 @@ def realm_client_table(user_summaries):
|
|||||||
|
|
||||||
title = 'Clients'
|
title = 'Clients'
|
||||||
|
|
||||||
data = dict(
|
return make_table(title, cols, rows)
|
||||||
rows=rows,
|
|
||||||
cols=cols,
|
|
||||||
title=title
|
|
||||||
)
|
|
||||||
|
|
||||||
content = loader.render_to_string(
|
|
||||||
'analytics/ad_hoc_query.html',
|
|
||||||
dict(data=data)
|
|
||||||
)
|
|
||||||
return content
|
|
||||||
|
|
||||||
def user_activity_summary_table(user_summary):
|
def user_activity_summary_table(user_summary):
|
||||||
rows = []
|
rows = []
|
||||||
@@ -686,18 +654,7 @@ def user_activity_summary_table(user_summary):
|
|||||||
]
|
]
|
||||||
|
|
||||||
title = 'User Activity'
|
title = 'User Activity'
|
||||||
|
return make_table(title, cols, rows)
|
||||||
data = dict(
|
|
||||||
rows=rows,
|
|
||||||
cols=cols,
|
|
||||||
title=title
|
|
||||||
)
|
|
||||||
|
|
||||||
content = loader.render_to_string(
|
|
||||||
'analytics/ad_hoc_query.html',
|
|
||||||
dict(data=data)
|
|
||||||
)
|
|
||||||
return content
|
|
||||||
|
|
||||||
def realm_user_summary_table(all_records):
|
def realm_user_summary_table(all_records):
|
||||||
user_records = {}
|
user_records = {}
|
||||||
@@ -750,17 +707,7 @@ def realm_user_summary_table(all_records):
|
|||||||
|
|
||||||
title = 'Summary'
|
title = 'Summary'
|
||||||
|
|
||||||
data = dict(
|
content = make_table(title, cols, rows)
|
||||||
rows=rows,
|
|
||||||
cols=cols,
|
|
||||||
title=title
|
|
||||||
)
|
|
||||||
|
|
||||||
content = loader.render_to_string(
|
|
||||||
'analytics/ad_hoc_query.html',
|
|
||||||
dict(data=data)
|
|
||||||
)
|
|
||||||
|
|
||||||
return user_records, content
|
return user_records, content
|
||||||
|
|
||||||
@zulip_internal
|
@zulip_internal
|
||||||
|
|||||||
Reference in New Issue
Block a user