Ejemplo n.º 1
0
def compile_email(
    registration: Registration, template: str, preheader: bool = True
) -> str:
    contact_info = get_registration_contact_info(registration)

    mailing_address = (
        contact_info.address
        if contact_info
        else "We were unable to find your local election official mailing address"
    )

    recipient = {
        "first_name": registration.first_name,
        "last_name": registration.last_name,
        "email": registration.email,
    }
    query_params = registration.get_query_params()
    context = {
        "registration": registration,
        "subscriber": registration.subscriber,
        "recipient": recipient,
        "mailing_address": mailing_address,
        "state_info": registration.state.data,
        "query_params": query_params,
        "vbm_link": f"{settings.WWW_ORIGIN}/vote-by-mail/?{query_params}",
    }
    if registration.result_item:
        context["download_url"] = registration.result_item.download_url

    if contact_info.email or contact_info.phone:
        contact_info_lines = []
        if contact_info.email:
            contact_info_lines.append(f"Email: {contact_info.email}")
        if contact_info.phone:
            contact_info_lines.append(f"Phone: {contact_info.phone}")

        context["leo_contact_info"] = "\n".join(contact_info_lines)
    else:
        context[
            "leo_contact_info"
        ] = "https://www.voteamerica.com/local-election-offices/"

    if registration.result_item_mail:
        context["mail_download_url"] = registration.result_item_mail.download_url
        context["confirm_url"] = PRINT_AND_FORWARD_CONFIRM_URL.format(
            base=settings.WWW_ORIGIN,
            uuid=registration.action.uuid,
            token=generate_lob_token(registration),
        )
        if preheader:
            context[
                "preheader_text"
            ] = f"{registration.first_name}, click the link below and we'll mail you for registration form."
    else:
        if preheader:
            context[
                "preheader_text"
            ] = f"{registration.first_name}, just a few more steps to complete your voter registration: print, sign and mail your form."

    return render_to_string(template, context)
Ejemplo n.º 2
0
def compile_email(
    ballot_request: BallotRequest, template: str, preheader: bool = True
) -> str:
    query_params = ballot_request.get_query_params()

    recipient = {
        "first_name": ballot_request.first_name,
        "last_name": ballot_request.last_name,
        "email": ballot_request.email,
    }
    context = {
        "ballot_request": ballot_request,
        "subscriber": ballot_request.subscriber,
        "recipient": recipient,
        "state_info": ballot_request.state.data,
        "query_params": query_params,
    }
    if ballot_request.result_item:
        context["download_url"] = ballot_request.result_item.download_url
    if ballot_request.region:
        contact_info = get_absentee_contact_info(ballot_request.region.external_id)
        context["mailing_address"] = (
            contact_info.full_address
            if contact_info
            else "We were unable to find your local election official mailing address"
        )
    else:
        contact_info = None

    if contact_info and (contact_info.email or contact_info.phone):
        contact_info_lines = []
        if contact_info.email:
            contact_info_lines.append(f"Email: {contact_info.email}")
        if contact_info.phone:
            contact_info_lines.append(f"Phone: {contact_info.phone}")

        context["leo_contact_info"] = "\n".join(contact_info_lines)
    else:
        context[
            "leo_contact_info"
        ] = "https://www.voteamerica.com/local-election-offices/"

    if ballot_request.request_mailing_address1:
        context["mail_download_url"] = ballot_request.result_item_mail.download_url
        context["confirm_url"] = PRINT_AND_FORWARD_CONFIRM_URL.format(
            base=settings.WWW_ORIGIN,
            uuid=ballot_request.action.uuid,
            token=generate_lob_token(ballot_request),
        )
        if preheader:
            context[
                "preheader_text"
            ] = f"{ballot_request.first_name}, click the link below and we'll mail you your form."
    else:
        if preheader:
            context[
                "preheader_text"
            ] = f"{ballot_request.first_name}, just a few more steps to sign-up for an absentee ballot: print, sign and mail your form."
    return render_to_string(template, context)
Ejemplo n.º 3
0
def lob_confirm(request, uuid):
    try:
        ballot_request = BallotRequest.objects.get(action_id=uuid)
    except ObjectDoesNotExist:
        raise Http404
    if generate_lob_token(ballot_request) != request.GET.get("token", ""):
        raise Http404

    return Response(
        {"error": "This feature is disabled for the time being"},
        status=status.HTTP_503_SERVICE_UNAVAILABLE,
    )
Ejemplo n.º 4
0
def test_lob_confirm(mocker):
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        result_item_mail=baker.make_recipe("storage.ballot_request_form"),
    )

    # send_date = datetime.datetime(2020, 1, 1, 1, 1, 1)
    # send = mocker.patch("absentee.api_views.send_letter", return_value=send_date)

    client = APIClient()
    response = client.put(
        LOB_LETTER_CONFIRM_API_ENDPOINT.format(
            uuid=ballot_request.action.uuid, token=generate_lob_token(ballot_request)
        ),
    )

    assert response.status_code == 503
    assert "error" in response.json()