2020from ballot .models import BallotReturnedListManager
2121from bookmark .models import BookmarkItemList
2222from config .base import get_environment_variable
23- from election .controllers import retrieve_upcoming_election_id_list
23+ from election .controllers import retrieve_election_id_list_by_year_list , retrieve_upcoming_election_id_list
2424from election .models import ElectionManager
2525from exception .models import handle_record_found_more_than_one_exception , \
2626 handle_record_not_found_exception , print_to_log
3838from voter_guide .models import VoterGuide
3939from wevote_functions .functions import convert_to_int , extract_twitter_handle_from_text_string , list_intersection , \
4040 positive_value_exists , STATE_CODE_MAP , display_full_name_with_correct_capitalization
41+ from wevote_settings .constants import ELECTION_YEARS_AVAILABLE
4142from wevote_settings .models import RemoteRequestHistory , \
4243 RETRIEVE_POSSIBLE_GOOGLE_LINKS , RETRIEVE_POSSIBLE_TWITTER_HANDLES
4344from .controllers import candidates_import_from_master_server , candidates_import_from_sample_file , \
@@ -332,6 +333,7 @@ def candidate_list_view(request):
332333 positive_value_exists (request .GET .get ('show_candidates_with_twitter_options' , False ))
333334 show_election_statistics = positive_value_exists (request .GET .get ('show_election_statistics' , False ))
334335 show_marquee_or_battleground = positive_value_exists (request .GET .get ('show_marquee_or_battleground' , False ))
336+ show_this_year_of_candidates = convert_to_int (request .GET .get ('show_this_year_of_candidates' , 0 ))
335337
336338 review_mode = positive_value_exists (request .GET .get ('review_mode' , False ))
337339
@@ -392,9 +394,13 @@ def candidate_list_view(request):
392394 # messages.add_message(request, messages.INFO, "candidates_migrated: " + str(candidates_migrated))
393395
394396 google_civic_election_id_list_generated = False
397+ show_this_year_of_candidates_restriction = False
395398 if positive_value_exists (google_civic_election_id ):
396399 google_civic_election_id_list = [convert_to_int (google_civic_election_id )]
397400 google_civic_election_id_list_generated = True
401+ elif positive_value_exists (show_this_year_of_candidates ):
402+ google_civic_election_id_list = retrieve_election_id_list_by_year_list ([show_this_year_of_candidates ])
403+ show_this_year_of_candidates_restriction = True
398404 elif positive_value_exists (show_all_elections ):
399405 google_civic_election_id_list = []
400406 else :
@@ -403,7 +409,12 @@ def candidate_list_view(request):
403409 google_civic_election_id_list = retrieve_upcoming_election_id_list ()
404410
405411 candidate_we_vote_id_list = []
406- if google_civic_election_id_list_generated :
412+ if show_this_year_of_candidates_restriction :
413+ results = candidate_list_manager .retrieve_candidate_we_vote_id_list_from_year_list (
414+ year_list = [show_this_year_of_candidates ],
415+ limit_to_this_state_code = state_code )
416+ candidate_we_vote_id_list = results ['candidate_we_vote_id_list' ]
417+ elif google_civic_election_id_list_generated :
407418 results = candidate_list_manager .retrieve_candidate_we_vote_id_list_from_election_list (
408419 google_civic_election_id_list = google_civic_election_id_list ,
409420 limit_to_this_state_code = state_code )
@@ -490,10 +501,12 @@ def candidate_list_view(request):
490501
491502 # Figure out the subset of candidate_we_vote_ids to look up
492503 filtered_candidate_we_vote_id_list = []
493- if google_civic_election_id_list_generated and show_marquee_or_battleground :
504+ # show_this_year_of_candidates_restriction
505+ if (google_civic_election_id_list_generated or show_this_year_of_candidates_restriction ) \
506+ and show_marquee_or_battleground :
494507 filtered_candidate_we_vote_id_list = list_intersection (
495508 candidate_we_vote_id_list , battleground_candidate_we_vote_id_list )
496- elif google_civic_election_id_list_generated :
509+ elif google_civic_election_id_list_generated or show_this_year_of_candidates_restriction :
497510 filtered_candidate_we_vote_id_list = candidate_we_vote_id_list
498511 elif show_marquee_or_battleground :
499512 filtered_candidate_we_vote_id_list = battleground_candidate_we_vote_id_list
@@ -502,7 +515,8 @@ def candidate_list_view(request):
502515 try :
503516 candidate_query = CandidateCampaign .objects .all ()
504517 if positive_value_exists (google_civic_election_id_list_generated ) \
505- or positive_value_exists (show_marquee_or_battleground ):
518+ or positive_value_exists (show_marquee_or_battleground ) \
519+ or positive_value_exists (show_this_year_of_candidates_restriction ):
506520 candidate_query = candidate_query .filter (we_vote_id__in = filtered_candidate_we_vote_id_list )
507521 if positive_value_exists (state_code ):
508522 candidate_query = candidate_query .filter (state_code__iexact = state_code )
@@ -870,6 +884,7 @@ def candidate_list_view(request):
870884 'current_page_minus_candidate_tools_url' : current_page_minus_candidate_tools_url ,
871885 'election' : election ,
872886 'election_list' : election_list ,
887+ 'election_years_available' : ELECTION_YEARS_AVAILABLE ,
873888 'facebook_urls_without_picture_urls' : facebook_urls_without_picture_urls ,
874889 'find_candidates_linked_to_multiple_offices' : find_candidates_linked_to_multiple_offices ,
875890 'google_civic_election_id' : google_civic_election_id ,
@@ -886,6 +901,7 @@ def candidate_list_view(request):
886901 'show_candidates_without_twitter' : show_candidates_without_twitter ,
887902 'show_election_statistics' : show_election_statistics ,
888903 'show_marquee_or_battleground' : show_marquee_or_battleground ,
904+ 'show_this_year_of_candidates' : show_this_year_of_candidates ,
889905 'state_code' : state_code ,
890906 'state_list' : sorted_state_list ,
891907 'total_twitter_handles' : total_twitter_handles ,
0 commit comments