Skip to content

Commit

Permalink
Added positionListForBallotItem API Endpoint. Renamed and refactored …
Browse files Browse the repository at this point in the history
…opposeCount/supportCount to positionOpposeCountForBallotItem/positionSupportCountForBallotItem.
  • Loading branch information
DaleMcGrew committed Dec 12, 2015
1 parent 1b967c4 commit 7a54c47
Show file tree
Hide file tree
Showing 15 changed files with 456 additions and 234 deletions.
123 changes: 123 additions & 0 deletions apis_v1/documentation_source/position_list_for_ballot_item_doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# apis_v1/documentation_source/position_list_for_ballot_item_doc.py
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-


def position_list_for_ballot_item_doc_template_values(url_root):
"""
Show documentation about positionListForBallotItem
"""
required_query_parameter_list = [
{
'name': 'voter_device_id',
'value': 'string (from cookie)', # boolean, integer, long, string
'description': 'An 88 character unique identifier linked to a voter record on the server',
},
{
'name': 'api_key',
'value': 'string (from post, cookie, or get (in that order))', # boolean, integer, long, string
'description': 'The unique key provided to any organization using the WeVoteServer APIs',
},
{
'name': 'office_id',
'value': 'integer', # boolean, integer, long, string
'description': 'The office we want positions for. '
'(One and only one of these must exist: office_id, candidate_id, or measure_id)',
},
{
'name': 'candidate_id',
'value': 'integer', # boolean, integer, long, string
'description': 'The candidate we want positions for. '
'(One and only one of these must exist: office_id, candidate_id, or measure_id)',
},
{
'name': 'measure_id',
'value': 'integer', # boolean, integer, long, string
'description': 'The measure we want the oppose count for. '
'(One and only one of these must exist: office_id, candidate_id, or measure_id)',
},
]
optional_query_parameter_list = [
{
'name': 'stance',
'value': 'string', # boolean, integer, long, string
'description': 'Default is ANY_STANCE. '
'Other options include SUPPORT, STILL_DECIDING, INFO_ONLY, NO_STANCE, OPPOSE',
},
{
'name': 'show_positions_this_voter_follows',
'value': 'boolean', # boolean, integer, long, string
'description': 'True default shows the positions of organizations, public figures and '
'friends this voter is following. '
'If False, show positions that the voter is NOT following.',
},
]

potential_status_codes_list = [
{
'code': 'VALID_VOTER_DEVICE_ID_MISSING',
'description': 'Cannot proceed. A valid voter_device_id parameter was not included.',
},
{
'code': 'VALID_VOTER_ID_MISSING',
'description': 'Cannot proceed. A valid voter_id was not found.',
},
{
'code': 'UNABLE_TO_RETRIEVE-CANDIDATE_ID_AND_MEASURE_ID_MISSING',
'description': 'Cannot proceed. Neither candidate_id nor measure_id were included.',
},
{
'code': 'SUCCESSFUL_RETRIEVE_OF_POSITIONS',
'description': 'The number of opposes for this ballot item was retrieved.',
},
{
'code': 'SUCCESSFUL_RETRIEVE_OF_POSITIONS_NOT_FOLLOWED',
'description': 'The number of organizations that oppose this ballot item that voter is NOT following.',
},
]

try_now_link_variables_dict = {
'candidate_id': '5655',
'show_positions_this_voter_follows': 'False',
'stance': 'ANY_STANCE',
}

api_response = '{\n' \
' "status": string,\n' \
' "success": boolean,\n' \
' "count": integer,\n' \
' "ballot_item_type": string, ' \
' (One of these: \'CANDIDATE\', \'MEASURE\', \'OFFICE\', \'UNKNOWN\',)\n' \
' "ballot_item_id": integer,\n' \
' "position_list": list\n' \
' [\n' \
' "position_id": integer,\n' \
' "position_we_vote_id": string,\n' \
' "speaker_label": string,\n' \
' "speaker_type": string,\n' \
' "speaker_id": integer,\n' \
' "speaker_we_vote_id": string,\n' \
' "is_support": boolean,\n' \
' "is_oppose": boolean,\n' \
' ],\n' \
'}'

template_values = {
'api_name': 'positionListForBallotItem',
'api_slug': 'positionListForBallotItem',
'api_introduction':
"A list of all positions (support/oppose/info) for this Ballot Item (Office, Candidate or Measure) "
"from organizations, friends, and public figures this voter follows. "
"(Or show the positions the voter is NOT following if show_positions_this_voter_follows is False.)",
'try_now_link': 'apis_v1:positionListForBallotItemView',
'try_now_link_variables_dict': try_now_link_variables_dict,
'url_root': url_root,
'get_or_post': 'GET',
'required_query_parameter_list': required_query_parameter_list,
'optional_query_parameter_list': optional_query_parameter_list,
'api_response': api_response,
'api_response_notes':
"",
'potential_status_codes_list': potential_status_codes_list,
}
return template_values
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# apis_v1/documentation_source/oppose_count_doc.py
# apis_v1/documentation_source/position_oppose_count_for_ballot_item_doc.py
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-


def oppose_count_doc_template_values(url_root):
def position_oppose_count_for_ballot_item_doc_template_values(url_root):
"""
Show documentation about opposeCount
Show documentation about positionOpposeCountForBallotItem
"""
required_query_parameter_list = [
{
Expand Down Expand Up @@ -73,12 +73,12 @@ def oppose_count_doc_template_values(url_root):
'}'

template_values = {
'api_name': 'opposeCount',
'api_slug': 'opposeCount',
'api_name': 'positionOpposeCountForBallotItem',
'api_slug': 'positionOpposeCountForBallotItem',
'api_introduction':
"How many of the organizations that the voter follows, plus the friends of the voter, "
"oppose this candidate or measure?",
'try_now_link': 'apis_v1:opposeCountView',
"A single number showing the total that oppose this Ballot Item (Candidate or Measure) from "
"organizations, friends, and public figures this voter follows.",
'try_now_link': 'apis_v1:positionOpposeCountForBallotItemView',
'try_now_link_variables_dict': try_now_link_variables_dict,
'url_root': url_root,
'get_or_post': 'GET',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# apis_v1/documentation_source/support_count_doc.py
# apis_v1/documentation_source/position_support_count_for_ballot_item_doc.py
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-


def support_count_doc_template_values(url_root):
def position_support_count_for_ballot_item_doc_template_values(url_root):
"""
Show documentation about supportCount
Show documentation about positionSupportCountForBallotItem
"""
required_query_parameter_list = [
{
Expand Down Expand Up @@ -73,12 +73,12 @@ def support_count_doc_template_values(url_root):
'}'

template_values = {
'api_name': 'supportCount',
'api_slug': 'supportCount',
'api_name': 'positionSupportCountForBallotItem',
'api_slug': 'positionSupportCountForBallotItem',
'api_introduction':
"How many of the organizations that the voter follows, plus the friends of the voter, "
"support this candidate or measure?",
'try_now_link': 'apis_v1:supportCountView',
"A single number showing the total supporters for this Ballot Item (Candidate or Measure) from "
"organizations, friends, and public figures this voter follows.",
'try_now_link': 'apis_v1:positionSupportCountForBallotItemView',
'try_now_link_variables_dict': try_now_link_variables_dict,
'url_root': url_root,
'get_or_post': 'GET',
Expand Down
18 changes: 13 additions & 5 deletions apis_v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
url(r'^organizationRetrieve/', views.organization_retrieve_view, name='organizationRetrieveView'),
url(r'^organizationSave/', views.organization_save_view, name='organizationSaveView'),
url(r'^organizationSearch/', views.organization_search_view, name='organizationSearchView'),
url(r'^organizationStopFollowing/', views.organization_stop_following_api_view, name='organizationStopFollowingView'),
url(r'^opposeCount/', views.oppose_count_view, name='opposeCountView'),
url(r'^organizationStopFollowing/',
views.organization_stop_following_api_view, name='organizationStopFollowingView'),
url(r'^positionLikeCount/', views.position_like_count_view, name='positionLikeCountView'),
url(r'^positionListForBallotItem/', views.position_list_for_ballot_item_view, name='positionListForBallotItemView'),
url(r'^positionOpposeCountForBallotItem/',
views.position_oppose_count_for_ballot_item_view, name='positionOpposeCountForBallotItemView'),
url(r'^positionRetrieve/', views.position_retrieve_view, name='positionRetrieveView'),
url(r'^positionSave/', views.position_save_view, name='positionSaveView'),
url(r'^supportCount/', views.support_count_view, name='supportCountView'),
url(r'^positionSupportCountForBallotItem/',
views.position_support_count_for_ballot_item_view, name='positionSupportCountForBallotItemView'),
url(r'^voterAddressRetrieve/', views.voter_address_retrieve_view, name='voterAddressRetrieveView'),
url(r'^voterAddressSave/', views.voter_address_save_view, name='voterAddressSaveView'),
url(r'^voterBallotItemsRetrieve/', views.voter_ballot_items_retrieve_view, name='voterBallotItemsRetrieveView'),
Expand Down Expand Up @@ -78,11 +82,15 @@
url(r'^docs/organizationSearch/$', views_docs.organization_search_doc_view, name='organizationSearchDocs'),
url(r'^docs/organizationStopFollowing/',
views_docs.organization_stop_following_doc_view, name='organizationStopFollowingDocs'),
url(r'^docs/opposeCount/', views_docs.oppose_count_doc_view, name='opposeCountDocs'),
url(r'^docs/positionListForBallotItem/',
views_docs.position_list_for_ballot_item_doc_view, name='positionListForBallotItemDocs'),
url(r'^docs/positionOpposeCountForBallotItem/',
views_docs.position_oppose_count_for_ballot_item_doc_view, name='positionOpposeCountForBallotItemDocs'),
url(r'^docs/positionLikeCount/$', views_docs.position_like_count_doc_view, name='positionLikeCountDocs'),
url(r'^docs/positionRetrieve/$', views_docs.position_retrieve_doc_view, name='positionRetrieveDocs'),
url(r'^docs/positionSave/$', views_docs.position_save_doc_view, name='positionSaveDocs'),
url(r'^docs/supportCount/', views_docs.support_count_doc_view, name='supportCountDocs'),
url(r'^docs/positionSupportCountForBallotItem/',
views_docs.position_support_count_for_ballot_item_doc_view, name='positionSupportCountForBallotItemDocs'),
url(r'^docs/voterAddressRetrieve/$', views_docs.voter_address_retrieve_doc_view, name='voterAddressRetrieveDocs'),
url(r'^docs/voterAddressSave/$', views_docs.voter_address_save_doc_view, name='voterAddressSaveDocs'),
url(r'^docs/voterBallotItemsRetrieve/$',
Expand Down
44 changes: 35 additions & 9 deletions apis_v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
from office.controllers import office_retrieve_for_api
from organization.controllers import organization_retrieve_for_api, organization_save_for_api, \
organization_search_for_api
from position.controllers import position_retrieve_for_api, position_save_for_api, \
voter_position_retrieve_for_api, voter_position_comment_save_for_api
from position.controllers import position_list_for_ballot_item_for_api, position_retrieve_for_api, \
position_save_for_api, voter_position_retrieve_for_api, voter_position_comment_save_for_api
from position.models import ANY_STANCE, SUPPORT, STILL_DECIDING, INFORMATION_ONLY, NO_STANCE, OPPOSE
from position_like.controllers import position_like_count_for_api, voter_position_like_off_save_for_api, \
voter_position_like_on_save_for_api, voter_position_like_status_retrieve_for_api
from rest_framework.response import Response
from rest_framework.views import APIView
from star.controllers import voter_star_off_save_for_api, voter_star_on_save_for_api, voter_star_status_retrieve_for_api
from support_oppose_deciding.controllers import oppose_count_for_api, support_count_for_api, \
from support_oppose_deciding.controllers import position_oppose_count_for_ballot_item_for_api, \
position_support_count_for_ballot_item_for_api, \
voter_opposing_save, voter_stop_opposing_save, voter_stop_supporting_save, voter_supporting_save_for_api
from voter.controllers import voter_address_retrieve_for_api, voter_address_save_for_api, voter_retrieve_list_for_api
from voter.serializers import VoterSerializer
Expand Down Expand Up @@ -181,6 +183,30 @@ def organization_search_view(request):
organization_email=organization_email)


def position_list_for_ballot_item_view(request):
"""
Retrieve the number of orgs and friends that support this (positionSupportCountForBallotItem)
:param request:
:return:
"""
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
office_id = request.GET.get('office_id', 0)
candidate_id = request.GET.get('candidate_id', 0)
measure_id = request.GET.get('measure_id', 0)
stance = request.GET.get('stance', ANY_STANCE)
if stance in(ANY_STANCE, SUPPORT, STILL_DECIDING, INFORMATION_ONLY, NO_STANCE, OPPOSE):
stance_we_are_looking_for = stance
else:
stance_we_are_looking_for = ANY_STANCE
show_positions_this_voter_follows = request.GET.get('show_positions_this_voter_follows', True)
return position_list_for_ballot_item_for_api(voter_device_id=voter_device_id,
office_id=office_id,
candidate_id=candidate_id,
measure_id=measure_id,
stance_we_are_looking_for=stance_we_are_looking_for,
show_positions_this_voter_follows=show_positions_this_voter_follows)


def position_retrieve_view(request):
"""
Retrieve all of the details about a single position based on unique identifier
Expand Down Expand Up @@ -242,28 +268,28 @@ def position_save_view(request):
return HttpResponse(json.dumps(results), content_type='application/json')


def oppose_count_view(request):
def position_oppose_count_for_ballot_item_view(request):
"""
Retrieve the number of orgs and friends that oppose this (opposeCount)
Retrieve the number of orgs and friends that oppose this (positionOpposeCountForBallotItem)
:param request:
:return:
"""
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
candidate_id = request.GET.get('candidate_id', 0)
measure_id = request.GET.get('measure_id', 0)
return oppose_count_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)
return position_oppose_count_for_ballot_item_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)


def support_count_view(request):
def position_support_count_for_ballot_item_view(request):
"""
Retrieve the number of orgs and friends that support this (supportCount)
Retrieve the number of orgs and friends that support this (positionSupportCountForBallotItem)
:param request:
:return:
"""
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
candidate_id = request.GET.get('candidate_id', 0)
measure_id = request.GET.get('measure_id', 0)
return support_count_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)
return position_support_count_for_ballot_item_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)


def voter_address_retrieve_view(request):
Expand Down
30 changes: 21 additions & 9 deletions apis_v1/views_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from .documentation_source import ballot_item_options_retrieve_doc, candidate_retrieve_doc, candidates_retrieve_doc, \
device_id_generate_doc, \
elections_retrieve_doc, measure_retrieve_doc, office_retrieve_doc, \
oppose_count_doc, organization_count_doc, \
organization_count_doc, \
organization_follow_doc, organization_follow_ignore_doc, organization_stop_following_doc, \
organization_retrieve_doc, organization_save_doc, organization_search_doc, \
position_like_count_doc, position_retrieve_doc, position_save_doc, \
support_count_doc, voter_address_retrieve_doc, voter_address_save_doc, \
position_like_count_doc, position_list_for_ballot_item_doc, position_oppose_count_for_ballot_item_doc, \
position_retrieve_doc, position_save_doc, \
position_support_count_for_ballot_item_doc, voter_address_retrieve_doc, voter_address_save_doc, \
voter_ballot_items_retrieve_doc, voter_ballot_items_retrieve_from_google_civic_doc, voter_count_doc, \
voter_create_doc, voter_guide_possibility_retrieve_doc, voter_guide_possibility_save_doc, \
voter_guides_to_follow_retrieve_doc, \
Expand Down Expand Up @@ -160,6 +161,15 @@ def organization_search_doc_view(request):
return render(request, 'apis_v1/api_doc_page.html', template_values)


def position_list_for_ballot_item_doc_view(request):
"""
Show documentation about positionListForBallotItem
"""
url_root = LOCALHOST_URL_ROOT
template_values = position_list_for_ballot_item_doc.position_list_for_ballot_item_doc_template_values(url_root)
return render(request, 'apis_v1/api_doc_page.html', template_values)


def position_retrieve_doc_view(request):
"""
Show documentation about positionRetrieve
Expand All @@ -179,21 +189,23 @@ def position_save_doc_view(request):
return render(request, 'apis_v1/api_doc_page.html', template_values)


def oppose_count_doc_view(request):
def position_oppose_count_for_ballot_item_doc_view(request):
"""
Show documentation about opposeCount
Show documentation about positionOpposeCountForBallotItem
"""
url_root = LOCALHOST_URL_ROOT
template_values = oppose_count_doc.oppose_count_doc_template_values(url_root)
template_values = position_oppose_count_for_ballot_item_doc.\
position_oppose_count_for_ballot_item_doc_template_values(url_root)
return render(request, 'apis_v1/api_doc_page.html', template_values)


def support_count_doc_view(request):
def position_support_count_for_ballot_item_doc_view(request):
"""
Show documentation about supportCount
Show documentation about positionSupportCountForBallotItem
"""
url_root = LOCALHOST_URL_ROOT
template_values = support_count_doc.support_count_doc_template_values(url_root)
template_values = position_support_count_for_ballot_item_doc.\
position_support_count_for_ballot_item_doc_template_values(url_root)
return render(request, 'apis_v1/api_doc_page.html', template_values)


Expand Down
2 changes: 1 addition & 1 deletion organization/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
handle_record_not_deleted_exception, handle_record_not_found_exception, handle_record_not_saved_exception
from candidate.models import CandidateCampaign, CandidateCampaignList
from election.models import Election
from position.models import PositionEntered, PositionEnteredManager, INFORMATION_ONLY, OPPOSE, \
from position.models import PositionEntered, PositionEnteredManager, ANY_STANCE, INFORMATION_ONLY, OPPOSE, \
STILL_DECIDING, SUPPORT
from rest_framework.views import APIView
from rest_framework.response import Response
Expand Down
Loading

0 comments on commit 7a54c47

Please sign in to comment.