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

Fix candidate page 404 errors due to missing district #2500

Merged
merged 4 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fec/data/templates/candidates-single.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@
<li><a href="#other">Other documents filed</a></li>
</ul>
</li>
{% if get_election_url(candidate, election_year, district) %}
<li class="side-nav__item">
<a class="button button--cta u-margin--top t-left-aligned button--two-candidates u-full-width" href="{{ get_election_url(candidate, election_year, district) }}">Compare to<br>opposing candidates</a>
</li>
{% endif %}
</ul>
</nav>

Expand Down
4 changes: 2 additions & 2 deletions fec/data/templates/partials/candidate/about-candidate.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
</table>

<div class="usa-width-one-fourth">
{% if get_election_url(candidate, election_year, district) %}
<div class="card">
{% if get_election_url(candidate, election_year, district) %}
<a href="{{ get_election_url(candidate, election_year, district) }}">
<div class="card__image__container">
<img class="icon--complex" src="/static/img/i-elections--primary.svg" alt="Icon representing elections">
Expand All @@ -63,8 +63,8 @@
View all candidates in the {% if election_year %}{{ election_year }} {% endif %}{% if constants.states[state] %}{{ constants.states[state] }}{% endif %} {% if office == 'P' %}Presidential{% else %}{{ office_full }}{% endif %}{% if office_full == 'House' %} District {{ district|strip_zero_pad }}{% endif %} election
</div>
</a>
{% endif %}
</div>
{% endif %}
</div>
</div>

Expand Down
14 changes: 11 additions & 3 deletions fec/data/templatetags/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ def nullify(value, *nulls):
def get_election_url(candidate, cycle, district=None):
if cycle:
if candidate['office'] == 'H':
district_url = '/' + str(candidate['state']) + '/' + candidate['district']
if candidate.get('state') and candidate.get('district'):
district_url = '/' + str(candidate['state']) + '/' + candidate['district']
else:
return None
elif candidate['office'] == 'S':
district_url = '/' + str(candidate['state'])
if candidate.get('state'):
district_url = '/' + str(candidate['state'])
else:
return None
else:
district_url = ''

Expand Down Expand Up @@ -101,7 +107,9 @@ def strip_zero_pad(number):
Removes leading 0's for display purposes
Commonly used for congressional districts
'''
return number.lstrip("0")
if number:
return number.lstrip("0")
return "None"


def date_filter(value, fmt='%m/%d/%Y'):
Expand Down
4 changes: 0 additions & 4 deletions fec/data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ def get_candidate(candidate_id, cycle, election_full):
'A', []
)

committee_groups = committee_groups
committees_authorized = committees_authorized
committee_ids = [committee['committee_id'] for committee in committees_authorized]

# Get aggregate totals for the financial summary
Expand All @@ -205,8 +203,6 @@ def get_candidate(candidate_id, cycle, election_full):
spending_summary = None
cash_summary = None

aggregate = aggregate

# Get totals for the last two-year period of a cycle for showing on
# raising and spending tabs
two_year_totals = api_caller.load_candidate_totals(
Expand Down