Skip to content

Commit 253c401

Browse files
authored
Merge pull request wevote#1827 from DaleMcGrew/Dale_WVS_May19-2022
New API messageToFriendSend.
2 parents fac7a0a + 8afa41d commit 253c401

File tree

10 files changed

+538
-6
lines changed

10 files changed

+538
-6
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# apis_v1/documentation_source/message_to_friend_send_doc.py
2+
# Brought to you by We Vote. Be good.
3+
# -*- coding: UTF-8 -*-
4+
5+
6+
def doc_template_values(url_root):
7+
"""
8+
Show documentation about messageToFriendSend
9+
"""
10+
required_query_parameter_list = [
11+
{
12+
'name': 'voter_device_id',
13+
'value': 'string', # 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': 'other_voter_we_vote_id',
23+
'value': 'string', # boolean, integer, long, string
24+
'description': 'The voter to send the friend invitation to.',
25+
},
26+
]
27+
optional_query_parameter_list = [
28+
{
29+
'name': 'message_to_send',
30+
'value': 'string', # boolean, integer, long, string
31+
'description': 'An optional message to send.',
32+
},
33+
]
34+
35+
potential_status_codes_list = [
36+
{
37+
'code': 'VALID_VOTER_DEVICE_ID_MISSING',
38+
'description': 'Cannot proceed. A valid voter_device_id parameter was not included.',
39+
},
40+
{
41+
'code': 'VALID_VOTER_ID_MISSING',
42+
'description': 'Cannot proceed. A valid voter_id was not found.',
43+
},
44+
]
45+
46+
try_now_link_variables_dict = {
47+
# 'organization_we_vote_id': 'wv85org1',
48+
}
49+
50+
api_response = '{\n' \
51+
' "status": string,\n' \
52+
' "success": boolean,\n' \
53+
' "description_of_send_status": string,\n' \
54+
'}'
55+
56+
template_values = {
57+
'api_name': 'messageToFriendSend',
58+
'api_slug': 'messageToFriendSend',
59+
'api_introduction':
60+
"Send a We Vote friend a message.",
61+
'try_now_link': 'apis_v1:messageToFriendSendView',
62+
'try_now_link_variables_dict': try_now_link_variables_dict,
63+
'url_root': url_root,
64+
'get_or_post': 'GET',
65+
'required_query_parameter_list': required_query_parameter_list,
66+
'optional_query_parameter_list': optional_query_parameter_list,
67+
'api_response': api_response,
68+
'api_response_notes':
69+
"",
70+
'potential_status_codes_list': potential_status_codes_list,
71+
}
72+
return template_values

apis_v1/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
re_path(r'^measureListForUpcomingElectionsRetrieve/',
153153
views_measure.measure_list_for_upcoming_elections_retrieve_api_view,
154154
name='measureListForUpcomingElectionsRetrieveView'),
155+
re_path(r'^messageToFriendSend/', views_friend.message_to_friend_send_view, name='messageToFriendSendView'),
155156
re_path(r'^officeRetrieve/', views_misc.office_retrieve_view, name='officeRetrieveView'),
156157
re_path(r'^officesSyncOut/', offices_sync_out_view, name='officesSyncOutView'),
157158
re_path(r'^organizationAnalyticsByVoter/',
@@ -527,6 +528,8 @@
527528
re_path(r'^docs/measureListForUpcomingElectionsRetrieve/$',
528529
views_docs.measure_list_for_upcoming_elections_retrieve_doc_view,
529530
name='measureListForUpcomingElectionsRetrieveDocs'),
531+
re_path(r'^docs/messageToFriendSend/$',
532+
views_docs.message_to_friend_send_doc_view, name='messageToFriendSendDocs'),
530533
re_path(r'^docs/officeRetrieve/$', views_docs.office_retrieve_doc_view, name='officeRetrieveDocs'),
531534
re_path(r'^docs/officesSyncOut/$', views_docs.offices_sync_out_doc_view, name='officesSyncOutDocs'),
532535
re_path(r'^docs/organizationAnalyticsByVoter/$', views_docs.organization_analytics_by_voter_doc_view,

apis_v1/views/views_docs.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
issues_followed_retrieve_doc, issues_retrieve_doc, issues_under_ballot_items_retrieve_doc, issues_sync_out_doc, \
2626
issues_linked_to_organization_doc, issues_to_link_to_for_organization_doc, \
2727
measure_retrieve_doc, measures_sync_out_doc, measure_list_for_upcoming_elections_retrieve_doc, \
28-
office_retrieve_doc, offices_sync_out_doc, organization_analytics_by_voter_doc, \
28+
message_to_friend_send_doc, office_retrieve_doc, offices_sync_out_doc, organization_analytics_by_voter_doc, \
2929
organization_count_doc, organization_daily_metrics_sync_out_doc, \
3030
organization_election_metrics_sync_out_doc, organizations_followed_retrieve_doc, \
3131
organization_follow_doc, organization_follow_ignore_doc, organization_index_doc, organizations_found_on_url_doc, \
@@ -78,13 +78,27 @@
7878
voter_update_doc, voter_verify_secret_code_doc, email_ballot_data_doc
7979
from config.base import get_environment_variable
8080
from django.contrib.messages import get_messages
81+
import importlib
8182
from django.shortcuts import render
8283
from voter.models import voter_setup
8384
from wevote_functions.functions import get_voter_api_device_id, set_voter_api_device_id, positive_value_exists
8485

8586
WE_VOTE_SERVER_ROOT_URL = get_environment_variable("WE_VOTE_SERVER_ROOT_URL")
8687

8788

89+
# def api_doc_view(request, api_name=''):
90+
# """
91+
# TODO: I would like to figure this out so we don't have to have so many custom doc functions!
92+
# """
93+
# url_root = WE_VOTE_SERVER_ROOT_URL
94+
# full_doc_file_name = "{api_name}_doc".format(api_name=api_name)
95+
# doc_file = importlib.import_module(full_doc_file_name)
96+
# from apis_v1.documentation_source import doc_file
97+
# template_values = full_doc_file_name.doc_template_values(url_root)
98+
# template_values['voter_api_device_id'] = get_voter_api_device_id(request)
99+
# return render(request, 'apis_v1/api_doc_page.html', template_values)
100+
101+
88102
def activity_comment_save_doc_view(request):
89103
"""
90104
Show documentation about activityCommentSave
@@ -650,6 +664,16 @@ def measure_list_for_upcoming_elections_retrieve_doc_view(request):
650664
return render(request, 'apis_v1/api_doc_page.html', template_values)
651665

652666

667+
def message_to_friend_send_doc_view(request):
668+
"""
669+
Show documentation about messageToFriendSend
670+
"""
671+
url_root = WE_VOTE_SERVER_ROOT_URL
672+
template_values = message_to_friend_send_doc.doc_template_values(url_root)
673+
template_values['voter_api_device_id'] = get_voter_api_device_id(request)
674+
return render(request, 'apis_v1/api_doc_page.html', template_values)
675+
676+
653677
def office_retrieve_doc_view(request):
654678
"""
655679
Show documentation about candidatesRetrieve

apis_v1/views/views_friend.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
from friend.controllers import friend_invitation_by_email_send_for_api, friend_invitation_by_email_verify_for_api, \
77
friend_invitation_by_we_vote_id_send_for_api, friend_invite_response_for_api, friend_list_for_api, \
88
friend_lists_all_for_api, friend_invitation_by_facebook_send_for_api, \
9-
friend_invitation_by_facebook_verify_for_api, friend_invitation_information_for_api
9+
friend_invitation_by_facebook_verify_for_api, friend_invitation_information_for_api, message_to_friend_send_for_api
1010
from friend.models import ACCEPT_INVITATION, CURRENT_FRIENDS, DELETE_INVITATION_EMAIL_SENT_BY_ME, \
1111
DELETE_INVITATION_VOTER_SENT_BY_ME, \
1212
FRIENDS_IN_COMMON, FRIEND_INVITATIONS_PROCESSED, FRIEND_INVITATIONS_SENT_TO_ME, FRIEND_INVITATIONS_SENT_BY_ME, \
1313
FRIEND_INVITATIONS_WAITING_FOR_VERIFICATION, \
1414
IGNORED_FRIEND_INVITATIONS, IGNORE_INVITATION, IGNORE_SUGGESTION, \
1515
SUGGESTED_FRIEND_LIST, UNFRIEND_CURRENT_FRIEND
1616
import json
17-
import wevote_functions.admin
18-
from wevote_functions.functions import get_voter_device_id
17+
from wevote_functions.functions import get_voter_device_id, positive_value_exists, wevote_functions
1918

2019

2120
logger = wevote_functions.admin.get_logger(__name__)
@@ -249,3 +248,30 @@ def friend_lists_all_view(request): # friendList
249248
'suggested_friends': results['suggested_friends'],
250249
}
251250
return HttpResponse(json.dumps(json_data), content_type='application/json')
251+
252+
253+
def message_to_friend_send_view(request): # messageToFriendSend
254+
"""
255+
256+
:param request:
257+
:return:
258+
"""
259+
voter_device_id = get_voter_device_id(request) # We standardize how we take in the voter_device_id
260+
election_date_in_future_formatted = request.GET.get('election_date_in_future_formatted', "")
261+
election_date_is_today = positive_value_exists(request.GET.get('election_date_is_today', False))
262+
message_to_friend = request.GET.get('message_to_friend', "")
263+
other_voter_we_vote_id = request.GET.get('other_voter_we_vote_id', "")
264+
hostname = request.GET.get('hostname', "")
265+
results = message_to_friend_send_for_api(
266+
election_date_in_future_formatted=election_date_in_future_formatted,
267+
election_date_is_today=election_date_is_today,
268+
other_voter_we_vote_id=other_voter_we_vote_id,
269+
message_to_friend=message_to_friend,
270+
voter_device_id=voter_device_id,
271+
web_app_root_url=hostname)
272+
json_data = {
273+
'status': results['status'],
274+
'success': results['success'],
275+
'voter_device_id': voter_device_id,
276+
}
277+
return HttpResponse(json.dumps(json_data), content_type='application/json')

email_outbound/functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .models import CAMPAIGNX_FRIEND_HAS_SUPPORTED_TEMPLATE, CAMPAIGNX_NEWS_ITEM_TEMPLATE, \
66
CAMPAIGNX_SUPER_SHARE_ITEM_TEMPLATE, CAMPAIGNX_SUPPORTER_INITIAL_RESPONSE_TEMPLATE, \
77
FRIEND_ACCEPTED_INVITATION_TEMPLATE, FRIEND_INVITATION_TEMPLATE, LINK_TO_SIGN_IN_TEMPLATE, \
8-
NOTICE_FRIEND_ENDORSEMENTS_TEMPLATE, NOTICE_VOTER_DAILY_SUMMARY_TEMPLATE, \
8+
MESSAGE_TO_FRIEND_TEMPLATE, NOTICE_FRIEND_ENDORSEMENTS_TEMPLATE, NOTICE_VOTER_DAILY_SUMMARY_TEMPLATE, \
99
SEND_BALLOT_TO_SELF, SEND_BALLOT_TO_FRIENDS, SIGN_IN_CODE_EMAIL_TEMPLATE, VERIFY_EMAIL_ADDRESS_TEMPLATE
1010
from django.template.loader import get_template
1111
from django.template import Context
@@ -53,6 +53,11 @@ def get_template_filename(kind_of_email_template, text_or_html):
5353
return "link_to_sign_in.html"
5454
else:
5555
return "link_to_sign_in.txt"
56+
elif kind_of_email_template == MESSAGE_TO_FRIEND_TEMPLATE:
57+
if text_or_html == "HTML":
58+
return "message_to_friend.html"
59+
else:
60+
return "message_to_friend.txt"
5661
elif kind_of_email_template == NOTICE_FRIEND_ENDORSEMENTS_TEMPLATE:
5762
if text_or_html == "HTML":
5863
return "notice_friend_endorsements.html"

email_outbound/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
FRIEND_INVITATION_TEMPLATE = 'FRIEND_INVITATION_TEMPLATE'
1919
GENERIC_EMAIL_TEMPLATE = 'GENERIC_EMAIL_TEMPLATE'
2020
LINK_TO_SIGN_IN_TEMPLATE = 'LINK_TO_SIGN_IN_TEMPLATE'
21+
MESSAGE_TO_FRIEND_TEMPLATE = 'MESSAGE_TO_FRIEND_TEMPLATE'
2122
NOTICE_FRIEND_ENDORSEMENTS_TEMPLATE = 'NOTICE_FRIEND_ENDORSEMENTS_TEMPLATE'
2223
NOTICE_VOTER_DAILY_SUMMARY_TEMPLATE = 'NOTICE_VOTER_DAILY_SUMMARY_TEMPLATE'
2324
VERIFY_EMAIL_ADDRESS_TEMPLATE = 'VERIFY_EMAIL_ADDRESS_TEMPLATE'
@@ -29,6 +30,7 @@
2930
(FRIEND_ACCEPTED_INVITATION_TEMPLATE, 'Accept an invitation to be a Friend'),
3031
(FRIEND_INVITATION_TEMPLATE, 'Invite Friend'),
3132
(LINK_TO_SIGN_IN_TEMPLATE, 'Link to sign in.'),
33+
(MESSAGE_TO_FRIEND_TEMPLATE, 'Message to friend'),
3234
(NOTICE_FRIEND_ENDORSEMENTS_TEMPLATE, 'New opinion from Friend.'),
3335
(NOTICE_VOTER_DAILY_SUMMARY_TEMPLATE, 'Daily summary of activity for the voter.'),
3436
(VERIFY_EMAIL_ADDRESS_TEMPLATE, 'Verify Senders Email Address'),

0 commit comments

Comments
 (0)