Skip to content
100 changes: 57 additions & 43 deletions apis_v1/documentation_source/voter_representatives_retrieve_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,68 +47,82 @@ def voter_representatives_retrieve_doc_template_values(url_root):
}

api_response = '{\n' \
' "is_from_substituted_address": boolean,\n' \
' "office_held_list_found": boolean,\n' \
' "offices_held_for_location_found": boolean,\n' \
' "offices_held_for_location_id": integer,\n' \
' "state_code": string,\n' \
' "status": string,\n' \
' "success": boolean,\n' \
' "voter_device_id": string (88 characters long),\n' \
' "google_civic_election_id": integer (if an error response),\n' \
' "original_text_city": string,\n' \
' "original_text_state": string,\n' \
' "original_text_zip": string,\n' \
' "text_for_map_search": string (if an error response),\n' \
' "substituted_address_nearby": string,\n' \
' "substituted_address_city": string,\n' \
' "substituted_address_state": string,\n' \
' "substituted_address_zip": string,\n' \
' "ballot_found": boolean (if an error response),\n' \
' "ballot_caveat": string (if an error response),\n' \
' "is_from_substituted_address": boolean,\n' \
' "is_from_test_ballot": boolean (if an error response),\n' \
' "text_for_map_search": string (if an error response),\n' \
' "voter_device_id": string (88 characters long),\n' \
' "voter_device_id_not_valid": boolean,\n' \
' "office_held_list": list\n' \
' [\n' \
' "id": integer,\n' \
' "we_vote_id": string,\n' \
' "office_held_display_name": string,\n' \
' "google_civic_election_id": integer,\n' \
' "google_ballot_placement": integer,\n' \
' "local_ballot_order": integer,\n' \
' "district_id": integer,\n' \
' "district_name": string,\n' \
' "ocd_division_id": string,\n' \
' "office_explanation_we_vote_id": string,\n' \
' "office_held_description": string,\n' \
' "office_held_facebook_url": string,\n' \
' "office_held_id": integer,\n' \
' "office_held_name": string,\n' \
' "office_held_twitter_handle": string,\n' \
' "office_held_url": string,\n' \
' "office_held_we_vote_id": string,\n' \
' "primary_party": string,\n' \
' "race_office_level": string,\n' \
' "state_code": string,\n' \
' "vote_usa_office_id": string,\n' \
' "representative_list": list\n' \
' [\n' \
' "id": integer,\n' \
' "we_vote_id": string,\n' \
' "office_held_display_name": string,\n' \
' "ballotpedia_candidate_id": integer,\n' \
' "ballotpedia_candidate_summary": string,\n' \
' "ballotpedia_candidate_url": string,\n' \
' "ballotpedia_person_id": integer,\n' \
' "candidate_email": string,\n' \
' "candidate_phone": string,\n' \
' "candidate_photo_url_large": string,\n' \
' "candidate_photo_url_medium": string,\n' \
' "candidate_photo_url_tiny": string,\n' \
' "candidate_url": string,\n' \
' "candidate_contact_form_url": string,\n' \
' "contest_office_id": integer,\n' \
' "contest_office_name": string,\n' \
' "contest_office_we_vote_id": string,\n' \
' "ballot_item_display_name": string,\n' \
' "facebook_url": string,\n' \
' "google_civic_election_id": integer,\n' \
' "instagram_handle": string,\n' \
' "id": integer,\n' \
' "instagram_followers_count": string,\n' \
' "maplight_id": string,\n' \
' "instagram_handle": string,\n' \
' "is_battleground_race_xxxx": boolean,\n' \
' "is_claimed_profile": boolean,\n' \
' "last_updated": string,\n' \
' "linked_campaignx_we_vote_id": string,\n' \
' "linkedin_url": string,\n' \
' "ocd_division_id": string,\n' \
' "order_on_ballot": integer,\n' \
' "party": string,\n' \
' "office_held_district_name": string,\n' \
' "office_held_id": integer,\n' \
' "office_held_name": string,\n' \
' "office_held_we_vote_id": string,\n' \
' "political_party": string,\n' \
' "politician_id": string,\n' \
' "politician_we_vote_id": string,\n' \
' "profile_image_background_color": string,\n' \
' "representative_contact_form_url": string,\n' \
' "representative_email": string,\n' \
' "representative_email2": string,\n' \
' "representative_email3": string,\n' \
' "representative_name": string,\n' \
' "representative_phone": string,\n' \
' "representative_phone2": string,\n' \
' "representative_phone3": string,\n' \
' "representative_photo_url_large": string,\n' \
' "representative_photo_url_medium": string,\n' \
' "representative_photo_url_tiny": string,\n' \
' "representative_url": string,\n' \
' "seo_friendly_path": string,\n' \
' "state_code": string,\n' \
' "twitter_url": string,\n' \
' "twitter_handle": string,\n' \
' "supporters_count": integer,\n' \
' "twitter_description": string,\n' \
' "twitter_handle": string,\n' \
' "twitter_followers_count": integer,\n' \
' "twitter_url": string,\n' \
' "vote_usa_office_id": string,\n' \
' "vote_usa_politician_id": string,\n' \
' "we_vote_id": string,\n' \
' "wikipedia_url": string,\n' \
' "youtube_url": string,\n' \
' "is_battleground_race": boolean,\n' \
' "withdrawn_from_election": boolean,\n' \
' "withdrawal_date": date,\n' \
' ],\n' \
' ],\n' \
'}'
Expand Down
10 changes: 4 additions & 6 deletions apis_v1/views/views_voter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from sms.models import SMSManager
from support_oppose_deciding.controllers import voter_opposing_save, voter_stop_opposing_save, \
voter_stop_supporting_save, voter_supporting_save
from voter.constants import MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS
from voter.controllers import delete_all_voter_information_permanently, \
voter_address_retrieve_for_api, voter_create_for_api, voter_merge_two_accounts_for_api, \
voter_merge_two_accounts_action_schedule, voter_photo_save_for_api, voter_retrieve_for_api, \
Expand Down Expand Up @@ -599,14 +600,13 @@ def voter_address_save_view(request): # voterAddressSave
pass
elif default_election_data_source_is_ballotpedia:
status += "VOTER_ADDRESS_SAVE-SHOULD_WE_USE_BALLOTPEDIA_API? "
length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)

# We don't want to call Ballotpedia when we just have "City, State ZIP". Since we don't always know
# whether we have a street address or not, then we use a simple string length cut-off.
if length_of_text_for_map_search > length_at_which_we_suspect_address_has_street:
if length_of_text_for_map_search > MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS:
status += "ADDRESS_SAVE_BALLOTPEDIA_TEXT_FOR_MAP_SEARCH_LONG_ENOUGH "
# 1a) Get ballot data from Ballotpedia for the actual VoterAddress
ballotpedia_retrieve_results = voter_ballot_items_retrieve_from_ballotpedia_for_api_v4(
Expand Down Expand Up @@ -663,15 +663,14 @@ def voter_address_save_view(request): # voterAddressSave
status += "NOT_REACHING_OUT_TO_BALLOTPEDIA_TEXT_NOT_LONG_ENOUGH "
elif default_election_data_source_is_ctcl:
status += "VOTER_ADDRESS_SAVE-USING_CTCL "
length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)

# We don't want to call CTCL when we just have "City, State ZIP".
# Since we don't always know whether we have a street address or not, then we use a
# simple string length cut-off.
if length_of_text_for_map_search > length_at_which_we_suspect_address_has_street:
if length_of_text_for_map_search > MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS:
status += "ADDRESS_SAVE_CTCL_TEXT_FOR_MAP_SEARCH_LONG_ENOUGH "
# 1a) Get ballot data for the actual VoterAddress
from import_export_google_civic.controllers import \
Expand Down Expand Up @@ -729,15 +728,14 @@ def voter_address_save_view(request): # voterAddressSave
status += "NOT_REACHING_OUT_TO_CTCL_TEXT_NOT_LONG_ENOUGH "
elif default_election_data_source_is_vote_usa:
status += "VOTER_ADDRESS_SAVE-USING_VOTE_USA "
length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)

# We don't want to call Vote-USA when we just have "City, State ZIP".
# Since we don't always know whether we have a street address or not, then we use a
# simple string length cut-off.
if length_of_text_for_map_search > length_at_which_we_suspect_address_has_street:
if length_of_text_for_map_search > MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS:
status += "ADDRESS_SAVE_VOTE_USA_TEXT_FOR_MAP_SEARCH_LONG_ENOUGH "
# 1a) Get ballot data for the actual VoterAddress
from import_export_google_civic.controllers import voter_ballot_items_retrieve_from_google_civic_2021
Expand Down
20 changes: 10 additions & 10 deletions ballot/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-

from datetime import datetime, timedelta
import datetime as the_other_datetime
import pytz

from geopy.geocoders import get_geocoder_for_service

from .models import BallotItemListManager, BallotItemManager, BallotReturnedListManager, BallotReturnedManager, \
CANDIDATE, find_best_previously_stored_ballot_returned, OFFICE, MEASURE, \
VoterBallotSaved, VoterBallotSavedManager
from candidate.models import CandidateListManager
from config.environment_variable_functions import get_environment_variable
from datetime import datetime, timedelta
import datetime as the_other_datetime
from election.controllers import retrieve_upcoming_election_id_list
from election.models import ElectionManager
from exception.models import handle_exception
Expand All @@ -19,13 +23,12 @@
from office.models import ContestOffice, ContestOfficeManager, ContestOfficeListManager, OfficeExplanation
from polling_location.models import PollingLocationManager
from politician.models import Politician
import pytz
from voter.constants import MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS
from voter.models import BALLOT_ADDRESS, VoterAddressManager, VoterDeviceLinkManager, VoterManager
import wevote_functions.admin
from wevote_functions.functions import convert_to_int, positive_value_exists, \
process_request_from_master, strip_html_tags
from wevote_functions.functions_date import generate_localized_datetime_from_obj, DATE_FORMAT_YMD
from geopy.geocoders import get_geocoder_for_service

logger = wevote_functions.admin.get_logger(__name__)

Expand Down Expand Up @@ -1684,7 +1687,6 @@ def generate_ballot_data(
pass
elif default_election_data_source_is_ballotpedia:
status += "SHOULD_WE_USE_BALLOTPEDIA_API? "
length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)
Expand All @@ -1706,7 +1708,7 @@ def generate_ballot_data(

# We don't want to call Ballotpedia when we just have "City, State ZIP". Since we don't always know
# whether we have a street address or not, then we use a simple string length cut-off.
if length_of_text_for_map_search > length_at_which_we_suspect_address_has_street:
if length_of_text_for_map_search > MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS:
status += "GENERATE_BALLOT_DATA_BP_TEXT_FOR_MAP_SEARCH_LONG_ENOUGH "
# 1a) Get ballot data from Ballotpedia for the actual VoterAddress
from import_export_ballotpedia.controllers import \
Expand Down Expand Up @@ -1758,14 +1760,13 @@ def generate_ballot_data(
status += "NOT_REACHING_OUT_TO_BALLOTPEDIA "
elif default_election_data_source_is_ctcl:
status += "SHOULD_WE_USE_CTCL_API? "
length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)

# We don't want to call CTCL when we just have "City, State ZIP". Since we don't always know
# whether we have a street address or not, then we use a simple string length cut-off.
if length_of_text_for_map_search > length_at_which_we_suspect_address_has_street:
if length_of_text_for_map_search > MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS:
status += "GENERATE_BALLOT_DATA_CTCL_TEXT_FOR_MAP_SEARCH_LONG_ENOUGH "
# 1a) Get ballot data for the actual VoterAddress
from import_export_google_civic.controllers import voter_ballot_items_retrieve_from_google_civic_2021
Expand Down Expand Up @@ -1861,15 +1862,14 @@ def generate_ballot_data(
return results
elif default_election_data_source_is_vote_usa:
status += "DEFAULT_ELECTION_SOURCE_IS_VOTE_USA "
length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)

# We don't want to call Vote-USA when we just have "City, State ZIP".
# Since we don't always know whether we have a street address or not, then we use a
# simple string length cut-off.
if length_of_text_for_map_search > length_at_which_we_suspect_address_has_street:
if length_of_text_for_map_search > MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS:
status += "GENERATE_BALLOT_DATA_VOTE_USA_TEXT_FOR_MAP_SEARCH_LONG_ENOUGH "
# 1a) Get ballot data for the actual VoterAddress
from import_export_google_civic.controllers import voter_ballot_items_retrieve_from_google_civic_2021
Expand Down
4 changes: 2 additions & 2 deletions ballot/controllers_upcoming_empty_election.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# -*- coding: UTF-8 -*-

from election.models import ElectionManager
from voter.constants import MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS
from voter.models import VoterAddressManager
import wevote_functions.admin
from wevote_functions.functions import extract_state_code_from_address_string, positive_value_exists
Expand Down Expand Up @@ -39,11 +40,10 @@ def retrieve_next_election_from_this_state(
if positive_value_exists(text_for_map_search):
state_code = extract_state_code_from_address_string(text_for_map_search)

length_at_which_we_suspect_address_has_street = 25
length_of_text_for_map_search = 0
if isinstance(text_for_map_search, str):
length_of_text_for_map_search = len(text_for_map_search)
text_for_map_search_too_short = length_of_text_for_map_search <= length_at_which_we_suspect_address_has_street
text_for_map_search_too_short = length_of_text_for_map_search <= MINIMUM_ADDRESS_LENGTH_TO_HAVE_STREET_ADDRESS
else:
state_code = ''

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 5.2.17 on 2026-11-25 01:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('candidate', '0050_alter_candidatecampaign_vote_usa_office_id_and_more'),
]

operations = [
migrations.AlterField(
model_name='candidatecampaign',
name='ballotpedia_candidate_name',
field=models.CharField(blank=True, db_index=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='candidatecampaign',
name='candidate_name',
field=models.CharField(db_index=True, max_length=255),
),
migrations.AlterField(
model_name='candidatecampaign',
name='contest_office_name',
field=models.CharField(blank=True, db_index=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='candidatecampaign',
name='google_civic_candidate_name',
field=models.CharField(db_index=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='candidatecampaign',
name='google_civic_candidate_name2',
field=models.CharField(db_index=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='candidatecampaign',
name='google_civic_candidate_name3',
field=models.CharField(db_index=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='candidatecampaign',
name='party',
field=models.CharField(blank=True, db_index=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='candidatecampaign',
name='twitter_name',
field=models.CharField(blank=True, db_index=True, max_length=255, null=True),
),
migrations.AddIndex(
model_name='candidatecampaign',
index=models.Index(fields=['ballotpedia_candidate_name', 'candidate_name', 'candidate_twitter_handle', 'candidate_twitter_handle2', 'candidate_twitter_handle3', 'contest_office_name', 'google_civic_candidate_name', 'party', 'twitter_name'], name='candidates_upcoming_election'),
),
]
Loading
Loading