-
Notifications
You must be signed in to change notification settings - Fork 26
Reporting with SQLAlchemy
Werner Bruhin edited this page Jun 5, 2013
·
1 revision
Not using the Dabo Framework but still wanting to use the reporting tools and feeding data to it from SQLAlchemy.
result = session.query(db.Cellarbook.currentvalue,
db.Drinkinfo.name,
db.Vintage.vintage,
db.Vintage.notes)
result = result.join(db.Drinkinfo)
result = result.join(db.Vintage)
repFile = r'C:\dev\twcbv4\twcbsrc\reports\reportdefs\daboTest.rfxml'
outFile = r'C:\dev\twcbv4\data\generatedReports\daboTest.pdf'
from dabo.lib.reportWriter import ReportWriter
from dabo.lib import reportUtils
print "Instantiating the report writer..."
rw = ReportWriter()
# Set some required properties:
rw.ReportFormFile = repFile
rw.OutputFile = outFile
rw.Cursor = result.all()
print "Writing %s..." % outFile
rw.write()
As you can see from the above it is quit simple to do.
- Create a report definition using the Dabo ReportDesigner
- With Dabo you would use
self.Record['columnName'], with SA you need to doself.Record.__dict__['columnName'] - Save the report definition
- Create a SQLAlchemy session
- Create the query to get the columns you need for the report
- "rw.Cursor = result.all()" hands the data over to the report writer
- You got a PDF!