Changeset 14d3c74 in rattail


Ignore:
Timestamp:
06/18/20 13:56:44 (8 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
c7617c2
Parents:
2f705ac
Message:

Add email_output() method for report handler, plus common template

Location:
rattail
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • rattail/config.py

    r2f705ac r14d3c74  
    506506        return self.getlist('rattail.upgrades', 'command', default=default, usedb=False)
    507507
     508    def base_url(self):
     509        """
     510        Returns the configured "base" (root) URL for the web app.
     511        """
     512        # first try "generic" config option
     513        url = self.get('rattail', 'base_url')
     514
     515        # or use tailbone as fallback, since it's most likely
     516        if url is None:
     517            url = self.get('tailbone', 'url')
     518
     519        if url is not None:
     520            return url.rstrip('/')
     521
    508522    def datasync_url(self):
    509523        """
  • rattail/mail.py

    r2f705ac r14d3c74  
    454454        '.pdf': 'pdf',
    455455        '.xls': 'vnd.ms-excel',
     456        '.xlsx': 'vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    456457    }
    457458
  • rattail/reporting/handlers.py

    r2f705ac r14d3c74  
    3434from rattail.db import model
    3535from rattail.util import load_entry_points, load_object
     36from rattail.mail import send_email
     37from rattail.time import localtime
    3638
    3739
     
    9496        return params
    9597
     98    def email_output(self, report, output, mailkey,
     99                     fallback_mailkey='common_report', extra_data={}, **kwargs):
     100        """
     101        Send an email (using the given :param:`mailkey`) with the report output
     102        as an attachment.
     103        """
     104        if 'attachments' not in kwargs:
     105            path = output.filepath(self.config)
     106            kwargs['attachments'] = [path]
     107
     108        data = {
     109            'config': self.config,
     110            'handler': self,
     111            'report': report,
     112            'output': output,
     113            'localtime': localtime,
     114        }
     115
     116        if extra_data:
     117            data.update(extra_data)
     118
     119        if 'params' not in data:
     120            data['params'] = output.params
     121
     122        send_email(self.config, mailkey, data, fallback_key=fallback_mailkey,
     123                   **kwargs)
     124
    96125
    97126def get_report_handler(config):
Note: See TracChangeset for help on using the changeset viewer.