Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database Reporting Services in Django or Python

I am wondering if there are any django based, or even Python Based Reporting Services ala JasperReports or SQL Server Reporting Services?

Basically, I would love to be able to create reports, send them out as emails as CSV or HTML or PDF without having to code the reports. Even if I have to code the report I wouldn't mind, but the whole framework with schedules and so on would be nice!

PS. I know I could use Django Apps to do it, but I was hoping if there was any integrated solutions or even projects such as Pinax or Satchmo which brings together the apps needed.

PPS: It would have to work off Postgres

like image 317
Mark Ellul Avatar asked Apr 27 '09 11:04

Mark Ellul


People also ask

Which database is best for Django?

MySQL and PostgreSQL work best with Django.

Does Django have a database?

Django comes with built-in database backends. You may subclass an existing database backends to modify its behavior, features, or configuration. You can see the current list of database engines by looking in django/db/backends.

Can I use SQL server with Django?

Django has a built-in web server that is used for development purposes. The framework supports several database management systems including Microsoft SQL Server.

How does Django interact with database?

By default, Django works with SQLite, database and allows configuring for other databases as well. Database connectivity requires all the connection details such as database name, user credentials, hostname drive name etc. To connect with MySQL, django. db.


2 Answers

"I would love to be able to create reports ... without having to code the reports"

So would I. Sadly, however, each report seems to be unique and require custom code.

From Django model to CSV is easy. Start there with a few of your reports.

import csv
from myApp.models import This, That, TheOther
def parseCommandLine():
    # setup optparse to get report query parameters
def main():
    wtr= csv.DictWriter( sys.stdout, ["Col1", "Col2", "Col3"] )
    this, that = parseCommandLine()
    thisList= This.objects.filter( name=this, that__name=that )
    for object in thisList:
        write.writerow( object.col1, object.that.col2, object.theOther.col3 )
if __name__ == "__main__":
    main()

HTML is pretty easy -- Django has an HTML template language. Rather than render_to_response, you simply render your template and write it to stdout. And the core of the algorithm, interestingly, is very similar to writing a CSV. Similar enough that -- without much cleverness -- you should have a design pattern that does both.

Once you have the CSV working, add the HTML using Django's templates.

PDF's are harder, because you have to actually work out the formatting in some detail. There are a lot of Python libraries for this. Interestingly, however, the overall pattern for PDF writing is very similar to CSV and HTML writing.

Emailing means using Python's smtplib directly or Django's email package. This isn't too hard. All the pieces are there, you just need to email the output files produced above to some distribution list.

Scheduling takes a little thinking to make best use of crontab. This -- perhaps -- is the hardest part of the job.

like image 101
S.Lott Avatar answered Sep 18 '22 17:09

S.Lott


I just thought after a fair bit of investigation I would report my findings...

http://code.google.com/p/django-reporting/ - I think that this project, looks like an awesome candidate for alot of the functionality I require. Unfortunately its Django 1.1 which as of this writing (29th April 2009) has not been released.At least in the ability to create reports without too much code.

http://code.google.com/p/django-cron/ - Look promising for scheduling of jobs without cron access

http://www.xhtml2pdf.com/ - Could be used or ReportLabs PDF Libraries for conversion of HTML to PDF

All these together with Django's Email functionality could make a nice Reporting System.

like image 28
Mark Ellul Avatar answered Sep 19 '22 17:09

Mark Ellul