コード例 #1
0
def display_and_process_html_for_modification_of_election_and_nominee_links__nominee_links(
        request, slug):
    """
    Shows the page where the webform is displayed so that the user inputs the data needed to create a new election
    """
    logger.info(
        "[elections/display_and_process_html_for_nominee_links.py "
        "display_and_process_html_for_modification_of_election_and_nominee_links__nominee_links()] "
        "request.POST=")
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message,
     context) = verify_access_logged_user_and_create_context_for_elections(
         request, TAB_STRING)
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value

    if len(Election.objects.all().filter(slug=slug)) != 1:
        context[ERROR_MESSAGES_KEY] = [
            f"Received invalid Election slug of {slug}"
        ]
        return render(
            request,
            'elections/update_election/update_election_nominee_links.html',
            context)

    process_election = (request.method == "POST")

    return process_existing_election_and_nominee_links(request, context, slug) if process_election \
        else display_selected_election_and_nominee_links(request, context, slug)
コード例 #2
0
def display_and_process_html_for_modification_of_webform_election(request):
    """Shows the request election to the user in WebForm format"""
    logger.info(
        "[elections/display_and_process_html_for_webform.py "
        "display_and_process_html_for_modification_of_webform_election()] request.POST="
    )
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message,
     context) = verify_access_logged_user_and_create_context_for_elections(
         request, TAB_STRING)
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value

    if not (ELECTION_ID in request.POST or ELECTION_ID in request.session):
        context[ERROR_MESSAGES_KEY] = [
            "Unable to locate the Election ID in the request"
        ]
        return render(
            request, 'elections/update_election/update_election__webform.html',
            context)

    process_election = (request.method
                        == "POST") and (UPDATE_EXISTING_ELECTION__NAME
                                        in request.POST)
    context.update(create_webform_context(create_new_election=False))

    return process_existing_election_information_from_webform(request, context) \
        if process_election else \
        display_current_webform_election(request, context)
コード例 #3
0
def delete_selected_election(request):
    logger.info("[administration/delete_selected_election.py delete_selected_election()] request.POST=")
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message, context) = verify_access_logged_user_and_create_context_for_elections(
        request, TAB_STRING
    )
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value
    if validate_election_id_in_dict(request.POST):
        Election.objects.get(id=int(request.POST[ELECTION_ID])).delete()
        return HttpResponseRedirect(f'{settings.URL_ROOT}elections/')
    request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format("Could not detect the election ID in your request")
    return HttpResponseRedirect(f"{settings.URL_ROOT}error")
コード例 #4
0
def display_and_process_html_for_new_json_election(request):
    """
    Shows the page where the json is displayed so that the user inputs the data needed to create a new election
    """
    logger.info(
        "[elections/create_election_json.py display_and_process_html_for_new_json_election()] request.POST="
    )
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message, context) = verify_access_logged_user_and_create_context_for_elections(
        request, TAB_STRING
    )
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value

    process_election = request.method == "POST" and CREATE_NEW_ELECTION__NAME in request.POST

    return process_new_inputted_json_election(request, context) \
        if process_election else display_empty_election_json(request, context)
def display_and_process_html_for_nominee_modification(request):
    logger.info(
        "[elections/display_and_process_html_for_nominee_modification__nominee_link.py"
        " display_and_process_html_for_nominee_modification()] "
        "request.POST=")
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message,
     context) = verify_access_logged_user_and_create_context_for_elections(
         request, TAB_STRING)
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value

    nominee_link_id = request.GET.get(NOMINEE_LINK_ID, None)
    nominee_links = NomineeLink.objects.all().filter(id=nominee_link_id)
    error_message = None
    if nominee_link_id is None:
        error_message = ["Unable to locate the Nominee Link ID in the request"]
    elif len(nominee_links) != 1:
        error_message = [
            f"invalid Nominee Link ID of {nominee_link_id} detected in the request"
        ]
    elif nominee_links[0].election is None:
        error_message = [
            f"No election attached to Nominee Link {nominee_links[0]} detected in the request"
        ]
    if error_message is not None:
        create_context_for_create_or_update_nominee__nominee_links_html(
            context, error_messages=[error_message])
        return render(
            request,
            'elections/update_nominee/create_or_update_nominee__nominee_links.html',
            context)

    process_nominee = (request.method
                       == "POST") and (CREATE_OR_UPDATE_NOMINEE__NAME
                                       in request.POST)

    return process_nominee__nominee_links(request, context, nominee_link_id) if process_nominee \
        else display_current_nominee_link_election(request, context, nominee_link_id)
コード例 #6
0
def display_and_process_html_for_new_webform_election(request):
    """
    Shows the page where the webform is displayed so that the user inputs the data needed to create a new election
    """
    logger.info(
        "[elections/create_election_webform.py display_and_process_html_for_new_webform_election()] "
        "request.POST"
    )
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message, context) = verify_access_logged_user_and_create_context_for_elections(
        request, TAB_STRING
    )
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value

    context.update(create_webform_context())
    process_election = request.method == "POST"

    return process_new_inputted_webform_election(request, context) \
        if process_election \
        else render(request, 'elections/create_election/create_election__webform.html', context)
コード例 #7
0
def display_and_process_html_for_new_nominee_links_election(request):
    """
    Shows the page where the webform is displayed so that the user inputs the data needed to create a new election
    via Nominee Links
    """
    logger.info(
        "[elections/create_election_nominee_links.py display_and_process_html_for_new_nominee_links_election()] "
        "request.POST"
    )
    logger.info(json.dumps(request.POST, indent=3))
    (render_value, error_message, context) = verify_access_logged_user_and_create_context_for_elections(
        request, TAB_STRING
    )
    if render_value is not None:
        request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format(error_message)
        return render_value

    if request.method == "POST":
        return process_new_election_and_nominee_links(request, context)
    else:
        create_context_for_create_election_nominee_links_html(context, create_new_election=True)
        return render(request, 'elections/create_election/create_election_nominee_links.html', context)