"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.