Design and implement the tech for displaying data as selectable widget
Data tabs are widget based so views can be customized
* Determine the widget architecture
* Create a sample widget
* Working widget shown on Dashboard
Blueprint information
- Status:
- Complete
- Approver:
- Chris Gregan
- Priority:
- Undefined
- Drafter:
- Chris Gregan
- Direction:
- Needs approval
- Assignee:
- Quality Dashboard
- Definition:
- Superseded
- Series goal:
- None
- Implementation:
- Unknown
- Milestone target:
- None
- Started by
- Completed by
- Chris Gregan
Related branches
Related bugs
Sprints
Whiteboard
Design Specifications
Requirements
=========
* Widget must be a pluggable architecture where new widgets can easily be created by injecting a different SQL query and setting a threshold.
* Widget should perform the threshold analysis
* Widget sends final data to HTML for display
Technology
=========
https:/
-------
https:/
from django.db import connections
cursor = connections[
# Your code here...
transaction.
def dictfetchall(
"Returns all rows from a cursor as a dict"
desc = cursor.description
return [
for row in cursor.fetchall()
]
-------
def my_custom_sql():
from django.db import connection, transaction
cursor = connection.cursor()
# Data modifying operation - commit required
cursor.
transaction
# Data retrieval operation - no commit required
cursor.
row = cursor.fetchone()
return row
-------
from itertools import *
from django.db import connection
def query_to_
"""Run a simple query and produce a generator
that returns the results as a bunch of dictionaries
with keys for the column values selected.
"""
cursor = connection.cursor()
cursor.
col_names = [desc[0] for desc in cursor.description]
while True:
row = cursor.fetchone()
if row is None:
break
row_dict = dict(izip(
yield row_dict
return
Limitations
=========
No checking is done on the SQL statement that is passed in to .raw(). Django expects that the statement will return a set of rows from the database, but does nothing to enforce that. If the query does not return rows, a (possibly cryptic) error will result.