Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor candidate view, fix 404's for future candidates #2320

Merged
merged 9 commits into from
Aug 31, 2018
6 changes: 3 additions & 3 deletions fec/data/templates/partials/candidate/about-candidate.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<div class="grid__item u-no-margin">
<div class="callout callout--primary{% if loop.last %} u-no-margin{% endif %}" style="width: 100%; max-width: 300px">
<h5 class="callout__title t-sans">
<a href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</h5>
<span class="callout__subtitle term" data-term="principal campaign committee">Principal campaign committee</span>
</div>
Expand All @@ -98,7 +98,7 @@
<ul class="list--bulleted" style="margin-top: 1rem">
{% for committee in committee_groups['A'] | reverse %}
<li class="u-no-margin-bottom">
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
</ul>
Expand All @@ -119,7 +119,7 @@
<ul class="list--bulleted">
{% for committee in committee_groups['J'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions fec/data/templates/partials/candidate/financial-summary.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<ul class="list--bulleted">
{% for committee in committee_groups['P'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
{% for committee in committee_groups['A'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions fec/data/templates/partials/candidate/raising.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<ul class="list--bulleted">
{% for committee in committee_groups['P'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
{% for committee in committee_groups['A'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions fec/data/templates/partials/candidate/spending.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<ul class="list--bulleted">
{% for committee in committee_groups['P'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
{% for committee in committee_groups['A'] | reverse %}
<li>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ committee.related_cycle }}">{{ committee.name }}</a>
<a class="t-sans" href="/data/committee/{{ committee.committee_id }}/?cycle={{ cycle }}">{{ committee.name }}</a>
</li>
{% endfor %}
</ul>
Expand Down
3 changes: 0 additions & 3 deletions fec/data/tests/test_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,18 @@ def test_base_case(self, load_with_nested_mock, load_candidate_totals_mock,
'cycles': [2016, 2014, 2012, 2018],
'name': 'My Primary Campaign Committee',
'cycle': 2016,
'related_cycle': 2016,
'committee_id': 'C001'}],
'A': [{
'designation': 'A',
'cycles': [2016, 2014, 2012, 2018],
'name': 'My Authorized Campaign Committee',
'cycle': 2016,
'related_cycle': 2016,
'committee_id': 'C002'}],
'J': [{
'designation': 'J',
'cycles': [2016, 2014, 2012, 2018],
'name': 'Joint Fundraising Committee',
'cycle': 2016,
'related_cycle': 2016,
'committee_id': 'C003'}]
}

Expand Down
15 changes: 0 additions & 15 deletions fec/data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,6 @@ def get_candidate(candidate_id, cycle, election_full):
if cycle_in_range(cycle_tmp)
]

# Annotate committees with most recent available cycle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message could say more about why this complex calculation was not needed, other than the fact that max was throwing errors.

aggregate_cycles = (
list(range(cycle, cycle - cycle_duration, -2))
if show_full_election
else [cycle]
)
for committee in committees:
committee['related_cycle'] = (
max(cycle for cycle in aggregate_cycles
if cycle in committee['cycles'])
if show_full_election
else candidate['two_year_period']
)

# Group the committees by designation
committee_groups = groupby(committees, lambda each: each['designation'])
authorized_committee_ids = [
Expand Down Expand Up @@ -205,7 +191,6 @@ def get_candidate(candidate_id, cycle, election_full):
'result_type': 'candidates',
'duration': cycle_duration,
'cycle_start_year': cycle_start_year,

'report_type': report_type,
'cycles': cycles,
'show_full_election': show_full_election,
Expand Down