def voter_ballot_items_retrieve_view(request): """ (voterBallotItemsRetrieve) Request a skeleton of ballot data for this voter location, so that the web_app has all of the ids it needs to make more requests for data about each ballot item. :param request: :return: """ voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id # If passed in, we want to look at google_civic_election_id = request.GET.get('google_civic_election_id', 0) 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 if positive_value_exists(use_test_election): google_civic_election_id = 2000 # The Google Civic API Test election elif not positive_value_exists(google_civic_election_id): # We look in the cookies for google_civic_election_id google_civic_election_id = get_google_civic_election_id_from_cookie(request) # This 'voter_ballot_items_retrieve_for_api' lives in apis_v1/controllers.py results = voter_ballot_items_retrieve_for_api(voter_device_id, google_civic_election_id) response = HttpResponse(json.dumps(results['json_data']), 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 voter_guides_to_follow_retrieve_view(request): """ Retrieve a list of voter_guides that a voter might want to follow :param request: :return: """ voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id # We look in the cookies for google_civic_election_id google_civic_election_id = get_google_civic_election_id_from_cookie(request) return voter_guides_to_follow_retrieve(voter_device_id, google_civic_election_id)
def voter_guides_to_follow_retrieve_view(request): """ Retrieve a list of voter_guides that a voter might want to follow (voterGuidesToFollow) :param request: :return: """ voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id kind_of_ballot_item = request.GET.get('kind_of_ballot_item', '') ballot_item_we_vote_id = request.GET.get('ballot_item_we_vote_id', '') google_civic_election_id = request.GET.get('google_civic_election_id', 0) 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 maximum_number_to_retrieve = get_maximum_number_to_retrieve_from_request(request) if positive_value_exists(ballot_item_we_vote_id): google_civic_election_id = 0 if positive_value_exists(use_test_election): google_civic_election_id = 2000 # The Google Civic API Test election elif not positive_value_exists(google_civic_election_id): # We look in the cookies for google_civic_election_id google_civic_election_id = get_google_civic_election_id_from_cookie(request) # TODO DALE Consider getting this to work # # If the google_civic_election_id was found cached in a cookie and passed in, use that # # If not, fetch it for this voter by looking in the BallotItem table # if not positive_value_exists(google_civic_election_id): # google_civic_election_id = fetch_google_civic_election_id_for_voter_id(voter_id) results = voter_guides_to_follow_retrieve_for_api(voter_device_id, kind_of_ballot_item, ballot_item_we_vote_id, google_civic_election_id, maximum_number_to_retrieve) response = HttpResponse(json.dumps(results['json_data']), content_type='application/json') # Save google_civic_election_id with fresh version that we retrieved from BallotItem table (if not passed in) set_google_civic_election_id_cookie(request, response, results['google_civic_election_id']) return response
def voter_ballot_items_retrieve_view(request): voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id # We look in the cookies for google_civic_election_id google_civic_election_id = get_google_civic_election_id_from_cookie(request) # This 'voter_ballot_items_retrieve' lives in ballot/controllers.py return voter_ballot_items_retrieve(voter_device_id, google_civic_election_id)