Skip to content

Commit 405450f

Browse files
committed
Moved election_years_available into a constants file. Added ability to filter Candidate's page so we can see all candidates in one year.
1 parent c513099 commit 405450f

File tree

11 files changed

+107
-21
lines changed

11 files changed

+107
-21
lines changed

campaign/views_admin.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,6 @@ def campaign_list_view(request):
550550
show_issues = request.GET.get('show_issues', '')
551551
show_organizations_without_email = positive_value_exists(request.GET.get('show_organizations_without_email', False))
552552

553-
election_years_available = [2022, 2021, 2020, 2019, 2018, 2017, 2016]
554-
555553
messages_on_stage = get_messages(request)
556554
campaignx_manager = CampaignXManager()
557555

@@ -722,7 +720,6 @@ def campaign_list_view(request):
722720
'campaignx_type_filter': campaignx_type_filter,
723721
'campaignx_types': [],
724722
'client_organization_list': client_organization_list,
725-
'election_years_available': election_years_available,
726723
'final_election_date_plus_cool_down': final_election_date_plus_cool_down,
727724
'google_civic_election_id': google_civic_election_id,
728725
'hide_campaigns_not_visible_yet': hide_campaigns_not_visible_yet,
@@ -833,8 +830,6 @@ def campaign_supporters_list_view(request, campaignx_we_vote_id=""):
833830
show_supporters_not_visible_to_public = \
834831
positive_value_exists(request.GET.get('show_supporters_not_visible_to_public', False))
835832

836-
election_years_available = [2022, 2021, 2020, 2019, 2018, 2017, 2016]
837-
838833
messages_on_stage = get_messages(request)
839834

840835
campaignx = CampaignX.objects.get(we_vote_id__iexact=campaignx_we_vote_id)
@@ -927,7 +922,6 @@ def campaign_supporters_list_view(request, campaignx_we_vote_id=""):
927922
'campaignx_search': campaignx_search,
928923
'campaignx_we_vote_id': campaignx_we_vote_id,
929924
'campaignx_title': campaignx_title,
930-
'election_years_available': election_years_available,
931925
'google_civic_election_id': google_civic_election_id,
932926
'limit_to_opinions_in_state_code': limit_to_opinions_in_state_code,
933927
'limit_to_opinions_in_this_year': limit_to_opinions_in_this_year,

candidate/models.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ def retrieve_all_candidates_for_one_year(
339339
limit_to_this_state_code='',
340340
search_string=False,
341341
return_list_of_objects=False):
342+
"""
343+
This might generate different results than retrieve_candidate_we_vote_id_list_from_year_list.
344+
:param candidate_year:
345+
:param limit_to_this_state_code:
346+
:param search_string:
347+
:param return_list_of_objects:
348+
:return:
349+
"""
342350
candidate_list_objects = []
343351
candidate_list_light = []
344352
candidate_list_found = False
@@ -1661,6 +1669,38 @@ def retrieve_candidate_we_vote_id_list_from_office_list(
16611669
}
16621670
return results
16631671

1672+
def retrieve_candidate_we_vote_id_list_from_year_list(
1673+
self,
1674+
limit_to_this_state_code='',
1675+
year_list=[]):
1676+
"""
1677+
This might return different results than retrieve_all_candidates_for_one_year.
1678+
:param limit_to_this_state_code:
1679+
:param year_list:
1680+
:return:
1681+
"""
1682+
status = ''
1683+
success = True
1684+
candidate_we_vote_id_list = []
1685+
1686+
candidate_query = CandidateCampaign.objects.all()
1687+
candidate_query = candidate_query.filter(candidate_year__in=year_list)
1688+
if positive_value_exists(limit_to_this_state_code):
1689+
candidate_query = candidate_query.filter(state_code__iexact=limit_to_this_state_code)
1690+
1691+
try:
1692+
candidate_we_vote_id_list = candidate_query.values_list('we_vote_id', flat=True).distinct()
1693+
except Exception as e:
1694+
status += 'ERROR_WITH_DATABASE_QUERY: ' + str(e) + ' '
1695+
success = False
1696+
1697+
results = {
1698+
'status': status,
1699+
'success': success,
1700+
'candidate_we_vote_id_list': candidate_we_vote_id_list,
1701+
}
1702+
return results
1703+
16641704
def fetch_candidate_we_vote_id_list_from_office_we_vote_id(self, office_we_vote_id):
16651705
results = self.retrieve_all_candidates_for_office(office_we_vote_id=office_we_vote_id)
16661706
if not positive_value_exists(results['candidate_list_found']):

candidate/views_admin.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ballot.models import BallotReturnedListManager
2121
from bookmark.models import BookmarkItemList
2222
from 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
2424
from election.models import ElectionManager
2525
from exception.models import handle_record_found_more_than_one_exception, \
2626
handle_record_not_found_exception, print_to_log
@@ -38,6 +38,7 @@
3838
from voter_guide.models import VoterGuide
3939
from 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
4142
from wevote_settings.models import RemoteRequestHistory, \
4243
RETRIEVE_POSSIBLE_GOOGLE_LINKS, RETRIEVE_POSSIBLE_TWITTER_HANDLES
4344
from .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,

issue/views_admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from voter_guide.models import VoterGuideListManager
2424
import wevote_functions.admin
2525
from wevote_functions.functions import convert_to_int, positive_value_exists, get_voter_device_id, STATE_CODE_MAP
26+
from wevote_settings.constants import ELECTION_YEARS_AVAILABLE
2627
from django.http import HttpResponse
2728
import json
2829

@@ -833,7 +834,6 @@ def issue_partisan_analysis_view(request):
833834

834835
issue_search = request.GET.get('issue_search', '')
835836
show_hidden_issues = False
836-
election_years_available = [2022, 2021, 2020, 2019, 2018, 2017, 2016]
837837

838838
organization_we_vote_id_in_this_election_list = []
839839
organization_retrieved_list = {}
@@ -842,7 +842,7 @@ def issue_partisan_analysis_view(request):
842842
voter_guide_list_manager = VoterGuideListManager()
843843

844844
if show_statistics_for_all_elections:
845-
election_year_list_to_show = election_years_available
845+
election_year_list_to_show = ELECTION_YEARS_AVAILABLE
846846
show_stats_for_this_google_civic_election_id_list = \
847847
retrieve_election_id_list_by_year_list(election_year_list_to_show=election_year_list_to_show)
848848
google_civic_election_id_list_for_dropdown = show_stats_for_this_google_civic_election_id_list
@@ -1099,7 +1099,7 @@ def issue_partisan_analysis_view(request):
10991099

11001100
template_values = {
11011101
'election_list': election_list,
1102-
'election_years_available': election_years_available,
1102+
'election_years_available': ELECTION_YEARS_AVAILABLE,
11031103
'endorsement_count_left': endorsement_count_left,
11041104
'endorsement_with_commentary_count_left': endorsement_with_commentary_count_left,
11051105
'endorsement_count_center': endorsement_count_center,

organization/views_admin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import wevote_functions.admin
4848
from wevote_functions.functions import convert_to_int, extract_twitter_handle_from_text_string, positive_value_exists, \
4949
STATE_CODE_MAP
50+
from wevote_settings.constants import ELECTION_YEARS_AVAILABLE
5051

5152

5253
ORGANIZATION_STANCE_CHOICES = (
@@ -449,8 +450,6 @@ def organization_list_view(request):
449450
show_organizations_to_be_analyzed = \
450451
positive_value_exists(request.GET.get('show_organizations_to_be_analyzed', False))
451452

452-
election_years_available = [2022, 2021, 2020, 2019, 2018, 2017, 2016]
453-
454453
messages_on_stage = get_messages(request)
455454
organization_list_query = Organization.objects.all()
456455
if positive_value_exists(sort_by):
@@ -644,7 +643,7 @@ def organization_list_view(request):
644643

645644
template_values = {
646645
'candidate_we_vote_id': candidate_we_vote_id,
647-
'election_years_available': election_years_available,
646+
'election_years_available': ELECTION_YEARS_AVAILABLE,
648647
'google_civic_election_id': google_civic_election_id,
649648
'issue_list': issue_list,
650649
'issues_selected': issues_selected,

position/views_admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import wevote_functions.admin
3232
from wevote_functions.functions import convert_to_int, convert_integer_to_string_with_comma_for_thousands_separator, \
3333
positive_value_exists, STATE_CODE_MAP
34+
from wevote_settings.constants import ELECTION_YEARS_AVAILABLE
3435
from django.http import HttpResponse
3536
import json
3637

@@ -251,7 +252,6 @@ def position_list_view(request):
251252
state_code = request.GET.get('state_code', '')
252253
state_list = STATE_CODE_MAP
253254
state_list_modified = {}
254-
election_years_available = [2022, 2021, 2020, 2019, 2018, 2017, 2016]
255255

256256
position_search = request.GET.get('position_search', '')
257257

@@ -565,7 +565,7 @@ def position_list_view(request):
565565
'position_list': position_list,
566566
'position_search': position_search,
567567
'election_list': election_list,
568-
'election_years_available': election_years_available,
568+
'election_years_available': ELECTION_YEARS_AVAILABLE,
569569
'google_civic_election_id': google_civic_election_id,
570570
'show_all_elections': show_all_elections,
571571
'show_statistics': show_statistics,

templates/candidate/candidate_list.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ <h1>Candidates</h1>
4444
</label>
4545
&nbsp;&nbsp;&nbsp;&nbsp;
4646

47+
{% if election_years_available %}
48+
<select id="show_this_year_of_candidates_id" name="show_this_year_of_candidates">
49+
<option value="0" {% if 0 == show_this_year_of_candidates|convert_to_int %} selected="selected"{% endif %}>
50+
-- Choose Year --</option>
51+
{% for year in election_years_available %}
52+
<option value="{{ year }}"
53+
{% if show_this_year_of_candidates|slugify == year|slugify %} selected="selected"{% endif %}>
54+
{% if show_this_year_of_candidates|slugify == year|slugify %}Limited To {% endif %}
55+
{{ year }}</option>
56+
{% endfor %}
57+
</select>
58+
{% endif %}{# End of if election_years_available #}
59+
&nbsp;&nbsp;&nbsp;&nbsp;
60+
4761
{# Show candidates which are either marquee or battleground #}
4862
<label for="show_marquee_or_battleground_id">
4963
<input type="checkbox" name="show_marquee_or_battleground" id="show_marquee_or_battleground_id" value="1"
@@ -257,7 +271,7 @@ <h1>Candidates</h1>
257271
<br />
258272
<form name="candidate_search" method="get" action="{% url 'candidate:candidate_list' %}">
259273
{% if candidate_search %}
260-
<a href="{% url 'candidate:candidate_list' %}?google_civic_election_id={{ google_civic_election_id }}&state_code={{ state_code }}">
274+
<a href="{% url 'candidate:candidate_list' %}?google_civic_election_id={{ google_civic_election_id }}&show_all_elections={{ show_all_elections }}&show_this_year_of_candidates={{ show_this_year_of_candidates }}&state_code={{ state_code }}">
261275
clear search</a>&nbsp;
262276
{% endif %}
263277
<input type="hidden" name="google_civic_election_id" value="{{ google_civic_election_id }}" />
@@ -267,6 +281,7 @@ <h1>Candidates</h1>
267281
<input type="hidden" name="show_all_elections" id="show_all_elections_id" value="{{ show_all_elections }}" />
268282
<input type="hidden" name="show_election_statistics" value="{{ show_election_statistics }}" />
269283
<input type="hidden" name="show_marquee_or_battleground" value="{{ show_marquee_or_battleground }}" />
284+
<input type="hidden" name="show_this_year_of_candidates" value="{{ show_this_year_of_candidates }}" />
270285

271286
<input type="submit" value="Search for Candidate" />
272287

@@ -690,6 +705,11 @@ <h1>Candidates</h1>
690705
this.form.submit();
691706
});
692707
});
708+
$(function() {
709+
$('#show_this_year_of_candidates_id').change(function() {
710+
this.form.submit();
711+
});
712+
});
693713
$(function() {
694714
$('#state_code_id').change(function() {
695715
this.form.submit();

templates/candidate/candidate_merge.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ <h1>{% if candidate_option1 %}Merge {{ candidate_option1.candidate_name }}{% els
113113

114114
{% include "candidate/candidate_merge_one_field_decision.html" with field_name="party" field_label="Party" conflict_status=conflict_values.party candidate1_field_value=candidate_option1.party candidate2_field_value=candidate_option2.party candidate1=candidate_option1 candidate2=candidate_option2 %}
115115

116+
<tr>
117+
<td>Candidate Year</td>
118+
<td>{{ candidate_option1.candidate_year|default_if_none:"" }}</td>
119+
<td>{{ candidate_option2.candidate_year|default_if_none:"" }}</td>
120+
</tr>
121+
116122
{% if candidate_option1.id != None or candidate_option2.id != None %}
117123
<tr>
118124
<td>ID</td>

templates/candidate/candidate_summary.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ <h1>{{ candidate.candidate_name }}</h1>
8585

8686
</td>
8787
</tr>
88+
<tr>
89+
<td>Candidate Year:</td>
90+
<td>
91+
<strong>{{ candidate.candidate_year }}</strong>
92+
</td>
93+
</tr>
8894
<tr>
8995
<td>Contest Office:</td>
9096
<td>
@@ -158,6 +164,7 @@ <h3>Merge with Another Candidate</h3>
158164
<th>ID</th>
159165
<th>We Vote ID</th>
160166
<th>Candidate Name</th>
167+
<th>Year</th>
161168
<th>State</th>
162169
<th>Ballotpedia Race ID</th>
163170
<th>Ballotpedia Candidate ID</th>
@@ -178,6 +185,7 @@ <h3>Merge with Another Candidate</h3>
178185
(<a href="{% url 'candidate:candidate_summary' found_candidate.id %}?google_civic_election_id={{ google_civic_election_id }}&state_code={{ state_code }}" target="_blank">view&nbsp;summary</a>,
179186
<a href="{% url 'candidate:compare_two_candidates_for_merge' %}?candidate1_we_vote_id={{ candidate.we_vote_id }}&candidate2_we_vote_id={{ found_candidate.we_vote_id }}&google_civic_election_id={{ google_civic_election_id }}&state_code={{ state_code }}" target="_blank">compare&nbsp;for&nbsp;merge</a>)
180187
</td>
188+
<td>{{ found_candidate.candidate_year }}</td>
181189
<td>{{ found_candidate.state_code }}</td>
182190
<td>{{ found_candidate.ballotpedia_race_id|default_if_none:"" }}</td>
183191
<td>{{ found_candidate.ballotpedia_candidate_id|default_if_none:"" }}</td>

templates/position/position_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h1>Opinions/Positions</h1>
6767
{{ year }}</option>
6868
{% endfor %}
6969
</select>
70-
{% endif %}{# End of if election_list #}
70+
{% endif %}{# End of if election_years_available #}
7171

7272
{% if state_list %}
7373
<select id="state_code_id" name="state_code">

0 commit comments

Comments
 (0)