Package: django-reporter
===============Django-reporter===============A Django application to create automated email reports in .csv format.  Itincludes a management command that is intended to be invoked periocically fromcron.Installation************To install::pip install django-reporterThen add ``reporter`` to your INSTALLED_APPS::INSTALLED_APPS = (...'reporter',)Also, make sure the email settings for your project are correct.Creating Reports****************Similar to Django's admin app, reports are created within *reports.py* filesinside your installed applications.  Inside each *reports.py* should be atleast one report that subclasses the ``reporter.BaseReport`` class.  After thesubclass is defined, use the ``reporter.register()`` function to register thereport.  Your subclass should define at least two attributes and implementa few methods, detailed below.  Review the *sample_reports.py* file for anexample of a simple report.Required Attributes-------------------A basic report should have a docstring (which is shown with the ``--list-all``option on the management command), and needs at least two attributes,``name``, and ``frequencies``.For example, the sample report starts out with::class AdminLogReport(reporter.BaseReport):"""Send full admin log info for the day, broken down by user"""name = 'admin_log'frequencies = ['daily']``name``~~~~~~~~.. attribute:: BaseReport.nameThe name of the report, used when invoking the ``report`` management command.``frequencies``~~~~~~~~~~~~~~~.. attribute:: BaseReport.frequenciesThe frequencies that this report is available for.Built-in Attributes-------------------The base class automatically sets a number of attributes that are availablein the subclass.``frequency``~~~~~~~~~~~~~.. attribute:: BaseReport.frequencyThe requested frequency of the report.  This can be used to determine thecorrect date range to filter for in your report.``date``~~~~~~~~.. attribute:: BaseReport.dateThe requested date for the report.  Defaults to today if no date is provided.``tomorrow``~~~~~~~~~~~~.. attribute:: BaseReport.tomorrowThe requested date plus 1 day.``one_week``~~~~~~~~~~~~.. attribute:: BaseReport.one_weekThe requested date minus 7 days.``one_month``~~~~~~~~~~~~~.. attribute:: BaseReport.one_monthThe requested date minus 32 days.``args``~~~~~~~~.. attribute:: BaseReport.argsA list of additional arguments passed on to the report from the managementcommand.Methods-------These methods are required to be implemented in your subclass in order togenerate reports.``get_default_recipients``~~~~~~~~~~~~~~~~~~~~~~~~~~.. method:: BaseReport.get_default_recipients(self):This method is called by the base class's ``send_results`` method.  Itprovides the default recipients for the email, which is used if the recipientsare not overridden by the ``--recipients`` option on the management command.This should return a list of strings containing the email address of eachrecipient.``get_email_subject``~~~~~~~~~~~~~~~~~~~~~.. method:: BaseReport.get_email_subject(self):This method is also called by the base class's ``send_results`` method.  Itprovides the subject line for the email that is sent.  It should return astring.``get_data``~~~~~~~~~~~~This is the method that the base class calls to retrieve the data that shouldbe converted to csv and sent through email.  This should return a list ofrows, each row consisting of a list of fields.For example, in the sample ``admin_log`` report, a header row is defined atthe top of the ``get_data`` method::data = [['Username', 'Time', 'Action', 'Content Type', 'ID', 'Name']]Then, for each row of data, a list of data within those fields is appended::data.append([log.user, time, actions[log.action_flag],log.content_type.name, log.object_id, obj_name])Registration------------Once the report is defined in the *reports.py* file, it's ready to beregistered.  The sample report registers its class at the bottom of the file::reporter.register(AdminLogReport)Running Reports***************To run reports, use the ``report`` management command.Usage::report [options] FREQUENCY REPORT_NAME [REPORT ARGS]Valid frequencies are "daily", "weekly", and "monthly". By default, thereports are emailed to the report's default recipients. This can beoverridden through the ``--recipients`` option.  Additional arguments afterthe report name will be passed to the report.Options-------``-V, --view``~~~~~~~~~~~~~~Send the data to stdout instead of emailing or saving to a file.``-f FILE, --filename=FILE``~~~~~~~~~~~~~~~~~~~~~~~~~~~~Instead of emailing the results, save them to the provided filename.``-r RECIPIENTS, --recipients=RECIPIENTS``~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Override the default recipients for the report.  Seperate each email addresswith a comma. Do not use spaces.``-l, --list-all``~~~~~~~~~~~~~~~~~~List all available reports, and then exit.``-d YYYY-MM-DD, --date=YYYY-MM-DD``~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Provide a date to run the report for.