utilities to inspect Sqlalchemy models
Bases: dict
A registry used to store sqla columns <-> formatters association
Excel exportation module
Bases: sqla_inspect.excel.XlsWriter, sqla_inspect.export.SqlaExporter
Main class used for exporting datas to the xls format
Models attributes output can be customized through the info param :
- Column(Integer, infos={‘export’:
- {‘excel’:<excel_specific_options>,
- <main_export_options>
}
}
main_export_options and excel_specific_options can be :
label
label of the column headerformat
a function that will be fired on each row to format the outputrelated_key
If the attribute is a relationship, the value of the given attribute of the related object will be used to fill the cellsexclude
This data will not be inserted in the export if True
Usage:
a = SqlaXlsExporter(MyModel) for i in MyModel.query().filter(<myfilter>):
a.add_row(i)a.render()
Bases: sqla_inspect.excel.XlsWriter, sqla_inspect.export.BaseExporter
A main xls exportation tool (without sqlalchemy support)
writer = MyXlsExporter() writer.add_row({‘key’: u’La valeur de la cellule de la colonne 1’}) writer.render()
Bases: object
Class providing common tools to write excel files from tabular datas
Has to be subclassed, the subclass should provide a _datas and a headers attribute that contains the datas to render and the headers
_datas
list of tuples (each tuple is a row)headers
- list of dict containing the label of each column:
- {‘label’: <a label>}
The render method expects rows as lists, here we switch our row format from dict to list respecting the order of the headers
Definitely render the workbook
Parameters: | f_buf (obj) – A file buffer supporting the write and seek |
---|
methods
Return a file buffer containing the resulting xls
Parameters: | f_buf (obj) – A file buffer supporting the write and seek |
---|
methods
Set the given color to the provided cell
cell
A xls cell objectcolor
A openpyxl color var
Base export class
A base exportation object, used to export tabular datas (csv or xls format) Should be used in conjunction with a writer
Bases: sqla_inspect.export.BaseExporter, sqla_inspect.base.BaseSqlaInspector
Sqla exportation class Allow to stream datas to be exported
config_key
The key in the export subdict in the sqlalchemy Column’s info dict that is used to configure this export e.g : set config_key = “csv” if your column configuration looks like the following
Column(Integer, info={'export' : {'csv': {<config>}}, <main_export_config> }Note
By default, we look for the title in the colanderalchemy’s title key info={‘colanderalchemy’: {‘title’: u’Column title’}}