示例#1
0
    def test_full_email_is_sent_async(self):
        jobs = []

        send_mail = asynchronously(send_mail)
        jobs.append(
            send_mail(
                [('To Example', '*****@*****.**'), '*****@*****.**'],
                '[Mail Test] - I should be delivered to the inbox',
                '''
                    <html>
                        <head></head>
                        <body>
                            <h1>Hello, wellcome to the mailing group</h1>
                            <p>See you in the inbox</p>
                            <br/>
                            <br/>
                            </p>Regards</p>
                        </body>
                    </html>
                ''',
                is_html=True,
                cc = '[email protected], [email protected]',
                bcc = ['*****@*****.**', ('You Know Who', '*****@*****.**')],
                sender = ('App', '*****@*****.**'),
                reply_to = '*****@*****.**',
                attachments = [os.path.abspath(os.path.dirname(__file__)) + '/mail_test.py', os.path.abspath(os.path.dirname(__file__)) + '/__init__.py']
            )
        )

        for j in jobs:
            j.join()
示例#2
0
def send_daily_report(today=None):
    """Task to run the Daily PDF Exporter"""

    today = date.today() if today is None else datetime.strptime(today, '%Y-%m-%d')

    # Get requests
    default = ''
    requests_list = []
    districts = []

    start_date = (today + timedelta(days=-2)).strftime('%Y-%m-%d')
    end_date = today.strftime('%Y-%m-%d')

    for _request in get_requests(start_date, end_date, None):

        location = Location.i().guess_location(_request)

        district = location['district']
        districts.append(district.lower())
        neighbourhood = location['neighbourhood']
        location_name = location['location_name']

        requests_list.append({
                'id': xstr(_request['service_request_id']),
                'district': district,
                'neighbourhood': neighbourhood,
                'location_name': location_name,
                'nature': xstr(_request['service_name']),
                'datetime': xstr(_request['requested_datetime'])[0:10] + " " + xstr(_request['requested_datetime'])[11:19],
                'type': xstr(_request['service_name']),
                'status': xstr(_request['service_notice']),
                'status_notes': xstr(_request.get('status_notes', ''))
            })

    # sorting
    requests_list = sorted(requests_list, key=lambda i: (i['district'], i['neighbourhood'], i['nature'], i['datetime']))

    # per district export
    districts = set(districts)

    for district in districts:
        district_requests = filter(lambda x: x['district'].lower() == district, requests_list)

        # Generate PDF
        context = {
            'today': today.strftime('%d-%m-%Y'),
            'requests_list': district_requests,
            'static': os.path.join(config.BASE_DIR, 'templates') + '/'
        }

        f_name = 'relatorio-diario-' + slugify(district) + '-' + today.strftime('%Y_%m_%d') + '.pdf'
        generate_pdf('daily_report.html', context, f_name)

        # Send mail
        html = '''\
            <html>
                <head></head>
                <body>
                <p>Sauda&ccedil;&otilde;es!<br/><br/>
                    Segue em anexo o relat&oacute;rio MOPA<br/><br/>
                    Cumprimentos,<br/>
                    <em>Enviado automaticamente</em>
                </p>
                </body>
            </html>
                '''
        send_mail(
            config.DAILY_REPORT_TO,
            '[MOPA] Relatorio Diario - ' + district.title() + ' - ' + today.strftime('%Y-%m-%d'),
            html,
            is_html=True,
            cc=config.DAILY_REPORT_CC,
            sender=(config.EMAIL_DEFAULT_NAME, config.EMAIL_DEFAULT_SENDER),
            attachments=[config.REPORTS_DIR + '/' + f_name]
        )

    return "Ok", 200
示例#3
0
        <html>
            <head></head>
            <body>
            <p>Sauda&ccedil;&otilde;es!<br/><br/>
                Segue em anexo o relat&oacute;rio MOPA<br/><br/>
                Cumprimentos,<br/>
                <em>Enviado automaticamente</em>
            </p>
            </body>
        </html>
            '''
    send_mail(
        config.WEEKLY_REPORT_TO,
        '[MOPA] Relatorio Semanal - ' + today.strftime('%Y-%m-%d'),
        html,
        is_html=True,
        cc=config.DAILY_REPORT_CC,
        sender=(config.EMAIL_DEFAULT_NAME, config.EMAIL_DEFAULT_SENDER),
        attachments=[config.REPORTS_DIR + '/' + f_name]
    )

    return "Ok", 200


@tasks.route('/send-monthly-report')
def send_monthly_report():
    """Task to prepare and send the monthly report"""
    return "Ok", 200


@tasks.route('/send-daily-report/<regex("\d{4}-\d{2}-\d{2}"):today>')