Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
94db91fc
Commit
94db91fc
authored
Mar 04, 2013
by
John Hess
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cast cursor responses as lists. MySQL returns them as tuples.
Removed print statemetns Moved import call to top of file
parent
02e30f50
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
lms/djangoapps/dashboard/views.py
+7
-5
No files found.
lms/djangoapps/dashboard/views.py
View file @
94db91fc
...
...
@@ -3,6 +3,7 @@ import json
from
datetime
import
datetime
from
django.http
import
Http404
from
mitxmako.shortcuts
import
render_to_response
from
django.db
import
connection
from
student.models
import
CourseEnrollment
,
CourseEnrollmentAllowed
from
django.contrib.auth.models
import
User
...
...
@@ -12,16 +13,18 @@ def dictfetchall(cursor):
'''Returns a list of all rows from a cursor as a column: result dict.
Borrowed from Django documentation'''
desc
=
cursor
.
description
table
=
[]
table
=
[]
table
.
append
([
col
[
0
]
for
col
in
desc
])
table
=
table
+
cursor
.
fetchall
()
print
"Table: "
+
str
(
table
)
# ensure response from db is a list, not a tuple (which is returned
# by MySQL backed django instances)
rows_from_cursor
=
cursor
.
fetchall
()
table
=
table
+
[
list
(
row
)
for
row
in
rows_from_cursor
]
return
table
def
SQL_query_to_list
(
cursor
,
query_string
):
cursor
.
execute
(
query_string
)
raw_result
=
dictfetchall
(
cursor
)
print
raw_result
return
raw_result
def
dashboard
(
request
):
...
...
@@ -50,7 +53,6 @@ def dashboard(request):
results
[
"scalars"
][
"Total Enrollments Across All Courses"
]
=
CourseEnrollment
.
objects
.
count
()
# establish a direct connection to the database (for executing raw SQL)
from
django.db
import
connection
cursor
=
connection
.
cursor
()
# define the queries that will generate our user-facing tables
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment