Design and implement the tech for displaying data as selectable widget

Registered by Chris Gregan

This blueprint has been superseded. See the newer blueprint "Quality Dashboard backend server tech spec" for updated plans.

 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
Completed by
Chris Gregan

Related branches

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://docs.djangoproject.com/en/dev/topics/db/queries/
---------------------
https://docs.djangoproject.com/en/dev/topics/db/sql/

from django.db import connections
cursor = connections['my_db_alias'].cursor()
# Your code here...
transaction.commit_unless_managed(using='my_db_alias')

def dictfetchall(cursor):
    "Returns all rows from a cursor as a dict"
    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
    ]

--------------------

def my_custom_sql():
    from django.db import connection, transaction
    cursor = connection.cursor()

    # Data modifying operation - commit required
    cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])
    transaction.commit_unless_managed()

    # Data retrieval operation - no commit required
    cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz])
    row = cursor.fetchone()

    return row

----------------------

from itertools import *
from django.db import connection

def query_to_dicts(query_string, *query_args):
    """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.execute(query_string, query_args)
    col_names = [desc[0] for desc in cursor.description]
    while True:
        row = cursor.fetchone()
        if row is None:
            break
        row_dict = dict(izip(col_names, row))
        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.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.