Exemplo n.º 1
0
def positions_related_to_candidate_campaign_view(request,
                                                 candidate_campaign_id,
                                                 stance_we_are_looking_for):
    """
    We want to return a JSON file with the support positions for a particular candidate's campaign
    :param request:
    :param candidate_campaign_id:
    :return:
    """
    if stance_we_are_looking_for not in (SUPPORT, NO_STANCE, INFORMATION_ONLY,
                                         STILL_DECIDING, OPPOSE):
        print stance_we_are_looking_for
        return JsonResponse({0: "stance not recognized"})

    # This implementation is built to make only two database calls. All other calculations are done here in the
    #  application layer

    position_list_manager = PositionListForCandidateCampaign()
    all_positions_list_for_candidate_campaign = \
        position_list_manager.retrieve_all_positions_for_candidate_campaign(
            candidate_campaign_id, stance_we_are_looking_for)

    voter_device_id = get_voter_device_id(request)
    voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)

    follow_organization_list_manager = FollowOrganizationList()
    organizations_followed_by_voter = \
        follow_organization_list_manager.retrieve_follow_organization_info_for_voter_simple_array(voter_id)

    positions_followed = position_list_manager.calculate_positions_followed_by_voter(
        voter_id, all_positions_list_for_candidate_campaign,
        organizations_followed_by_voter)

    positions_not_followed = position_list_manager.calculate_positions_not_followed_by_voter(
        all_positions_list_for_candidate_campaign,
        organizations_followed_by_voter)

    # TODO: Below we return a snippet of HTML, but this should be converted to returning just the org's name
    #       and id, so the "x, y, and z support" can be assembled and rendered by the client
    # VERSION 1
    # position_html = assemble_candidate_campaign_position_stance_html(
    #     all_positions_list_for_candidate_campaign, stance_we_are_looking_for, candidate_campaign_id)
    # VERSION 2
    position_html = assemble_candidate_campaign_stance_html(
        candidate_campaign_id, stance_we_are_looking_for, positions_followed,
        positions_not_followed)

    return JsonResponse({0: position_html})
Exemplo n.º 2
0
def positions_count_for_candidate_campaign_view(request,
                                                candidate_campaign_id,
                                                stance_we_are_looking_for,
                                                show_followed_positions=True):
    """
    We want to return a JSON file with the support positions for a particular candidate's campaign
    :param request:
    :param candidate_campaign_id:
    :return:
    """
    if stance_we_are_looking_for not in (ANY, SUPPORT, NO_STANCE,
                                         INFORMATION_ONLY, STILL_DECIDING,
                                         OPPOSE):
        print stance_we_are_looking_for
        return JsonResponse({0: "stance not recognized"})

    # This implementation is built to make only two database calls. All other calculations are done here in the
    #  application layer

    position_list_manager = PositionListForCandidateCampaign()
    all_positions_list_for_candidate_campaign = \
        position_list_manager.retrieve_all_positions_for_candidate_campaign(
            candidate_campaign_id, stance_we_are_looking_for)

    voter_device_id = get_voter_device_id(request)
    voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)

    follow_organization_list_manager = FollowOrganizationList()
    organizations_followed_by_voter = \
        follow_organization_list_manager.retrieve_follow_organization_info_for_voter_simple_array(voter_id)

    if show_followed_positions:
        positions_followed = position_list_manager.calculate_positions_followed_by_voter(
            voter_id, all_positions_list_for_candidate_campaign,
            organizations_followed_by_voter)
        positions_followed_count = len(positions_followed)
        return JsonResponse({0: positions_followed_count})
    else:
        positions_not_followed = position_list_manager.calculate_positions_not_followed_by_voter(
            all_positions_list_for_candidate_campaign,
            organizations_followed_by_voter)
        positions_not_followed_count = len(positions_not_followed)
        return JsonResponse({0: positions_not_followed_count})
Exemplo n.º 3
0
def positions_related_to_candidate_campaign_view(request, candidate_campaign_id, stance_we_are_looking_for):
    """
    We want to return a JSON file with the support positions for a particular candidate's campaign
    :param request:
    :param candidate_campaign_id:
    :return:
    """
    if stance_we_are_looking_for not in(SUPPORT, NO_STANCE, INFORMATION_ONLY, STILL_DECIDING, OPPOSE):
        print stance_we_are_looking_for
        return JsonResponse({0: "stance not recognized"})

    # This implementation is built to make only two database calls. All other calculations are done here in the
    #  application layer

    position_list_manager = PositionListForCandidateCampaign()
    all_positions_list_for_candidate_campaign = \
        position_list_manager.retrieve_all_positions_for_candidate_campaign(
            candidate_campaign_id, stance_we_are_looking_for)

    voter_device_id = get_voter_device_id(request)
    voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)

    follow_organization_list_manager = FollowOrganizationList()
    organizations_followed_by_voter = \
        follow_organization_list_manager.retrieve_follow_organization_info_for_voter_simple_array(voter_id)

    positions_followed = position_list_manager.calculate_positions_followed_by_voter(
        voter_id, all_positions_list_for_candidate_campaign, organizations_followed_by_voter)

    positions_not_followed = position_list_manager.calculate_positions_not_followed_by_voter(
        all_positions_list_for_candidate_campaign, organizations_followed_by_voter)

    # TODO: Below we return a snippet of HTML, but this should be converted to returning just the org's name
    #       and id, so the "x, y, and z support" can be assembled and rendered by the client
    # VERSION 1
    # position_html = assemble_candidate_campaign_position_stance_html(
    #     all_positions_list_for_candidate_campaign, stance_we_are_looking_for, candidate_campaign_id)
    # VERSION 2
    position_html = assemble_candidate_campaign_stance_html(
        candidate_campaign_id, stance_we_are_looking_for, positions_followed, positions_not_followed)

    return JsonResponse({0: position_html})
Exemplo n.º 4
0
def positions_display_list_related_to_candidate_campaign(
        request, candidate_campaign_id, stance_we_are_looking_for):
    show_only_followed_positions = convert_to_int(request.GET.get('f', 0))
    show_only_not_followed_positions = convert_to_int(request.GET.get('nf', 0))

    messages_on_stage = get_messages(request)
    candidate_campaign_id = convert_to_int(candidate_campaign_id)

    position_list_manager = PositionListForCandidateCampaign()
    all_positions_list_for_candidate_campaign = \
        position_list_manager.retrieve_all_positions_for_candidate_campaign(
            candidate_campaign_id, stance_we_are_looking_for)

    voter_device_id = get_voter_device_id(request)
    voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)

    follow_organization_list_manager = FollowOrganizationList()
    organizations_followed_by_voter = \
        follow_organization_list_manager.retrieve_follow_organization_info_for_voter_simple_array(voter_id)

    if show_only_followed_positions == 1:
        # print "positions_display_list: show only followed positions"
        list_to_display = position_list_manager.calculate_positions_followed_by_voter(
            voter_id, all_positions_list_for_candidate_campaign,
            organizations_followed_by_voter)
    elif show_only_not_followed_positions == 1:
        # print "positions_display_list: show only NOT followed positions"
        list_to_display = position_list_manager.calculate_positions_not_followed_by_voter(
            all_positions_list_for_candidate_campaign,
            organizations_followed_by_voter)
    else:
        list_to_display = all_positions_list_for_candidate_campaign

    template_values = {
        'error': True,
        'messages_on_stage': messages_on_stage,
        'position_list': list_to_display,
        'organizations_followed_by_voter': organizations_followed_by_voter,
    }
    return render(request, 'position/position_list.html', template_values)
Exemplo n.º 5
0
def positions_display_list_related_to_candidate_campaign(request, candidate_campaign_id, stance_we_are_looking_for):
    show_only_followed_positions = convert_to_int(request.GET.get('f', 0))
    show_only_not_followed_positions = convert_to_int(request.GET.get('nf', 0))

    messages_on_stage = get_messages(request)
    candidate_campaign_id = convert_to_int(candidate_campaign_id)

    position_list_manager = PositionListForCandidateCampaign()
    all_positions_list_for_candidate_campaign = \
        position_list_manager.retrieve_all_positions_for_candidate_campaign(
            candidate_campaign_id, stance_we_are_looking_for)

    voter_device_id = get_voter_device_id(request)
    voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)

    follow_organization_list_manager = FollowOrganizationList()
    organizations_followed_by_voter = \
        follow_organization_list_manager.retrieve_follow_organization_info_for_voter_simple_array(voter_id)

    if show_only_followed_positions == 1:
        # print "positions_display_list: show only followed positions"
        list_to_display = position_list_manager.calculate_positions_followed_by_voter(
            voter_id, all_positions_list_for_candidate_campaign, organizations_followed_by_voter)
    elif show_only_not_followed_positions == 1:
        # print "positions_display_list: show only NOT followed positions"
        list_to_display = position_list_manager.calculate_positions_not_followed_by_voter(
            all_positions_list_for_candidate_campaign, organizations_followed_by_voter)
    else:
        list_to_display = all_positions_list_for_candidate_campaign

    template_values = {
        'error':                            True,
        'messages_on_stage':                messages_on_stage,
        'position_list':                    list_to_display,
        'organizations_followed_by_voter':  organizations_followed_by_voter,
    }
    return render(request, 'position/position_list.html', template_values)
Exemplo n.º 6
0
def positions_count_for_candidate_campaign_view(request, candidate_campaign_id, stance_we_are_looking_for,
                                                show_followed_positions=True):
    """
    We want to return a JSON file with the support positions for a particular candidate's campaign
    :param request:
    :param candidate_campaign_id:
    :return:
    """
    if stance_we_are_looking_for not in(ANY, SUPPORT, NO_STANCE, INFORMATION_ONLY, STILL_DECIDING, OPPOSE):
        print stance_we_are_looking_for
        return JsonResponse({0: "stance not recognized"})

    # This implementation is built to make only two database calls. All other calculations are done here in the
    #  application layer

    position_list_manager = PositionListForCandidateCampaign()
    all_positions_list_for_candidate_campaign = \
        position_list_manager.retrieve_all_positions_for_candidate_campaign(
            candidate_campaign_id, stance_we_are_looking_for)

    voter_device_id = get_voter_device_id(request)
    voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)

    follow_organization_list_manager = FollowOrganizationList()
    organizations_followed_by_voter = \
        follow_organization_list_manager.retrieve_follow_organization_info_for_voter_simple_array(voter_id)

    if show_followed_positions:
        positions_followed = position_list_manager.calculate_positions_followed_by_voter(
            voter_id, all_positions_list_for_candidate_campaign, organizations_followed_by_voter)
        positions_followed_count = len(positions_followed)
        return JsonResponse({0: positions_followed_count})
    else:
        positions_not_followed = position_list_manager.calculate_positions_not_followed_by_voter(
            all_positions_list_for_candidate_campaign, organizations_followed_by_voter)
        positions_not_followed_count = len(positions_not_followed)
        return JsonResponse({0: positions_not_followed_count})