def quick_info_summary_view(request, quick_info_id): # TODO to be updated authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) quick_info_id = convert_to_int(quick_info_id) quick_info_on_stage_found = False quick_info_on_stage = QuickInfo() try: quick_info_on_stage = QuickInfo.objects.get(id=quick_info_id) quick_info_on_stage_found = True except QuickInfo.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except QuickInfo.DoesNotExist: # This is fine, create new pass if quick_info_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'quick_info': quick_info_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'quick_info/quick_info_summary.html', template_values)
def office_edit_view(request, office_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) office_id = convert_to_int(office_id) google_civic_election_id = request.GET.get('google_civic_election_id', 0) office_on_stage_found = False try: office_on_stage = ContestOffice.objects.get(id=office_id) office_on_stage_found = True except ContestOffice.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except ContestOffice.DoesNotExist: # This is fine, create new pass if office_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'office': office_on_stage, 'google_civic_election_id': google_civic_election_id, } else: template_values = { 'messages_on_stage': messages_on_stage, 'google_civic_election_id': google_civic_election_id, } return render(request, 'office/office_edit.html', template_values)
def office_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = convert_to_int(request.GET.get('google_civic_election_id', 0)) office_list_manager = ContestOfficeListManager() updated_office_list = [] results = office_list_manager.retrieve_all_offices_for_upcoming_election(google_civic_election_id, True) if results['office_list_found']: office_list = results['office_list_objects'] for office in office_list: office.candidate_count = fetch_candidate_count_for_office(office.id) updated_office_list.append(office) election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'office_list': updated_office_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'office/office_list.html', template_values)
def quick_info_master_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) kind_of_ballot_item = request.GET.get('kind_of_ballot_item', "") language = request.GET.get('language', ENGLISH) quick_info_master_list = QuickInfoMaster.objects.order_by( 'id') # This order_by is temp if positive_value_exists(kind_of_ballot_item): quick_info_master_list = quick_info_master_list.filter( kind_of_ballot_item=kind_of_ballot_item) if positive_value_exists(language): quick_info_master_list = quick_info_master_list.filter( language=language) template_values = { 'messages_on_stage': messages_on_stage, 'quick_info_master_list': quick_info_master_list, 'language_choices': LANGUAGE_CHOICES, 'ballot_item_choices': KIND_OF_BALLOT_ITEM_CHOICES, 'kind_of_ballot_item': kind_of_ballot_item, 'language': language, } return render(request, 'quick_info/quick_info_master_list.html', template_values)
def quick_info_master_new_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # If the voter tried to submit an entry, and it didn't save, capture the changed values for display kind_of_ballot_item = request.POST.get('kind_of_ballot_item', "") language = request.POST.get('language', ENGLISH) info_text = request.POST.get('info_text', "") info_html = request.POST.get('info_html', "") master_entry_name = request.POST.get('master_entry_name', "") more_info_credit = request.POST.get('more_info_credit', "") more_info_url = request.POST.get('more_info_url', "") quick_info_master = QuickInfoMaster() quick_info_master.kind_of_ballot_item = kind_of_ballot_item quick_info_master.language = language quick_info_master.master_entry_name = master_entry_name quick_info_master.more_info_credit = more_info_credit quick_info_master.more_info_url = more_info_url quick_info_master.info_text = info_text quick_info_master.info_html = info_html messages_on_stage = get_messages(request) template_values = { 'messages_on_stage': messages_on_stage, 'language_choices': LANGUAGE_CHOICES, 'ballot_item_choices': KIND_OF_BALLOT_ITEM_CHOICES, 'quick_info_master': quick_info_master, } return render(request, 'quick_info/quick_info_master_edit.html', template_values)
def election_edit_view(request, election_local_id): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) election_local_id = convert_to_int(election_local_id) election_on_stage_found = False election_on_stage = Election() try: election_on_stage = Election.objects.get(id=election_local_id) election_on_stage_found = True except Election.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except Election.DoesNotExist: # This is fine, create new pass if election_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'election': election_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, "election/election_edit.html", template_values)
def retrieve_twitter_data_for_all_organizations_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) organization_state_code = request.GET.get('organization_state', '') google_civic_election_id = request.GET.get('google_civic_election_id', 0) first_retrieve_only = request.GET.get('first_retrieve_only', True) results = retrieve_twitter_data_for_all_organizations(state_code=organization_state_code, google_civic_election_id=google_civic_election_id, first_retrieve_only=first_retrieve_only) if not results['success']: messages.add_message(request, messages.INFO, results['status']) else: number_of_twitter_accounts_queried = results['number_of_twitter_accounts_queried'] number_of_organizations_updated = results['number_of_organizations_updated'] messages.add_message(request, messages.INFO, "Twitter accounts queried: {number_of_twitter_accounts_queried}, " "Organizations updated: {number_of_organizations_updated}".format( number_of_twitter_accounts_queried=number_of_twitter_accounts_queried, number_of_organizations_updated=number_of_organizations_updated)) return HttpResponseRedirect(reverse('organization:organization_list', args=()) + '?organization_state=' + organization_state_code)
def sync_data_with_master_servers_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) google_civic_election_id = request.GET.get('google_civic_election_id', '') state_code = request.GET.get('state_code', '') election_list = Election.objects.order_by('-election_day_text') state_list = STATE_CODE_MAP sorted_state_list = sorted(state_list.items()) template_values = { 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, 'state_list': sorted_state_list, 'state_code': state_code, 'ballot_items_sync_url': BALLOT_ITEMS_SYNC_URL, 'ballot_returned_sync_url': BALLOT_RETURNED_SYNC_URL, 'candidates_sync_url': CANDIDATES_SYNC_URL, 'elections_sync_url': ELECTIONS_SYNC_URL, 'measures_sync_url': MEASURES_SYNC_URL, 'offices_sync_url': OFFICES_SYNC_URL, 'organizations_sync_url': ORGANIZATIONS_SYNC_URL, 'polling_locations_sync_url': POLLING_LOCATIONS_SYNC_URL, 'positions_sync_url': POSITIONS_SYNC_URL, 'voter_guides_sync_url': VOTER_GUIDES_SYNC_URL, } response = render(request, 'admin_tools/sync_data_with_master_dashboard.html', template_values) return response
def voter_guide_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) google_civic_election_id = convert_to_int(request.GET.get('google_civic_election_id', 0)) voter_guide_list = [] voter_guide_list_object = VoterGuideList() if positive_value_exists(google_civic_election_id): results = voter_guide_list_object.retrieve_voter_guides_for_election( google_civic_election_id=google_civic_election_id) if results['success']: voter_guide_list = results['voter_guide_list'] else: results = voter_guide_list_object.retrieve_all_voter_guides() if results['success']: voter_guide_list = results['voter_guide_list'] election_list = Election.objects.order_by('-election_day_text') messages_on_stage = get_messages(request) template_values = { 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, 'messages_on_stage': messages_on_stage, 'voter_guide_list': voter_guide_list, } return render(request, 'voter_guide/voter_guide_list.html', template_values)
def measure_list_view(request): authority_required = {"verified_volunteer"} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = request.GET.get("google_civic_election_id", 0) try: measure_list = ContestMeasure.objects.order_by("measure_title") if positive_value_exists(google_civic_election_id): measure_list = measure_list.filter(google_civic_election_id=google_civic_election_id) except ContestMeasure.DoesNotExist: # This is fine measure_list = ContestMeasure() pass election_list = Election.objects.order_by("-election_day_text") template_values = { "messages_on_stage": messages_on_stage, "measure_list": measure_list, "election_list": election_list, "google_civic_election_id": google_civic_election_id, } return render(request, "measure/measure_list.html", template_values)
def office_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = convert_to_int( request.GET.get('google_civic_election_id', 0)) office_list_manager = ContestOfficeListManager() updated_office_list = [] results = office_list_manager.retrieve_all_offices_for_upcoming_election( google_civic_election_id, True) if results['office_list_found']: office_list = results['office_list_objects'] for office in office_list: office.candidate_count = fetch_candidate_count_for_office( office.id) updated_office_list.append(office) election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'office_list': updated_office_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'office/office_list.html', template_values)
def import_group_ratings_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # state_code = request.GET.get('state_code', 'NA') # Default to national # category_id = request.GET.get('category_id', 0) # Retrieve each group so we can request the ratings for each group get_sig_group_count = 0 get_sig_error_message_count = 0 special_interest_group_list = VoteSmartSpecialInterestGroup.objects.order_by('name') for one_group in special_interest_group_list: special_interest_group_id = one_group.sigId one_group_results = retrieve_vote_smart_ratings_by_group_into_local_db(special_interest_group_id) if not one_group_results['success']: print_to_log(logger=logger, exception_message_optional=one_group_results['status']) get_sig_error_message_count += 1 else: get_sig_group_count += 1 messages.add_message(request, messages.INFO, "Ratings from {get_sig_group_count} " "Special Interest Groups retrieved. " "(errors: {get_sig_error_message_count})" "".format(get_sig_group_count=get_sig_group_count, get_sig_error_message_count=get_sig_error_message_count)) return HttpResponseRedirect(reverse('import_export_vote_smart:vote_smart_rating_list', args=()))
def voter_summary_view(request, voter_id): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) voter_id = convert_to_int(voter_id) voter_on_stage_found = False try: voter_on_stage = Voter.objects.get(id=voter_id) voter_on_stage_found = True except Voter.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except Voter.DoesNotExist: # This is fine, create new pass if voter_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'voter': voter_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'voter/voter_summary.html', template_values)
def position_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = convert_to_int(request.GET.get('google_civic_election_id', 0)) position_list_manager = PositionListManager() if positive_value_exists(google_civic_election_id): public_only = True position_list = position_list_manager.retrieve_all_positions_for_election(google_civic_election_id, ANY_STANCE, public_only) else: position_list = PositionEntered.objects.order_by('position_id')[:500] # This order_by is temp election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'position_list': position_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'position/position_list.html', template_values)
def organization_new_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # A positive value in google_civic_election_id means we want to create a voter guide for this org for this election google_civic_election_id = request.GET.get('google_civic_election_id', 0) election_manager = ElectionManager() upcoming_election_list = [] results = election_manager.retrieve_upcoming_elections() if results['success']: upcoming_election_list = results['election_list'] state_list = STATE_CODE_MAP sorted_state_list = sorted(state_list.items()) messages_on_stage = get_messages(request) template_values = { 'messages_on_stage': messages_on_stage, 'upcoming_election_list': upcoming_election_list, 'google_civic_election_id': google_civic_election_id, 'state_list': sorted_state_list, } return render(request, 'organization/organization_edit.html', template_values)
def voter_guide_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) google_civic_election_id = convert_to_int(request.GET.get('google_civic_election_id', 0)) voter_guide_list = [] voter_guide_list_object = VoterGuideListManager() if positive_value_exists(google_civic_election_id): results = voter_guide_list_object.retrieve_voter_guides_for_election( google_civic_election_id=google_civic_election_id) if results['success']: voter_guide_list = results['voter_guide_list'] else: order_by = "google_civic_election_id" results = voter_guide_list_object.retrieve_all_voter_guides(order_by) if results['success']: voter_guide_list = results['voter_guide_list'] election_list = Election.objects.order_by('-election_day_text') messages_on_stage = get_messages(request) template_values = { 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, 'messages_on_stage': messages_on_stage, 'voter_guide_list': voter_guide_list, } return render(request, 'voter_guide/voter_guide_list.html', template_values)
def admin_home_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # Create a voter_device_id and voter in the database if one doesn't exist yet results = voter_setup(request) voter_api_device_id = results['voter_api_device_id'] store_new_voter_api_device_id_in_cookie = results[ 'store_new_voter_api_device_id_in_cookie'] google_civic_election_id = convert_to_int( request.GET.get('google_civic_election_id', 0)) template_values = { 'google_civic_election_id': google_civic_election_id, } response = render(request, 'admin_tools/index.html', template_values) # We want to store the voter_api_device_id cookie if it is new if positive_value_exists(voter_api_device_id) and positive_value_exists( store_new_voter_api_device_id_in_cookie): set_voter_api_device_id(request, response, voter_api_device_id) return response
def measure_edit_view(request, measure_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) measure_id = convert_to_int(measure_id) measure_on_stage_found = False try: measure_on_stage = ContestMeasure.objects.get(id=measure_id) measure_on_stage_found = True except ContestMeasure.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) measure_on_stage = ContestMeasure() except ContestMeasure.DoesNotExist: # This is fine, create new measure_on_stage = ContestMeasure() pass if measure_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'measure': measure_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'measure/measure_edit.html', template_values)
def candidate_retrieve_photos_view(request, candidate_id): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) candidate_id = convert_to_int(candidate_id) force_retrieve = request.GET.get('force_retrieve', 0) candidate_campaign_manager = CandidateCampaignManager() results = candidate_campaign_manager.retrieve_candidate_campaign_from_id( candidate_id) if not positive_value_exists(results['candidate_campaign_found']): messages.add_message( request, messages.ERROR, "Candidate '{candidate_id}' not found.".format( candidate_id=candidate_id)) return HttpResponseRedirect( reverse('candidate:candidate_edit', args=(candidate_id, ))) we_vote_candidate = results['candidate_campaign'] display_messages = True retrieve_candidate_results = retrieve_candidate_photos( we_vote_candidate, force_retrieve) if retrieve_candidate_results['status'] and display_messages: messages.add_message(request, messages.INFO, retrieve_candidate_results['status']) return HttpResponseRedirect( reverse('candidate:candidate_edit', args=(candidate_id, )))
def import_photo_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # NOTE: This view is for testing purposes. For the operational "Import Vote Smart Images" view, see: # "candidate_retrieve_photos_view" in candidate/views_admin.py last_name = "Trump" results = retrieve_vote_smart_candidates_into_local_db(last_name) if not results['success']: messages.add_message(request, messages.INFO, results['status']) else: messages.add_message(request, messages.INFO, "Photo retrieved.") # Now we can go on to make sure we have the right VoteSmartCandidate vote_smart_candidate_id = 15723 # ...and then retrieve the photo results = retrieve_vote_smart_candidate_bio_into_local_db( vote_smart_candidate_id) last_name = "Pelosi" results = retrieve_vote_smart_officials_into_local_db(last_name) messages_on_stage = get_messages(request) template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'import_export_vote_smart/vote_smart_import.html', template_values)
def position_edit_view(request, position_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) position_id = convert_to_int(position_id) position_on_stage_found = False try: position_on_stage = CandidateCampaign.objects.get(id=position_id) position_on_stage_found = True except CandidateCampaign.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except CandidateCampaign.DoesNotExist: # This is fine, create new pass if position_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'position': position_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'position/position_edit.html', template_values)
def position_edit_view(request, position_we_vote_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) position_on_stage_found = False try: position_on_stage = PositionEntered.objects.get(we_vote_id=position_we_vote_id) position_on_stage_found = True except PositionEntered.MultipleObjectsReturned as e: pass except PositionEntered.DoesNotExist: # This is fine, create new pass if position_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'position': position_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'position/position_edit.html', template_values)
def import_group_ratings_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # state_code = request.GET.get('state_code', 'NA') # Default to national # category_id = request.GET.get('category_id', 0) # Retrieve each group so we can request the ratings for each group get_sig_group_count = 0 get_sig_error_message_count = 0 special_interest_group_list = VoteSmartSpecialInterestGroup.objects.order_by( 'name') for one_group in special_interest_group_list: special_interest_group_id = one_group.sigId one_group_results = retrieve_vote_smart_ratings_by_group_into_local_db( special_interest_group_id) if not one_group_results['success']: print_to_log( logger=logger, exception_message_optional=one_group_results['status']) get_sig_error_message_count += 1 else: get_sig_group_count += 1 messages.add_message( request, messages.INFO, "Ratings from {get_sig_group_count} " "Special Interest Groups retrieved. " "(errors: {get_sig_error_message_count})" "".format(get_sig_group_count=get_sig_group_count, get_sig_error_message_count=get_sig_error_message_count)) return HttpResponseRedirect( reverse('import_export_vote_smart:vote_smart_rating_list', args=()))
def voter_summary_view(request, voter_id): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) voter_id = convert_to_int(voter_id) voter_on_stage_found = False voter_on_stage = Voter() try: voter_on_stage = Voter.objects.get(id=voter_id) voter_on_stage_found = True except Voter.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except Voter.DoesNotExist: # This is fine, create new pass if voter_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'voter': voter_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'voter/voter_summary.html', template_values)
def retrieve_positions_from_vote_smart_for_election_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) google_civic_election_id = request.GET.get('google_civic_election_id', 0) try: candidate_list = CandidateCampaign.objects.all() if positive_value_exists(google_civic_election_id): candidate_list = candidate_list.filter(google_civic_election_id=google_civic_election_id) candidate_list = candidate_list.order_by('candidate_name')[:500] except CandidateCampaign.DoesNotExist: messages.add_message(request, messages.INFO, "Could not find any candidates.") pass # Do a first pass through where we get positions for candidates for whom we already have an id for we_vote_candidate in candidate_list: if we_vote_candidate.vote_smart_id: retrieve_vote_smart_ratings_by_candidate_into_local_db(we_vote_candidate.vote_smart_id) transfer_vote_smart_ratings_to_positions_for_candidate(we_vote_candidate.id) # Then we cycle through again, and if we find a Vote Smart id, we get positions for that candidate for we_vote_candidate in candidate_list: if not we_vote_candidate.vote_smart_id: force_retrieve = False results = retrieve_and_match_candidate_from_vote_smart(we_vote_candidate, force_retrieve) if results['success'] and results['we_vote_candidate_id']: we_vote_candidate = results['we_vote_candidate'] if we_vote_candidate.vote_smart_id: retrieve_vote_smart_ratings_by_candidate_into_local_db(we_vote_candidate.vote_smart_id) transfer_vote_smart_ratings_to_positions_for_candidate(we_vote_candidate.id) return HttpResponseRedirect(reverse('position:position_list', args=()) + "?google_civic_election_id=" + google_civic_election_id)
def candidate_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = convert_to_int( request.GET.get('google_civic_election_id', 0)) candidate_list = [] try: candidate_list = CandidateCampaign.objects.all() if positive_value_exists(google_civic_election_id): candidate_list = candidate_list.filter( google_civic_election_id=google_civic_election_id) candidate_list = candidate_list.order_by('candidate_name')[:500] except CandidateCampaign.DoesNotExist: # This is fine, create new pass election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'candidate_list': candidate_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'candidate/candidate_list.html', template_values)
def retrieve_candidate_photos_for_election_view(request, election_id): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) google_civic_election_id = convert_to_int(election_id) # We only want to process if a google_civic_election_id comes in if not positive_value_exists(google_civic_election_id): messages.add_message(request, messages.ERROR, "Google Civic Election ID required.") return HttpResponseRedirect(reverse('candidate:candidate_list', args=())) try: candidate_list = CandidateCampaign.objects.order_by('candidate_name') if positive_value_exists(google_civic_election_id): candidate_list = candidate_list.filter(google_civic_election_id=google_civic_election_id) except CandidateCampaign.DoesNotExist: pass display_messages = False force_retrieve = False # Loop through all of the candidates in this election for we_vote_candidate in candidate_list: retrieve_candidate_results = retrieve_candidate_photos(we_vote_candidate, force_retrieve) if retrieve_candidate_results['status'] and display_messages: messages.add_message(request, messages.INFO, retrieve_candidate_results['status']) return HttpResponseRedirect(reverse('candidate:candidate_list', args=()) + "?google_civic_election_id={var}".format( var=google_civic_election_id))
def vote_smart_candidate_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) candidate_list = [] candidate_list_found = False try: candidate_list = VoteSmartCandidate.objects.order_by( 'lastName')[:1000] # Descending order, and limited to 1000 if len(candidate_list): candidate_list_found = True except VotesmartApiError as error_instance: # Catch the error message coming back from Vote Smart and pass it in the status error_message = error_instance.args status = "EXCEPTION_RAISED: {error_message}".format( error_message=error_message) print_to_log(logger=logger, exception_message_optional=status) # election_list = Election.objects.order_by('-election_day_text') if candidate_list_found: template_values = { 'messages_on_stage': messages_on_stage, 'candidate_list': candidate_list, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'import_export_vote_smart/candidate_list.html', template_values)
def polling_location_summary_by_we_vote_id_view(request, polling_location_we_vote_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) polling_location_on_stage_found = False polling_location_on_stage = PollingLocation() try: polling_location_on_stage = PollingLocation.objects.get(we_vote_id=polling_location_we_vote_id) polling_location_on_stage_found = True except PollingLocation.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except PollingLocation.DoesNotExist: # This is fine, create new pass if polling_location_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'polling_location': polling_location_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'polling_location/polling_location_summary.html', template_values)
def import_one_politician_ratings_view( request, vote_smart_candidate_id): # TODO DALE update to politician authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # retrieve_vote_smart_ratings_for_candidate_into_local_db can be used for both We Vote candidate or politician one_group_results = retrieve_vote_smart_ratings_for_candidate_into_local_db( vote_smart_candidate_id) if one_group_results['success']: messages.add_message(request, messages.INFO, "Ratings for one candidate retrieved. ") else: messages.add_message( request, messages.ERROR, "Ratings for one candidate NOT retrieved. " "(error: {error_message})" "".format(error_message=one_group_results['status'])) candidate_manager = CandidateCampaignManager() results = candidate_manager.retrieve_candidate_campaign_from_vote_smart_id( vote_smart_candidate_id) if results['candidate_campaign_found']: candidate = results['candidate_campaign'] candidate_campaign_id = candidate.id return HttpResponseRedirect( reverse('candidate:candidate_edit', args=(candidate_campaign_id, ))) else: return HttpResponseRedirect( reverse('candidate:candidate_list', args=()))
def measure_summary_view(request, measure_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) measure_id = convert_to_int(measure_id) measure_on_stage_found = False measure_on_stage = ContestMeasure() google_civic_election_id = convert_to_int( request.GET.get('google_civic_election_id', 0)) try: measure_on_stage = ContestMeasure.objects.get(id=measure_id) measure_on_stage_found = True except ContestMeasure.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except ContestMeasure.DoesNotExist: # This is fine, create new pass election_list = Election.objects.order_by('-election_day_text') if measure_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'measure': measure_on_stage, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'measure/measure_summary.html', template_values)
def politician_tag_new_process_view(request, politician_id): """ Process the form to add a new link tying a politician to twitter tags """ authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) politician_on_stage = get_object_or_404(Politician, id=politician_id) new_tag = request.POST['new_tag'] # If an invalid tag didn't come in, redirect back to tag_new if not is_tag_valid(new_tag): messages.add_message( request, messages.INFO, 'That is not a valid tag. Please enter a different tag.') return HttpResponseRedirect( reverse('politician:politician_tag_new', args=(politician_id, ))) new_tag_temp, created = Tag.objects.get_or_create(hashtag_text=new_tag) new_tag_link = PoliticianTagLink(tag=new_tag_temp, politician=politician_on_stage) new_tag_link.save() return HttpResponseRedirect( reverse('politician:politician_detail', args=(politician_id, )))
def import_polling_locations_process_view(request): """ This view imports the polling location data from xml files from VIP (http://data.votinginfoproject.org) :param request: :return: """ authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) polling_location_state = request.GET.get('polling_location_state', '') # polling_location_state = 'mo' # State code for Missouri results = import_and_save_all_polling_locations_data( polling_location_state.lower()) messages.add_message( request, messages.INFO, 'Polling locations retrieved from file. ' '({saved} added, {updated} updated, {not_processed} not_processed)'. format( saved=results['saved'], updated=results['updated'], not_processed=results['not_processed'], )) return HttpResponseRedirect( reverse('polling_location:polling_location_list', args=()) + "?polling_location_state={var}".format(var=polling_location_state))
def refresh_existing_voter_guides_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) voter_guide_updated_count = 0 # Cycle through existing voter_guides voter_guide_list_manager = VoterGuideListManager() voter_guide_manager = VoterGuideManager() results = voter_guide_list_manager.retrieve_all_voter_guides() if results['voter_guide_list_found']: voter_guide_list = results['voter_guide_list'] for voter_guide in voter_guide_list: if positive_value_exists(voter_guide.organization_we_vote_id): if positive_value_exists(voter_guide.google_civic_election_id): results = voter_guide_manager.update_or_create_organization_voter_guide_by_election_id( voter_guide.organization_we_vote_id, voter_guide.google_civic_election_id) if results['success']: voter_guide_updated_count += 1 elif positive_value_exists(voter_guide.vote_smart_time_span): results = voter_guide_manager.update_or_create_organization_voter_guide_by_time_span( voter_guide.organization_we_vote_id, voter_guide.vote_smart_time_span) if results['success']: voter_guide_updated_count += 1 messages.add_message(request, messages.INFO, '{voter_guide_updated_count} updated.'.format( voter_guide_updated_count=voter_guide_updated_count, )) return HttpResponseRedirect(reverse('voter_guide:voter_guide_list', args=()))
def import_photo_view(request): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # NOTE: This view is for testing purposes. For the operational "Import Vote Smart Images" view, see: # "candidate_retrieve_photos_view" in candidate/views_admin.py last_name = "Trump" results = retrieve_vote_smart_candidates_into_local_db(last_name) if not results['success']: messages.add_message(request, messages.INFO, results['status']) else: messages.add_message(request, messages.INFO, "Photo retrieved.") # Now we can go on to make sure we have the right VoteSmartCandidate vote_smart_candidate_id = 15723 # ...and then retrieve the photo results = retrieve_vote_smart_candidate_bio_into_local_db(vote_smart_candidate_id) last_name = "Pelosi" results = retrieve_vote_smart_officials_into_local_db(last_name) messages_on_stage = get_messages(request) template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'import_export_vote_smart/vote_smart_import.html', template_values)
def vote_smart_rating_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) rating_list = [] rating_list_found = False try: rating_list = VoteSmartRating.objects.order_by('-timeSpan')[:1000] # Descending order, and limited to 1000 if len(rating_list): rating_list_found = True except VotesmartApiError as error_instance: # Catch the error message coming back from Vote Smart and pass it in the status error_message = error_instance.args status = "EXCEPTION_RAISED: {error_message}".format(error_message=error_message) print_to_log(logger=logger, exception_message_optional=status) # election_list = Election.objects.order_by('-election_day_text') if rating_list_found: template_values = { 'messages_on_stage': messages_on_stage, 'rating_list': rating_list, # 'election_list': election_list, # 'google_civic_election_id': google_civic_election_id, } else: template_values = { 'messages_on_stage': messages_on_stage, # 'election_list': election_list, # 'google_civic_election_id': google_civic_election_id, } return render(request, 'import_export_vote_smart/rating_list.html', template_values)
def relink_candidates_measures_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages.add_message(request, messages.INFO, 'TO BE BUILT: relink_candidates_measures_view') return HttpResponseRedirect(reverse('position:position_list', args=()))
def organization_edit_existing_position_form_view(request, organization_id, position_id): """ In edit, you can only change your stance and comments, not who or what the position is about :param request: :param organization_id: :param position_id: :return: """ authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) organization_id = convert_to_int(organization_id) position_id = convert_to_int(position_id) organization_on_stage_found = False try: organization_on_stage = Organization.objects.get(id=organization_id) organization_on_stage_found = True except Organization.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except Organization.DoesNotExist: # This is fine, create new pass if not organization_on_stage_found: messages.add_message(request, messages.INFO, 'Could not find organization when trying to edit a position.') return HttpResponseRedirect(reverse('organization:organization_position_list', args=([organization_id]))) # Get the existing position organization_position_on_stage = PositionEntered() organization_position_on_stage_found = False position_entered_manager = PositionEnteredManager() results = position_entered_manager.retrieve_position_from_id(position_id) if results['position_found']: organization_position_on_stage_found = True organization_position_on_stage = results['position'] if not organization_position_on_stage_found: messages.add_message(request, messages.INFO, 'Could not find organization position when trying to edit.') return HttpResponseRedirect(reverse('organization:organization_position_list', args=([organization_id]))) # Note: We have access to the candidate campaign through organization_position_on_stage.candidate_campaign election_list = Election.objects.all() if organization_position_on_stage_found: template_values = { 'is_in_edit_mode': True, 'messages_on_stage': messages_on_stage, 'organization': organization_on_stage, 'organization_position': organization_position_on_stage, 'possible_stances_list': ORGANIZATION_STANCE_CHOICES, 'stance_selected': organization_position_on_stage.stance, 'election_list': election_list, } return render(request, 'organization/organization_position_edit.html', template_values)
def politician_tag_new_view(request, politician_id): """ Form to add a new link tying a politician to twitter tags :param request: :return: """ authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) # for message in messages_on_stage: # if message.level is ERROR: politician_on_stage = get_object_or_404(Politician, id=politician_id) try: tag_link_list = politician_on_stage.tag_link.all() except PoliticianTagLink.DoesNotExist: tag_link_list = None template_values = { 'politician_on_stage': politician_on_stage, 'tag_link_list': tag_link_list, 'messages_on_stage': messages_on_stage, } return render(request, 'politician/politician_tag_new.html', template_values)
def refresh_twitter_candidate_details_for_election_view(request, election_id): authority_required = {'admin'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) google_civic_election_id = convert_to_int(election_id) results = refresh_twitter_candidate_details_for_election( google_civic_election_id=google_civic_election_id) if not results['success']: messages.add_message(request, messages.INFO, results['status']) else: twitter_handles_added = results['twitter_handles_added'] profiles_refreshed_with_twitter_data = results[ 'profiles_refreshed_with_twitter_data'] messages.add_message( request, messages.INFO, "Social media retrieved. Twitter handles added: {twitter_handles_added}, " "Profiles refreshed with Twitter data: {profiles_refreshed_with_twitter_data}" .format(twitter_handles_added=twitter_handles_added, profiles_refreshed_with_twitter_data= profiles_refreshed_with_twitter_data)) return HttpResponseRedirect( reverse('candidate:candidate_list', args=()) + '?google_civic_election_id=' + election_id)
def candidate_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = request.GET.get('google_civic_election_id', 0) try: candidate_list = CandidateCampaign.objects.all() if positive_value_exists(google_civic_election_id): candidate_list = candidate_list.filter(google_civic_election_id=google_civic_election_id) candidate_list = candidate_list.order_by('candidate_name')[:500] except CandidateCampaign.DoesNotExist: # This is fine, create new pass election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'candidate_list': candidate_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'candidate/candidate_list.html', template_values)
def refresh_existing_voter_guides_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) voter_guide_updated_count = 0 # Cycle through existing voter_guides voter_guide_list_manager = VoterGuideListManager() voter_guide_manager = VoterGuideManager() results = voter_guide_list_manager.retrieve_all_voter_guides() if results['voter_guide_list_found']: voter_guide_list = results['voter_guide_list'] for voter_guide in voter_guide_list: if positive_value_exists(voter_guide.organization_we_vote_id): if positive_value_exists(voter_guide.google_civic_election_id): results = voter_guide_manager.update_or_create_organization_voter_guide_by_election_id( voter_guide.organization_we_vote_id, voter_guide.google_civic_election_id) if results['success']: voter_guide_updated_count += 1 elif positive_value_exists(voter_guide.vote_smart_time_span): results = voter_guide_manager.update_or_create_organization_voter_guide_by_time_span( voter_guide.organization_we_vote_id, voter_guide.vote_smart_time_span) if results['success']: voter_guide_updated_count += 1 messages.add_message( request, messages.INFO, '{voter_guide_updated_count} updated.'.format( voter_guide_updated_count=voter_guide_updated_count, )) return HttpResponseRedirect( reverse('voter_guide:voter_guide_list', args=()))
def voter_guide_search_view(request): """ Before creating a voter guide, search for an existing organization :param request: :return: """ authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) # A positive value in google_civic_election_id means we want to create a voter guide for this org for this election google_civic_election_id = request.GET.get('google_civic_election_id', 0) messages_on_stage = get_messages(request) election_manager = ElectionManager() upcoming_election_list = [] results = election_manager.retrieve_upcoming_elections() if results['success']: upcoming_election_list = results['election_list'] state_list = STATE_CODE_MAP sorted_state_list = sorted(state_list.items()) template_values = { 'messages_on_stage': messages_on_stage, 'upcoming_election_list': upcoming_election_list, 'google_civic_election_id': google_civic_election_id, 'state_list': sorted_state_list, } return render(request, 'voter_guide/voter_guide_search.html', template_values)
def polling_location_summary_by_we_vote_id_view(request, polling_location_we_vote_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) polling_location_on_stage_found = False polling_location_on_stage = PollingLocation() try: polling_location_on_stage = PollingLocation.objects.get( we_vote_id=polling_location_we_vote_id) polling_location_on_stage_found = True except PollingLocation.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except PollingLocation.DoesNotExist: # This is fine, create new pass if polling_location_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'polling_location': polling_location_on_stage, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'polling_location/polling_location_summary.html', template_values)
def measure_summary_view(request, measure_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) measure_id = convert_to_int(measure_id) measure_on_stage_found = False measure_on_stage = ContestMeasure() google_civic_election_id = convert_to_int(request.GET.get('google_civic_election_id', 0)) try: measure_on_stage = ContestMeasure.objects.get(id=measure_id) measure_on_stage_found = True except ContestMeasure.MultipleObjectsReturned as e: handle_record_found_more_than_one_exception(e, logger=logger) except ContestMeasure.DoesNotExist: # This is fine, create new pass election_list = Election.objects.order_by('-election_day_text') if measure_on_stage_found: template_values = { 'messages_on_stage': messages_on_stage, 'measure': measure_on_stage, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } else: template_values = { 'messages_on_stage': messages_on_stage, } return render(request, 'measure/measure_summary.html', template_values)
def measure_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = convert_to_int( request.GET.get('google_civic_election_id', 0)) try: measure_list = ContestMeasure.objects.order_by('measure_title') if positive_value_exists(google_civic_election_id): measure_list = measure_list.filter( google_civic_election_id=google_civic_election_id) except ContestMeasure.DoesNotExist: # This is fine measure_list = ContestMeasure() pass election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'measure_list': measure_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'measure/measure_list.html', template_values)
def measure_list_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) messages_on_stage = get_messages(request) google_civic_election_id = convert_to_int(request.GET.get('google_civic_election_id', 0)) try: measure_list = ContestMeasure.objects.order_by('measure_title') if positive_value_exists(google_civic_election_id): measure_list = measure_list.filter(google_civic_election_id=google_civic_election_id) except ContestMeasure.DoesNotExist: # This is fine measure_list = ContestMeasure() pass election_list = Election.objects.order_by('-election_day_text') template_values = { 'messages_on_stage': messages_on_stage, 'measure_list': measure_list, 'election_list': election_list, 'google_civic_election_id': google_civic_election_id, } return render(request, 'measure/measure_list.html', template_values)
def candidate_politician_match_view(request): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) candidate_id = request.GET.get('candidate_id', 0) candidate_id = convert_to_int(candidate_id) # google_civic_election_id is included for interface usability reasons and isn't used in the processing google_civic_election_id = request.GET.get('google_civic_election_id', 0) google_civic_election_id = convert_to_int(google_civic_election_id) if not positive_value_exists(candidate_id): messages.add_message(request, messages.ERROR, "The candidate_id variable was not passed in.") return HttpResponseRedirect(reverse('candidate:candidate_edit', args=(candidate_id,))) candidate_campaign_manager = CandidateCampaignManager() results = candidate_campaign_manager.retrieve_candidate_campaign_from_id(candidate_id) if not positive_value_exists(results['candidate_campaign_found']): messages.add_message(request, messages.ERROR, "Candidate '{candidate_id}' not found.".format(candidate_id=candidate_id)) return HttpResponseRedirect(reverse('candidate:candidate_edit', args=(candidate_id,))) we_vote_candidate = results['candidate_campaign'] # Make sure we have a politician for this candidate. If we don't, create a politician entry, and save the # politician_we_vote_id in the candidate results = candidate_politician_match(we_vote_candidate) display_messages = True if results['status'] and display_messages: messages.add_message(request, messages.INFO, results['status']) return HttpResponseRedirect(reverse('candidate:candidate_edit', args=(candidate_id,)) + "?google_civic_election_id=" + str(google_civic_election_id))
def quick_info_master_edit_view(request, quick_info_master_id): authority_required = {'verified_volunteer'} # admin, verified_volunteer if not voter_has_authority(request, authority_required): return redirect_to_sign_in_page(request, authority_required) form_submitted = request.POST.get('form_submitted', False) quick_info_master_id = convert_to_int(quick_info_master_id) try: quick_info_master = QuickInfoMaster.objects.get(id=quick_info_master_id) except QuickInfoMaster.MultipleObjectsReturned as e: # Pretty unlikely that multiple objects have the same id messages.add_message(request, messages.ERROR, "This quick_info_master_id has multiple records.") return HttpResponseRedirect(reverse('quick_info:quick_info_master_list', args=())) except QuickInfoMaster.DoesNotExist: # This is fine, create new entry return quick_info_master_new_view(request) if positive_value_exists(form_submitted): # If the voter tried to submit an entry, and it didn't save, capture the changed values for display kind_of_ballot_item = request.POST.get('kind_of_ballot_item', False) language = request.POST.get('language', False) info_text = request.POST.get('info_text', False) info_html = request.POST.get('info_html', False) master_entry_name = request.POST.get('master_entry_name', False) more_info_credit = request.POST.get('more_info_credit', False) more_info_url = request.POST.get('more_info_url', False) # Write over the fields where a change has been made on the form if kind_of_ballot_item is not False: quick_info_master.kind_of_ballot_item = kind_of_ballot_item if language is not False: quick_info_master.language = language if master_entry_name is not False: quick_info_master.master_entry_name = master_entry_name if more_info_credit is not False: quick_info_master.more_info_credit = more_info_credit if more_info_url is not False: quick_info_master.more_info_url = more_info_url if info_text is not False: quick_info_master.info_text = info_text if info_html is not False: quick_info_master.info_html = info_html # ################################## # Above we have dealt with data provided by prior submit quick_info_list = QuickInfo.objects.order_by('id') # This order_by is temp quick_info_list = QuickInfo.objects.filter(quick_info_master_we_vote_id=quick_info_master.we_vote_id) messages_on_stage = get_messages(request) template_values = { 'messages_on_stage': messages_on_stage, 'ballot_item_choices': KIND_OF_BALLOT_ITEM_CHOICES, 'language_choices': LANGUAGE_CHOICES, 'quick_info_master': quick_info_master, 'quick_info_list': quick_info_list, } return render(request, 'quick_info/quick_info_master_edit.html', template_values)