def voter_ballot_items_retrieve_from_google_civic_view(request): voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id text_for_map_search = request.GET.get('text_for_map_search', '') use_test_election = request.GET.get('use_test_election', False) use_test_election = False if use_test_election == 'false' else use_test_election use_test_election = False if use_test_election == 'False' else use_test_election results = voter_ballot_items_retrieve_from_google_civic_for_api( voter_device_id, text_for_map_search, use_test_election) response = HttpResponse(json.dumps(results), content_type='application/json') # Save google_civic_election_id in the cookie so the interface knows google_civic_election_id_from_ballot_retrieve = results['google_civic_election_id'] if positive_value_exists(google_civic_election_id_from_ballot_retrieve): set_google_civic_election_id_cookie(request, response, results['google_civic_election_id']) return response
def generate_ballot_data(voter_device_link, voter_address): voter_device_id = voter_device_link.voter_device_id voter_id = voter_device_link.voter_id voter_ballot_saved_manager = VoterBallotSavedManager() if not positive_value_exists(voter_id): results = { 'status': "VOTER_NOT_FOUND_FROM_VOTER_DEVICE_ID", 'success': False, 'google_civic_election_id': 0, 'voter_ballot_saved_found': False, 'voter_ballot_saved': VoterBallotSaved() } return results # If a partial address doesn't exist, exit because we can't generate a ballot without an address if not positive_value_exists(voter_address.text_for_map_search): results = { 'status': "VOTER_ADDRESS_BLANK", 'success': True, 'google_civic_election_id': 0, 'voter_ballot_saved_found': False, 'voter_ballot_saved': None, } return results # 1) Get ballot data from Google Civic for the actual VoterAddress text_for_map_search = voter_address.text_for_map_search use_test_election = False results = voter_ballot_items_retrieve_from_google_civic_for_api(voter_device_id, text_for_map_search, use_test_election) if results['google_civic_election_id']: is_from_substituted_address = False substituted_address_nearby = '' is_from_test_address = False # We update the voter_address with this google_civic_election_id outside of this function # Save the meta information for this ballot data save_results = voter_ballot_saved_manager.create_voter_ballot_saved( voter_id, results['google_civic_election_id'], results['election_date_text'], results['election_description_text'], results['text_for_map_search'], substituted_address_nearby, is_from_substituted_address, is_from_test_address ) results = { 'status': save_results['status'], 'success': save_results['success'], 'google_civic_election_id': save_results['google_civic_election_id'], 'voter_ballot_saved_found': save_results['voter_ballot_saved_found'], 'voter_ballot_saved': save_results['voter_ballot_saved'], } return results # 2) Copy ballot data from a nearby address, previously retrieved from Google Civic and cached within We Vote copy_results = copy_existing_ballot_items_from_stored_ballot(voter_id, text_for_map_search) if copy_results['ballot_returned_copied']: is_from_substituted_address = True is_from_test_address = False save_results = voter_ballot_saved_manager.create_voter_ballot_saved( voter_id, copy_results['google_civic_election_id'], copy_results['election_date_text'], copy_results['election_description_text'], text_for_map_search, copy_results['substituted_address_nearby'], is_from_substituted_address, is_from_test_address ) results = { 'status': save_results['status'], 'success': save_results['success'], 'google_civic_election_id': save_results['google_civic_election_id'], 'voter_ballot_saved_found': save_results['voter_ballot_saved_found'], 'voter_ballot_saved': save_results['voter_ballot_saved'], } return results # 3) Get test ballot data from Google Civic use_test_election = True results = voter_ballot_items_retrieve_from_google_civic_for_api(voter_device_id, text_for_map_search, use_test_election) if results['google_civic_election_id']: is_from_substituted_address = False substituted_address_nearby = '' is_from_test_address = True # Since this is a test address, we don't want to save the google_civic_election_id (of 2000) # with the voter_address save_results = voter_ballot_saved_manager.create_voter_ballot_saved( voter_id, results['google_civic_election_id'], results['election_date_text'], results['election_description_text'], results['text_for_map_search'], substituted_address_nearby, is_from_substituted_address, is_from_test_address ) results = { 'status': save_results['status'], 'success': save_results['success'], 'google_civic_election_id': save_results['google_civic_election_id'], 'voter_ballot_saved_found': save_results['voter_ballot_saved_found'], 'voter_ballot_saved': save_results['voter_ballot_saved'], } return results results = { 'status': "UNABLE_TO_GENERATE_BALLOT_DATA", 'success': True, 'google_civic_election_id': 0, 'voter_ballot_saved_found': False, 'voter_ballot_saved': None, } return results
def generate_ballot_data(voter_device_link, voter_address): voter_device_id = voter_device_link.voter_device_id voter_id = voter_device_link.voter_id voter_ballot_saved_manager = VoterBallotSavedManager() if not positive_value_exists(voter_id): results = { 'status': "VOTER_NOT_FOUND_FROM_VOTER_DEVICE_ID", 'success': False, 'google_civic_election_id': 0, 'voter_ballot_saved_found': False, 'voter_ballot_saved': VoterBallotSaved() } return results # If a partial address doesn't exist, exit because we can't generate a ballot without an address if not positive_value_exists(voter_address.text_for_map_search): results = { 'status': "VOTER_ADDRESS_BLANK", 'success': True, 'google_civic_election_id': 0, 'voter_ballot_saved_found': False, 'voter_ballot_saved': None, } return results # 1) Get ballot data from Google Civic for the actual VoterAddress text_for_map_search = voter_address.text_for_map_search use_test_election = False results = voter_ballot_items_retrieve_from_google_civic_for_api( voter_device_id, text_for_map_search, use_test_election) if results['google_civic_election_id']: is_from_substituted_address = False substituted_address_nearby = '' is_from_test_address = False # We update the voter_address with this google_civic_election_id outside of this function # Save the meta information for this ballot data save_results = voter_ballot_saved_manager.create_voter_ballot_saved( voter_id, results['google_civic_election_id'], results['election_date_text'], results['election_description_text'], results['text_for_map_search'], substituted_address_nearby, is_from_substituted_address, is_from_test_address) results = { 'status': save_results['status'], 'success': save_results['success'], 'google_civic_election_id': save_results['google_civic_election_id'], 'voter_ballot_saved_found': save_results['voter_ballot_saved_found'], 'voter_ballot_saved': save_results['voter_ballot_saved'], } return results # 2) Copy ballot data from a nearby address, previously retrieved from Google Civic and cached within We Vote copy_results = copy_existing_ballot_items_from_stored_ballot( voter_id, text_for_map_search) if copy_results['ballot_returned_copied']: is_from_substituted_address = True is_from_test_address = False save_results = voter_ballot_saved_manager.create_voter_ballot_saved( voter_id, copy_results['google_civic_election_id'], copy_results['election_date_text'], copy_results['election_description_text'], text_for_map_search, copy_results['substituted_address_nearby'], is_from_substituted_address, is_from_test_address) results = { 'status': save_results['status'], 'success': save_results['success'], 'google_civic_election_id': save_results['google_civic_election_id'], 'voter_ballot_saved_found': save_results['voter_ballot_saved_found'], 'voter_ballot_saved': save_results['voter_ballot_saved'], } return results # 3) Get test ballot data from Google Civic use_test_election = True results = voter_ballot_items_retrieve_from_google_civic_for_api( voter_device_id, text_for_map_search, use_test_election) if results['google_civic_election_id']: is_from_substituted_address = False substituted_address_nearby = '' is_from_test_address = True # Since this is a test address, we don't want to save the google_civic_election_id (of 2000) # with the voter_address save_results = voter_ballot_saved_manager.create_voter_ballot_saved( voter_id, results['google_civic_election_id'], results['election_date_text'], results['election_description_text'], results['text_for_map_search'], substituted_address_nearby, is_from_substituted_address, is_from_test_address) results = { 'status': save_results['status'], 'success': save_results['success'], 'google_civic_election_id': save_results['google_civic_election_id'], 'voter_ballot_saved_found': save_results['voter_ballot_saved_found'], 'voter_ballot_saved': save_results['voter_ballot_saved'], } return results results = { 'status': "UNABLE_TO_GENERATE_BALLOT_DATA", 'success': True, 'google_civic_election_id': 0, 'voter_ballot_saved_found': False, 'voter_ballot_saved': None, } return results
def voter_address_save_view(request): """ Save or update an address for this voter :param request: :return: """ status = '' voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id try: text_for_map_search = request.POST['text_for_map_search'] text_for_map_search = text_for_map_search.strip() address_variable_exists = True except KeyError: text_for_map_search = '' address_variable_exists = False results = voter_address_save_for_api(voter_device_id, text_for_map_search, address_variable_exists) voter_address_saved = True if results['success'] else False if not positive_value_exists(text_for_map_search): json_data = { 'status': results['status'], 'success': results['success'], 'voter_device_id': voter_device_id, 'text_for_map_search': text_for_map_search, 'voter_address_saved': voter_address_saved, 'google_civic_election_id': 0, } response = HttpResponse(json.dumps(json_data), content_type='application/json') # Reset google_civic_election_id to 0 whenever we save an empty address google_civic_election_id = 0 set_google_civic_election_id_cookie(request, response, google_civic_election_id) return response status += results['status'] + ", " # If here, we saved a valid address google_civic_election_id = get_google_civic_election_id_from_cookie(request) if positive_value_exists(google_civic_election_id): google_civic_election_id = convert_to_int(google_civic_election_id) if google_civic_election_id == 2000: use_test_election = True else: use_test_election = False else: use_test_election = False results = voter_ballot_items_retrieve_from_google_civic_for_api(voter_device_id, text_for_map_search, use_test_election) status += results['status'] google_civic_election_id = results['google_civic_election_id'] json_data = { 'status': status, 'success': results['success'], 'voter_device_id': voter_device_id, 'text_for_map_search': text_for_map_search, 'voter_address_saved': voter_address_saved, 'google_civic_election_id': google_civic_election_id, } response = HttpResponse(json.dumps(json_data), content_type='application/json') # Reset google_civic_election_id to the new election whenever we save a new address set_google_civic_election_id_cookie(request, response, google_civic_election_id) return response