Skip to content

Commit 7a54c47

Browse files
committed
Added positionListForBallotItem API Endpoint. Renamed and refactored opposeCount/supportCount to positionOpposeCountForBallotItem/positionSupportCountForBallotItem.
1 parent 1b967c4 commit 7a54c47

15 files changed

+456
-234
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# apis_v1/documentation_source/position_list_for_ballot_item_doc.py
2+
# Brought to you by We Vote. Be good.
3+
# -*- coding: UTF-8 -*-
4+
5+
6+
def position_list_for_ballot_item_doc_template_values(url_root):
7+
"""
8+
Show documentation about positionListForBallotItem
9+
"""
10+
required_query_parameter_list = [
11+
{
12+
'name': 'voter_device_id',
13+
'value': 'string (from cookie)', # boolean, integer, long, string
14+
'description': 'An 88 character unique identifier linked to a voter record on the server',
15+
},
16+
{
17+
'name': 'api_key',
18+
'value': 'string (from post, cookie, or get (in that order))', # boolean, integer, long, string
19+
'description': 'The unique key provided to any organization using the WeVoteServer APIs',
20+
},
21+
{
22+
'name': 'office_id',
23+
'value': 'integer', # boolean, integer, long, string
24+
'description': 'The office we want positions for. '
25+
'(One and only one of these must exist: office_id, candidate_id, or measure_id)',
26+
},
27+
{
28+
'name': 'candidate_id',
29+
'value': 'integer', # boolean, integer, long, string
30+
'description': 'The candidate we want positions for. '
31+
'(One and only one of these must exist: office_id, candidate_id, or measure_id)',
32+
},
33+
{
34+
'name': 'measure_id',
35+
'value': 'integer', # boolean, integer, long, string
36+
'description': 'The measure we want the oppose count for. '
37+
'(One and only one of these must exist: office_id, candidate_id, or measure_id)',
38+
},
39+
]
40+
optional_query_parameter_list = [
41+
{
42+
'name': 'stance',
43+
'value': 'string', # boolean, integer, long, string
44+
'description': 'Default is ANY_STANCE. '
45+
'Other options include SUPPORT, STILL_DECIDING, INFO_ONLY, NO_STANCE, OPPOSE',
46+
},
47+
{
48+
'name': 'show_positions_this_voter_follows',
49+
'value': 'boolean', # boolean, integer, long, string
50+
'description': 'True default shows the positions of organizations, public figures and '
51+
'friends this voter is following. '
52+
'If False, show positions that the voter is NOT following.',
53+
},
54+
]
55+
56+
potential_status_codes_list = [
57+
{
58+
'code': 'VALID_VOTER_DEVICE_ID_MISSING',
59+
'description': 'Cannot proceed. A valid voter_device_id parameter was not included.',
60+
},
61+
{
62+
'code': 'VALID_VOTER_ID_MISSING',
63+
'description': 'Cannot proceed. A valid voter_id was not found.',
64+
},
65+
{
66+
'code': 'UNABLE_TO_RETRIEVE-CANDIDATE_ID_AND_MEASURE_ID_MISSING',
67+
'description': 'Cannot proceed. Neither candidate_id nor measure_id were included.',
68+
},
69+
{
70+
'code': 'SUCCESSFUL_RETRIEVE_OF_POSITIONS',
71+
'description': 'The number of opposes for this ballot item was retrieved.',
72+
},
73+
{
74+
'code': 'SUCCESSFUL_RETRIEVE_OF_POSITIONS_NOT_FOLLOWED',
75+
'description': 'The number of organizations that oppose this ballot item that voter is NOT following.',
76+
},
77+
]
78+
79+
try_now_link_variables_dict = {
80+
'candidate_id': '5655',
81+
'show_positions_this_voter_follows': 'False',
82+
'stance': 'ANY_STANCE',
83+
}
84+
85+
api_response = '{\n' \
86+
' "status": string,\n' \
87+
' "success": boolean,\n' \
88+
' "count": integer,\n' \
89+
' "ballot_item_type": string, ' \
90+
' (One of these: \'CANDIDATE\', \'MEASURE\', \'OFFICE\', \'UNKNOWN\',)\n' \
91+
' "ballot_item_id": integer,\n' \
92+
' "position_list": list\n' \
93+
' [\n' \
94+
' "position_id": integer,\n' \
95+
' "position_we_vote_id": string,\n' \
96+
' "speaker_label": string,\n' \
97+
' "speaker_type": string,\n' \
98+
' "speaker_id": integer,\n' \
99+
' "speaker_we_vote_id": string,\n' \
100+
' "is_support": boolean,\n' \
101+
' "is_oppose": boolean,\n' \
102+
' ],\n' \
103+
'}'
104+
105+
template_values = {
106+
'api_name': 'positionListForBallotItem',
107+
'api_slug': 'positionListForBallotItem',
108+
'api_introduction':
109+
"A list of all positions (support/oppose/info) for this Ballot Item (Office, Candidate or Measure) "
110+
"from organizations, friends, and public figures this voter follows. "
111+
"(Or show the positions the voter is NOT following if show_positions_this_voter_follows is False.)",
112+
'try_now_link': 'apis_v1:positionListForBallotItemView',
113+
'try_now_link_variables_dict': try_now_link_variables_dict,
114+
'url_root': url_root,
115+
'get_or_post': 'GET',
116+
'required_query_parameter_list': required_query_parameter_list,
117+
'optional_query_parameter_list': optional_query_parameter_list,
118+
'api_response': api_response,
119+
'api_response_notes':
120+
"",
121+
'potential_status_codes_list': potential_status_codes_list,
122+
}
123+
return template_values

apis_v1/documentation_source/oppose_count_doc.py renamed to apis_v1/documentation_source/position_oppose_count_for_ballot_item_doc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# apis_v1/documentation_source/oppose_count_doc.py
1+
# apis_v1/documentation_source/position_oppose_count_for_ballot_item_doc.py
22
# Brought to you by We Vote. Be good.
33
# -*- coding: UTF-8 -*-
44

55

6-
def oppose_count_doc_template_values(url_root):
6+
def position_oppose_count_for_ballot_item_doc_template_values(url_root):
77
"""
8-
Show documentation about opposeCount
8+
Show documentation about positionOpposeCountForBallotItem
99
"""
1010
required_query_parameter_list = [
1111
{
@@ -73,12 +73,12 @@ def oppose_count_doc_template_values(url_root):
7373
'}'
7474

7575
template_values = {
76-
'api_name': 'opposeCount',
77-
'api_slug': 'opposeCount',
76+
'api_name': 'positionOpposeCountForBallotItem',
77+
'api_slug': 'positionOpposeCountForBallotItem',
7878
'api_introduction':
79-
"How many of the organizations that the voter follows, plus the friends of the voter, "
80-
"oppose this candidate or measure?",
81-
'try_now_link': 'apis_v1:opposeCountView',
79+
"A single number showing the total that oppose this Ballot Item (Candidate or Measure) from "
80+
"organizations, friends, and public figures this voter follows.",
81+
'try_now_link': 'apis_v1:positionOpposeCountForBallotItemView',
8282
'try_now_link_variables_dict': try_now_link_variables_dict,
8383
'url_root': url_root,
8484
'get_or_post': 'GET',

apis_v1/documentation_source/support_count_doc.py renamed to apis_v1/documentation_source/position_support_count_for_ballot_item_doc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# apis_v1/documentation_source/support_count_doc.py
1+
# apis_v1/documentation_source/position_support_count_for_ballot_item_doc.py
22
# Brought to you by We Vote. Be good.
33
# -*- coding: UTF-8 -*-
44

55

6-
def support_count_doc_template_values(url_root):
6+
def position_support_count_for_ballot_item_doc_template_values(url_root):
77
"""
8-
Show documentation about supportCount
8+
Show documentation about positionSupportCountForBallotItem
99
"""
1010
required_query_parameter_list = [
1111
{
@@ -73,12 +73,12 @@ def support_count_doc_template_values(url_root):
7373
'}'
7474

7575
template_values = {
76-
'api_name': 'supportCount',
77-
'api_slug': 'supportCount',
76+
'api_name': 'positionSupportCountForBallotItem',
77+
'api_slug': 'positionSupportCountForBallotItem',
7878
'api_introduction':
79-
"How many of the organizations that the voter follows, plus the friends of the voter, "
80-
"support this candidate or measure?",
81-
'try_now_link': 'apis_v1:supportCountView',
79+
"A single number showing the total supporters for this Ballot Item (Candidate or Measure) from "
80+
"organizations, friends, and public figures this voter follows.",
81+
'try_now_link': 'apis_v1:positionSupportCountForBallotItemView',
8282
'try_now_link_variables_dict': try_now_link_variables_dict,
8383
'url_root': url_root,
8484
'get_or_post': 'GET',

apis_v1/urls.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
url(r'^organizationRetrieve/', views.organization_retrieve_view, name='organizationRetrieveView'),
2626
url(r'^organizationSave/', views.organization_save_view, name='organizationSaveView'),
2727
url(r'^organizationSearch/', views.organization_search_view, name='organizationSearchView'),
28-
url(r'^organizationStopFollowing/', views.organization_stop_following_api_view, name='organizationStopFollowingView'),
29-
url(r'^opposeCount/', views.oppose_count_view, name='opposeCountView'),
28+
url(r'^organizationStopFollowing/',
29+
views.organization_stop_following_api_view, name='organizationStopFollowingView'),
3030
url(r'^positionLikeCount/', views.position_like_count_view, name='positionLikeCountView'),
31+
url(r'^positionListForBallotItem/', views.position_list_for_ballot_item_view, name='positionListForBallotItemView'),
32+
url(r'^positionOpposeCountForBallotItem/',
33+
views.position_oppose_count_for_ballot_item_view, name='positionOpposeCountForBallotItemView'),
3134
url(r'^positionRetrieve/', views.position_retrieve_view, name='positionRetrieveView'),
3235
url(r'^positionSave/', views.position_save_view, name='positionSaveView'),
33-
url(r'^supportCount/', views.support_count_view, name='supportCountView'),
36+
url(r'^positionSupportCountForBallotItem/',
37+
views.position_support_count_for_ballot_item_view, name='positionSupportCountForBallotItemView'),
3438
url(r'^voterAddressRetrieve/', views.voter_address_retrieve_view, name='voterAddressRetrieveView'),
3539
url(r'^voterAddressSave/', views.voter_address_save_view, name='voterAddressSaveView'),
3640
url(r'^voterBallotItemsRetrieve/', views.voter_ballot_items_retrieve_view, name='voterBallotItemsRetrieveView'),
@@ -78,11 +82,15 @@
7882
url(r'^docs/organizationSearch/$', views_docs.organization_search_doc_view, name='organizationSearchDocs'),
7983
url(r'^docs/organizationStopFollowing/',
8084
views_docs.organization_stop_following_doc_view, name='organizationStopFollowingDocs'),
81-
url(r'^docs/opposeCount/', views_docs.oppose_count_doc_view, name='opposeCountDocs'),
85+
url(r'^docs/positionListForBallotItem/',
86+
views_docs.position_list_for_ballot_item_doc_view, name='positionListForBallotItemDocs'),
87+
url(r'^docs/positionOpposeCountForBallotItem/',
88+
views_docs.position_oppose_count_for_ballot_item_doc_view, name='positionOpposeCountForBallotItemDocs'),
8289
url(r'^docs/positionLikeCount/$', views_docs.position_like_count_doc_view, name='positionLikeCountDocs'),
8390
url(r'^docs/positionRetrieve/$', views_docs.position_retrieve_doc_view, name='positionRetrieveDocs'),
8491
url(r'^docs/positionSave/$', views_docs.position_save_doc_view, name='positionSaveDocs'),
85-
url(r'^docs/supportCount/', views_docs.support_count_doc_view, name='supportCountDocs'),
92+
url(r'^docs/positionSupportCountForBallotItem/',
93+
views_docs.position_support_count_for_ballot_item_doc_view, name='positionSupportCountForBallotItemDocs'),
8694
url(r'^docs/voterAddressRetrieve/$', views_docs.voter_address_retrieve_doc_view, name='voterAddressRetrieveDocs'),
8795
url(r'^docs/voterAddressSave/$', views_docs.voter_address_save_doc_view, name='voterAddressSaveDocs'),
8896
url(r'^docs/voterBallotItemsRetrieve/$',

apis_v1/views.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
from office.controllers import office_retrieve_for_api
1717
from organization.controllers import organization_retrieve_for_api, organization_save_for_api, \
1818
organization_search_for_api
19-
from position.controllers import position_retrieve_for_api, position_save_for_api, \
20-
voter_position_retrieve_for_api, voter_position_comment_save_for_api
19+
from position.controllers import position_list_for_ballot_item_for_api, position_retrieve_for_api, \
20+
position_save_for_api, voter_position_retrieve_for_api, voter_position_comment_save_for_api
21+
from position.models import ANY_STANCE, SUPPORT, STILL_DECIDING, INFORMATION_ONLY, NO_STANCE, OPPOSE
2122
from position_like.controllers import position_like_count_for_api, voter_position_like_off_save_for_api, \
2223
voter_position_like_on_save_for_api, voter_position_like_status_retrieve_for_api
2324
from rest_framework.response import Response
2425
from rest_framework.views import APIView
2526
from star.controllers import voter_star_off_save_for_api, voter_star_on_save_for_api, voter_star_status_retrieve_for_api
26-
from support_oppose_deciding.controllers import oppose_count_for_api, support_count_for_api, \
27+
from support_oppose_deciding.controllers import position_oppose_count_for_ballot_item_for_api, \
28+
position_support_count_for_ballot_item_for_api, \
2729
voter_opposing_save, voter_stop_opposing_save, voter_stop_supporting_save, voter_supporting_save_for_api
2830
from voter.controllers import voter_address_retrieve_for_api, voter_address_save_for_api, voter_retrieve_list_for_api
2931
from voter.serializers import VoterSerializer
@@ -181,6 +183,30 @@ def organization_search_view(request):
181183
organization_email=organization_email)
182184

183185

186+
def position_list_for_ballot_item_view(request):
187+
"""
188+
Retrieve the number of orgs and friends that support this (positionSupportCountForBallotItem)
189+
:param request:
190+
:return:
191+
"""
192+
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
193+
office_id = request.GET.get('office_id', 0)
194+
candidate_id = request.GET.get('candidate_id', 0)
195+
measure_id = request.GET.get('measure_id', 0)
196+
stance = request.GET.get('stance', ANY_STANCE)
197+
if stance in(ANY_STANCE, SUPPORT, STILL_DECIDING, INFORMATION_ONLY, NO_STANCE, OPPOSE):
198+
stance_we_are_looking_for = stance
199+
else:
200+
stance_we_are_looking_for = ANY_STANCE
201+
show_positions_this_voter_follows = request.GET.get('show_positions_this_voter_follows', True)
202+
return position_list_for_ballot_item_for_api(voter_device_id=voter_device_id,
203+
office_id=office_id,
204+
candidate_id=candidate_id,
205+
measure_id=measure_id,
206+
stance_we_are_looking_for=stance_we_are_looking_for,
207+
show_positions_this_voter_follows=show_positions_this_voter_follows)
208+
209+
184210
def position_retrieve_view(request):
185211
"""
186212
Retrieve all of the details about a single position based on unique identifier
@@ -242,28 +268,28 @@ def position_save_view(request):
242268
return HttpResponse(json.dumps(results), content_type='application/json')
243269

244270

245-
def oppose_count_view(request):
271+
def position_oppose_count_for_ballot_item_view(request):
246272
"""
247-
Retrieve the number of orgs and friends that oppose this (opposeCount)
273+
Retrieve the number of orgs and friends that oppose this (positionOpposeCountForBallotItem)
248274
:param request:
249275
:return:
250276
"""
251277
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
252278
candidate_id = request.GET.get('candidate_id', 0)
253279
measure_id = request.GET.get('measure_id', 0)
254-
return oppose_count_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)
280+
return position_oppose_count_for_ballot_item_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)
255281

256282

257-
def support_count_view(request):
283+
def position_support_count_for_ballot_item_view(request):
258284
"""
259-
Retrieve the number of orgs and friends that support this (supportCount)
285+
Retrieve the number of orgs and friends that support this (positionSupportCountForBallotItem)
260286
:param request:
261287
:return:
262288
"""
263289
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
264290
candidate_id = request.GET.get('candidate_id', 0)
265291
measure_id = request.GET.get('measure_id', 0)
266-
return support_count_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)
292+
return position_support_count_for_ballot_item_for_api(voter_device_id=voter_device_id, candidate_id=candidate_id, measure_id=measure_id)
267293

268294

269295
def voter_address_retrieve_view(request):

apis_v1/views_docs.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from .documentation_source import ballot_item_options_retrieve_doc, candidate_retrieve_doc, candidates_retrieve_doc, \
66
device_id_generate_doc, \
77
elections_retrieve_doc, measure_retrieve_doc, office_retrieve_doc, \
8-
oppose_count_doc, organization_count_doc, \
8+
organization_count_doc, \
99
organization_follow_doc, organization_follow_ignore_doc, organization_stop_following_doc, \
1010
organization_retrieve_doc, organization_save_doc, organization_search_doc, \
11-
position_like_count_doc, position_retrieve_doc, position_save_doc, \
12-
support_count_doc, voter_address_retrieve_doc, voter_address_save_doc, \
11+
position_like_count_doc, position_list_for_ballot_item_doc, position_oppose_count_for_ballot_item_doc, \
12+
position_retrieve_doc, position_save_doc, \
13+
position_support_count_for_ballot_item_doc, voter_address_retrieve_doc, voter_address_save_doc, \
1314
voter_ballot_items_retrieve_doc, voter_ballot_items_retrieve_from_google_civic_doc, voter_count_doc, \
1415
voter_create_doc, voter_guide_possibility_retrieve_doc, voter_guide_possibility_save_doc, \
1516
voter_guides_to_follow_retrieve_doc, \
@@ -160,6 +161,15 @@ def organization_search_doc_view(request):
160161
return render(request, 'apis_v1/api_doc_page.html', template_values)
161162

162163

164+
def position_list_for_ballot_item_doc_view(request):
165+
"""
166+
Show documentation about positionListForBallotItem
167+
"""
168+
url_root = LOCALHOST_URL_ROOT
169+
template_values = position_list_for_ballot_item_doc.position_list_for_ballot_item_doc_template_values(url_root)
170+
return render(request, 'apis_v1/api_doc_page.html', template_values)
171+
172+
163173
def position_retrieve_doc_view(request):
164174
"""
165175
Show documentation about positionRetrieve
@@ -179,21 +189,23 @@ def position_save_doc_view(request):
179189
return render(request, 'apis_v1/api_doc_page.html', template_values)
180190

181191

182-
def oppose_count_doc_view(request):
192+
def position_oppose_count_for_ballot_item_doc_view(request):
183193
"""
184-
Show documentation about opposeCount
194+
Show documentation about positionOpposeCountForBallotItem
185195
"""
186196
url_root = LOCALHOST_URL_ROOT
187-
template_values = oppose_count_doc.oppose_count_doc_template_values(url_root)
197+
template_values = position_oppose_count_for_ballot_item_doc.\
198+
position_oppose_count_for_ballot_item_doc_template_values(url_root)
188199
return render(request, 'apis_v1/api_doc_page.html', template_values)
189200

190201

191-
def support_count_doc_view(request):
202+
def position_support_count_for_ballot_item_doc_view(request):
192203
"""
193-
Show documentation about supportCount
204+
Show documentation about positionSupportCountForBallotItem
194205
"""
195206
url_root = LOCALHOST_URL_ROOT
196-
template_values = support_count_doc.support_count_doc_template_values(url_root)
207+
template_values = position_support_count_for_ballot_item_doc.\
208+
position_support_count_for_ballot_item_doc_template_values(url_root)
197209
return render(request, 'apis_v1/api_doc_page.html', template_values)
198210

199211

organization/views_admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
handle_record_not_deleted_exception, handle_record_not_found_exception, handle_record_not_saved_exception
1616
from candidate.models import CandidateCampaign, CandidateCampaignList
1717
from election.models import Election
18-
from position.models import PositionEntered, PositionEnteredManager, INFORMATION_ONLY, OPPOSE, \
18+
from position.models import PositionEntered, PositionEnteredManager, ANY_STANCE, INFORMATION_ONLY, OPPOSE, \
1919
STILL_DECIDING, SUPPORT
2020
from rest_framework.views import APIView
2121
from rest_framework.response import Response

0 commit comments

Comments
 (0)