A simple to use Django package to turn your sql query into a beautiful reporting html table
Project description
django-query-to-table is an easy to use django package to generate html table from sql query.
You can read more about this package here : django query to table
The package contains one function named "generateFromSql" accepting 12 arguments :
- cursor : DB cursor
- title : The title of the report that will be shown on top of table
- sqltext : The sql select query to retrieve data
- footerCols : A list of columns name that you want to have Sum of values on footer . Example : ['amount','price']
- htmlClass : Html CSS classes for the table
- direction (default = "ltr") : Indicates direction of the report page. "ltr"- Left to Right , "rtl" - Right to Left
- font (default = "Tahoma") : Font of title and table contents
- totalText (default = "Total") : Title of footer row that will be the put below the first column.
- rowIndex (default = False) : Indicates whether the table should have index column or not.
- headerRowColor (default = '#eeeeee') : The header (title) row background color.
- evenRowColor (default = '#ffffff') : The even rows background color.
- oddRowColor (default = '#ffffff') : The odd rows background color.
Installation
To install django-query-to-table using pip :
pip install django-query-to-table
Usage :
from django.db import connection
from django_query_to_table import DjangoQtt
from django.http import HttpResponse
# view function in Django project
def listOfPersons(request):
cursor = connection.cursor()
reportTitle = "Employee List"
sqlQuery = "SELECT FirstName as 'First Name', LastName as 'Last Name', phone as 'Phone Number', salary as 'Salary' FROM persons"
columnsToBeSummarized = ['Salary']
fontName = "Arial"
cssClasses = "reportTable container"
headerRowBackgroundColor = '#ffeeee'
evenRowsBackgroundColor = '#ffeeff'
oddRowsBackgroundColor = '#ffffff'
table = DjangoQtt.generateFromSql(cursor, reportTitle, sqlQuery, columnsToBeSummarized, cssClasses,
"ltr", fontName, "Total Salary", True,
headerRowBackgroundColor, evenRowsBackgroundColor, oddRowsBackgroundColor
)
# table is a string variable contianing the html table showing the query result
return HttpResponse(table)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-query-to-table-0.1.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dee857ca62bf210a0db14c079cd00b50d0592fe4a81353dcd309031dd6f687fc |
|
MD5 | 9d3a2f899f5c2e3d665a74f9193e1276 |
|
BLAKE2b-256 | e2c11638838be4c31de13dbb185e89ea8c8d28a9eea9fc4b2aa3126da2ca03b4 |
Close
Hashes for django_query_to_table-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 649227cc9831fe66e06c6008f3f4f3afb0cfeaa8cd3bb02d7f238a8d51fe9c01 |
|
MD5 | 0b3063a97d8f1a34e729cb8f45d198f8 |
|
BLAKE2b-256 | 5d145769181f113abef6457d6f7045d3507b6cb7aeda1b57b2c55d5879597ad9 |