Beispiel #1
0
def send_approval_reinstate_email_notification(approval, request):
    # 31 Reinstated
    # email to licence/permit holder when licence/permit is reinstated or when suspension ends
    email = TemplateEmailBase(
        subject='Reinstated: Rottnest Island {} {}'.format(approval.description, approval.lodgement_number),
        # html_template='mooringlicensing/emails/approval_reinstate_notification.html',
        # txt_template='mooringlicensing/emails/approval_reinstate_notification.txt',
        html_template='mooringlicensing/emails_2/email_31.html',
        txt_template='mooringlicensing/emails_2/email_31.txt',
    )
    proposal = approval.current_proposal

    context = {
        'public_url': get_public_url(request),
        'approval': approval,
        'recipient': approval.submitter,
        'details': '',  # TODO
    }
    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]
    msg = email.send(proposal.submitter.email, cc=all_ccs, context=context)
    sender = request.user if request else settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender)
    #_log_org_email(msg, approval.applicant, proposal.submitter, sender=sender)
    if approval.org_applicant:
        _log_org_email(msg, approval.org_applicant, proposal.submitter, sender=sender)
    else:
        _log_user_email(msg, approval.submitter, proposal.submitter, sender=sender)
Beispiel #2
0
def send_vessel_nomination_reminder_mail(approval, request=None):
    # 10
    email = TemplateEmailBase(
        subject=
        'First and Final Reminder: Vessel Requirements for {} - Rottnest Island Authority'
        .format(approval.description),
        html_template='mooringlicensing/emails_2/email_10.html',
        txt_template='mooringlicensing/emails_2/email_10.txt',
    )
    url = settings.SITE_URL if settings.SITE_URL else ''
    url = url + reverse('external')

    proposal = approval.current_proposal

    context = {
        'public_url':
        get_public_url(request),
        'approval':
        approval,
        'date_to_nominate_new_vessel':
        approval.current_proposal.vessel_ownership.end_date +
        relativedelta(months=+6),
        'dashboard_external_url':
        url,
    }

    sender = settings.DEFAULT_FROM_EMAIL
    try:
        sender_user = EmailUser.objects.get(email__icontains=sender)
    except:
        EmailUser.objects.create(email=sender, password='')
        sender_user = EmailUser.objects.get(email__icontains=sender)

    to_address = approval.submitter.email
    all_ccs = []
    bcc = []

    msg = email.send(
        to_address,
        context=context,
        attachments=[],
        cc=all_ccs,
        bcc=bcc,
    )

    _log_approval_email(msg, approval, sender=sender_user)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender_user)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender_user)

    return msg
Beispiel #3
0
def send_approval_suspend_email_notification(approval, request=None):
    # 29 Suspended
    # email to licence/permit holder when licence/permit is suspended
    email = TemplateEmailBase(
        subject='Suspension of your {} {}'.format(approval.description,
                                                  approval.lodgement_number),
        # html_template='mooringlicensing/emails/approval_suspend_notification.html',
        # txt_template='mooringlicensing/emails/approval_suspend_notification.txt',
        html_template='mooringlicensing/emails_2/email_29.html',
        txt_template='mooringlicensing/emails_2/email_29.txt',
    )
    proposal = approval.current_proposal

    if request and 'test-emails' in request.path_info:
        details = 'This are my test details'
        from_date = '01/01/1970'
        to_date = '01/01/2070'
    else:
        details = approval.suspension_details['details']
        from_date = approval.suspension_details[
            'from_date'] if 'from_date' in approval.suspension_details else ''
        to_date = approval.suspension_details[
            'to_date'] if 'to_date' in approval.suspension_details else ''

    context = {
        'public_url': get_public_url(request),
        'approval': approval,
        'details': details,
        'from_date': from_date,
        'to_date': to_date
    }
    sender = settings.DEFAULT_FROM_EMAIL
    try:
        sender_user = EmailUser.objects.get(email__icontains=sender)
    except:
        EmailUser.objects.create(email=sender, password='')
        sender_user = EmailUser.objects.get(email__icontains=sender)
    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]
    msg = email.send(proposal.submitter.email, cc=all_ccs, context=context)
    sender = settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender_user)
    #_log_org_email(msg, approval.applicant, proposal.submitter, sender=sender_user)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender_user)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender_user)
Beispiel #4
0
def send_dcv_permit_mail(dcv_permit, invoice, request):
    # 26
    # email to applicant upon successful payment of dcv permit application with details of issued dcv permit
    email = TemplateEmailBase(
        subject='Dcv Permit.',
        # html_template='mooringlicensing/emails/dcv_permit_mail.html',
        # txt_template='mooringlicensing/emails/dcv_permit_mail.txt',
        html_template='mooringlicensing/emails_2/email_26.html',
        txt_template='mooringlicensing/emails_2/email_26.txt',
    )

    context = {
        'public_url': get_public_url(request),
        'dcv_permit': dcv_permit,
        'recipient': dcv_permit.submitter,
    }

    attachments = []

    # attach invoice
    contents = create_invoice_pdf_bytes(
        'invoice.pdf',
        invoice,
    )
    attachments.append(('invoice#{}.pdf'.format(invoice.reference), contents,
                        'application/pdf'))

    # attach DcvPermit
    dcv_permit_doc = dcv_permit.permits.first()
    filename = str(dcv_permit_doc)
    content = dcv_permit_doc._file.read()
    mime = mimetypes.guess_type(dcv_permit_doc.filename)[0]
    attachments.append((filename, content, mime))

    to = dcv_permit.submitter.email
    cc = []
    bcc = []

    # Update bcc if
    dcv_group = Group.objects.get(name=settings.GROUP_DCV_PERMIT_ADMIN)
    users = dcv_group.user_set.all()
    if users:
        bcc = [user.email for user in users]

    msg = email.send(
        to,
        context=context,
        attachments=attachments,
        cc=cc,
        bcc=bcc,
    )

    sender = get_user_as_email_user(msg.from_email)
    email_data = _extract_email_headers(msg, sender=sender)
    return email_data
Beispiel #5
0
def send_reissue_aap_after_sale_recorded_email(approval, request,
                                               vessel_ownership,
                                               stickers_to_be_returned):
    # 35 (only for AAP)
    # email to annual admission permit holder upon automatic re-issue after date of sale is recorded (regardless of whether new vessel added at that time)
    proposal = approval.current_proposal

    # Calculate new vessle nomination due date
    sale_date = vessel_ownership.end_date
    six_months = relativedelta(months=6)
    due_date = sale_date + six_months

    email = TemplateEmailBase(
        subject=
        'Vessel Removed from Rottnest Island Annual Admission Permit - Notice to Return Sticker to RIA',
        html_template='mooringlicensing/emails_2/email_35.html',
        txt_template='mooringlicensing/emails_2/email_35.txt',
    )

    attachments = []
    attachment = approval.get_licence_document_as_attachment()
    if attachment:
        attachments.append(attachment)

    context = {
        'public_url': get_public_url(request),
        'recipient': approval.submitter,
        'vessel_rego_no': vessel_ownership.vessel.rego_no,
        'stickers_to_be_returned': stickers_to_be_returned,
        'due_date': due_date,
        'dashboard_external_url': get_public_url(request),
    }
    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]

    msg = email.send(proposal.submitter.email,
                     cc=all_ccs,
                     context=context,
                     attachments=attachments)

    sender = request.user if request else settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender)
Beispiel #6
0
def send_dcv_admission_mail(dcv_admission, invoice, request):
    # 27
    # email to external user upon payment of dcv admission fees
    email = TemplateEmailBase(
        subject='DCV Admission fees',
        # html_template='mooringlicensing/emails/dcv_admission_mail.html',
        # txt_template='mooringlicensing/emails/dcv_admission_mail.txt',
        html_template='mooringlicensing/emails_2/email_27.html',
        txt_template='mooringlicensing/emails_2/email_27.txt',
    )
    summary = dcv_admission.get_summary()

    context = {
        'public_url': get_public_url(request),
        'dcv_admission': dcv_admission,
        'recipient': dcv_admission.submitter,
        'summary': summary,
    }

    attachments = []

    # attach invoice
    if invoice:
        contents = create_invoice_pdf_bytes(
            'invoice.pdf',
            invoice,
        )
        attachments.append(('invoice#{}.pdf'.format(invoice.reference),
                            contents, 'application/pdf'))

    # attach DcvPermit
    if dcv_admission.admissions:
        dcv_admission_doc = dcv_admission.admissions.first()
        if dcv_admission_doc:
            filename = str(dcv_admission_doc)
            content = dcv_admission_doc._file.read()
            mime = mimetypes.guess_type(dcv_admission_doc.filename)[0]
            attachments.append((filename, content, mime))

    to = dcv_admission.submitter.email
    cc = []
    bcc = []

    msg = email.send(
        to,
        context=context,
        attachments=attachments,
        cc=cc,
        bcc=bcc,
    )

    sender = get_user_as_email_user(msg.from_email)
    email_data = _extract_email_headers(msg, sender=sender)
    return email_data
Beispiel #7
0
def send_aup_revoked_due_to_relinquishment_email(request,
                                                 authorised_user_permit,
                                                 mooring,
                                                 stickers_to_be_returned):
    # 38
    # email to authorised user when mooring site authorisation revoked due to mooring site licence relinquishment and to return sticker
    proposal = authorised_user_permit.current_proposal
    approval = authorised_user_permit

    email = TemplateEmailBase(
        subject=
        'Authorised Use of {} Cancelled Due to Relinquishment - Notice to Return Sticker(s) - Rottnest Island Authority'
        .format(mooring.name),
        html_template='mooringlicensing/emails_2/email_38.html',
        txt_template='mooringlicensing/emails_2/email_38.txt',
    )

    attachments = []
    attachment = authorised_user_permit.get_licence_document_as_attachment()
    if attachment:
        attachments.append(attachment)

    context = {
        'public_url': get_public_url(request),
        'recipient': authorised_user_permit.submitter,
        'mooring': mooring,
        'stickers_to_be_returned': stickers_to_be_returned,
        'dashboard_external_url': get_public_url(request),
    }

    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]

    msg = email.send(proposal.submitter.email,
                     cc=all_ccs,
                     context=context,
                     attachments=attachments)

    sender = request.user if request else settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender)
Beispiel #8
0
def send_sticker_replacement_email(request, sticker, invoice):
    # 36
    # email to licence/permit holder when sticker replacement request has been submitted (with payment)
    approval = sticker.approval
    proposal = approval.current_proposal

    email = TemplateEmailBase(
        subject='Sticker Replacement for {} - Rottnest Island Authority'.
        format(approval.description),
        html_template='mooringlicensing/emails_2/email_36.html',
        txt_template='mooringlicensing/emails_2/email_36.txt',
    )

    # Attach invoice
    attachments = []
    invoice_bytes = create_invoice_pdf_bytes(
        'invoice.pdf',
        invoice,
    )
    attachment = ('invoice#{}.pdf'.format(invoice.reference), invoice_bytes,
                  'application/pdf')
    attachments.append(attachment)

    context = {
        'public_url': get_public_url(request),
        'recipient': approval.submitter,
        'sticker': sticker,
        'dashboard_external_url': get_public_url(request),
    }

    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]

    msg = email.send(proposal.submitter.email,
                     cc=all_ccs,
                     context=context,
                     attachments=attachments)

    sender = request.user if request else settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender)
Beispiel #9
0
def send_approval_surrender_email_notification(approval, request=None):
    # 30 Surrendered
    # email to licence/permit holder when licence/permit is surrendered
    email = TemplateEmailBase(
        subject='Surrendered: Rottnest Island {} {} - Effective {}'.format(
            approval.description, approval.lodgement_number,
            approval.surrender_details['surrender_date']),
        # html_template='mooringlicensing/emails/approval_surrender_notification.html',
        # txt_template='mooringlicensing/emails/approval_surrender_notification.txt',
        html_template='mooringlicensing/emails_2/email_30.html',
        txt_template='mooringlicensing/emails_2/email_30.txt',
    )
    proposal = approval.current_proposal

    if request and 'test-emails' in request.path_info:
        details = 'This are my test details'
        surrender_date = '01/01/1970'
    else:
        details = approval.surrender_details['details'],
        surrender_date = approval.surrender_details['surrender_date'],

    context = {
        'public_url': get_public_url(request),
        'approval': approval,
        'recipient': approval.submitter,
        'details': details,
        'surrender_date': surrender_date,
    }
    sender = settings.DEFAULT_FROM_EMAIL
    try:
        sender_user = EmailUser.objects.get(email__icontains=sender)
    except:
        EmailUser.objects.create(email=sender, password='')
        sender_user = EmailUser.objects.get(email__icontains=sender)
    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]
    msg = email.send(proposal.submitter.email, cc=all_ccs, context=context)
    sender = settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender_user)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender_user)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender_user)
Beispiel #10
0
def send_reissue_ml_after_sale_recorded_email(approval, request, vessel_ownership, stickers_to_be_returned):
    # 32 (only for ML)
    # email to licence or mooring licence holder upon automatic re-issue after date of sale is recorded (regardless of whether new vessel added at that time)
    proposal = approval.current_proposal

    # Retrieve mooring
    mooring_name = ''
    if hasattr(approval, 'mooring'):
        mooring_name = approval.mooring.name
    else:
        # Should not reach here
        logger.error('Mooring not found for {} when sending the automatic re-issue email after date of sale is recorded.'.format(approval.lodgement_number))

    # Calculate due date
    sale_date = vessel_ownership.end_date
    six_months = relativedelta(months=6)
    due_date = sale_date + six_months

    email = TemplateEmailBase(
        subject='Vessel Removed from Rottnest Island Mooring Site Licence {} - Notice to Return Sticker to RIA'.format(mooring_name),
        html_template='mooringlicensing/emails_2/email_32.html',
        txt_template='mooringlicensing/emails_2/email_32.txt',
    )

    attachments = []
    attachment = approval.get_licence_document_as_attachment()
    if attachment:
        attachments.append(attachment)

    context = {
        'public_url': get_public_url(request),
        'recipient': approval.submitter,
        'vessel_rego_no': vessel_ownership.vessel.rego_no,
        'stickers_to_be_returned': stickers_to_be_returned,
        'due_date': due_date,
        'dashboard_external_url': get_public_url(request),
    }
    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]

    msg = email.send(proposal.submitter.email, cc=all_ccs, context=context, attachments=attachments)

    sender = request.user if request else settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender, attachments=attachments)
    if approval.org_applicant:
        _log_org_email(msg, approval.org_applicant, proposal.submitter, sender=sender)
    else:
        _log_user_email(msg, approval.submitter, proposal.submitter, sender=sender)
def send_sticker_import_batch_email(process_summary):
    try:
        email = TemplateEmailBase(
            subject='Sticker Import Batch',
            html_template='mooringlicensing/emails/send_sticker_import_batch.html',
            txt_template='mooringlicensing/emails/send_sticker_import_batch.txt',
        )

        attachments = []
        context = {
            'public_url': get_public_url(),
            'process_summary': process_summary,
        }

        from mooringlicensing.components.proposals.models import StickerPrintingContact
        tos = StickerPrintedContact.objects.filter(type=StickerPrintingContact.TYPE_EMIAL_TO, enabled=True)
        ccs = StickerPrintedContact.objects.filter(type=StickerPrintingContact.TYPE_EMAIL_CC, enabled=True)
        bccs = StickerPrintedContact.objects.filter(type=StickerPrintingContact.TYPE_EMAIL_BCC, enabled=True)

        if tos:
            to_address = [contact.email for contact in tos]
            cc = [contact.email for contact in ccs]
            bcc = [contact.email for contact in bccs]

            # Send email
            msg = email.send(to_address, context=context, attachments=attachments, cc=cc, bcc=bcc,)
            return msg

    except Exception as e:
        err_msg = 'Error sending sticker import email'
        logger.exception('{}\n{}'.format(err_msg, str(e)))
Beispiel #12
0
def send_approval_cancel_email_notification(approval):
    # 28 Cancelled
    # email to licence/permit holder when licence/permit is cancelled
    email = TemplateEmailBase(
        subject='Cancellation of your {} {}'.format(approval.description,
                                                    approval.lodgement_number),
        # html_template='mooringlicensing/emails/approval_cancel_notification.html',
        # txt_template='mooringlicensing/emails/approval_cancel_notification.txt',
        html_template='mooringlicensing/emails_2/email_28.html',
        txt_template='mooringlicensing/emails_2/email_28.txt',
    )
    proposal = approval.current_proposal

    context = {
        'public_url': get_public_url(),
        'approval': approval,
        'recipient': approval.submitter,
        'cancel_start_date': approval.cancellation_date,
        'details': approval.cancellation_details,
    }
    sender = settings.DEFAULT_FROM_EMAIL
    try:
        sender_user = EmailUser.objects.get(email__icontains=sender)
    except:
        EmailUser.objects.create(email=sender, password='')
        sender_user = EmailUser.objects.get(email__icontains=sender)
    all_ccs = []
    if proposal.org_applicant and proposal.org_applicant.email:
        cc_list = proposal.org_applicant.email
        if cc_list:
            all_ccs = [cc_list]
    msg = email.send(proposal.submitter.email, cc=all_ccs, context=context)
    sender = settings.DEFAULT_FROM_EMAIL
    _log_approval_email(msg, approval, sender=sender_user)
    #_log_org_email(msg, approval.applicant, proposal.submitter, sender=sender_user)
    if approval.org_applicant:
        _log_org_email(msg,
                       approval.org_applicant,
                       proposal.submitter,
                       sender=sender_user)
    else:
        _log_user_email(msg,
                        approval.submitter,
                        proposal.submitter,
                        sender=sender_user)