Commit 02e30f50 by John Hess

Cleaned up admin_dashboard code and template

parent 2f5e1b9c
...@@ -24,7 +24,6 @@ def SQL_query_to_list(cursor, query_string): ...@@ -24,7 +24,6 @@ def SQL_query_to_list(cursor, query_string):
print raw_result print raw_result
return raw_result return raw_result
def dashboard(request): def dashboard(request):
""" """
Slightly less hackish hack to show staff enrollment numbers and other Slightly less hackish hack to show staff enrollment numbers and other
...@@ -58,8 +57,20 @@ def dashboard(request): ...@@ -58,8 +57,20 @@ def dashboard(request):
# table queries need not take the form of raw SQL, but do in this case since # table queries need not take the form of raw SQL, but do in this case since
# the MySQL backend for django isn't very friendly with group by or distinct # the MySQL backend for django isn't very friendly with group by or distinct
table_queries = {} table_queries = {}
table_queries["course enrollments"]="select count(user_id) as students, course_id from student_courseenrollment group by course_id order by students desc;" table_queries["course enrollments"]= \
table_queries["number of students in each number of classes"]="select registrations, count(registrations) from (select count(user_id) as registrations from student_courseenrollment group by user_id) as registrations_per_user group by registrations;" "select "+ \
"course_id as Course, "+ \
"count(user_id) as Students " + \
"from student_courseenrollment "+ \
"group by course_id "+ \
"order by students desc;"
table_queries["number of students in each number of classes"]= \
"select registrations as 'Registered for __ Classes' , "+ \
"count(registrations) as Users "+ \
"from (select count(user_id) as registrations "+ \
"from student_courseenrollment "+ \
"group by user_id) as registrations_per_user "+ \
"group by registrations;"
# add the result for each of the table_queries to the results object # add the result for each of the table_queries to the results object
for query in table_queries.keys(): for query in table_queries.keys():
......
...@@ -23,7 +23,12 @@ ...@@ -23,7 +23,12 @@
<div class="table_display"> <div class="table_display">
<h2>${table}</h2> <h2>${table}</h2>
<table style="margin-left:auto;margin-right:auto;width:50%"> <table style="margin-left:auto;margin-right:auto;width:50%">
% for row in results["tables"][table]: <tr>
% for column in results["tables"][table][0]:
<td><b>${column}</b></td>
% endfor
</tr>
% for row in results["tables"][table][1:]:
<tr> <tr>
% for column in row: % for column in row:
<td>${column}</td> <td>${column}</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment