-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
Fix line lengths, whitespace, remove statements that do nothing
Use @library.filter filters.date()
max_cycle and cycle will always be the same value
This change originally came from PR fecgov/openFEC-web-app#1945. After much investigation, I can't see any use case for this logic given the current setup, so I'm removing it. The user interface ensures on the "financial summary", "about this candidate", and "spending by other tabs", where the cycle options correspond with election_years, election_year/cycle will always be a valid election year.
The max() function in "Annotate committees with most recent available cycle" was throwing errors - this simplifies the logic
Allow two_year_select to be passed election_full values for candidate pages
a9c5787
to
32abdd3
Compare
Codecov Report
@@ Coverage Diff @@
## develop #2320 +/- ##
===========================================
+ Coverage 74.06% 74.08% +0.01%
===========================================
Files 112 112
Lines 6582 6567 -15
Branches 807 800 -7
===========================================
- Hits 4875 4865 -10
+ Misses 1655 1654 -1
+ Partials 52 48 -4
Continue to review full report at Codecov.
|
{% set cycle = cycle | int %} | ||
<div class="content__section"> | ||
<label for="{{id}}-cycle" class="label cycle-select__label">Election</label> | ||
<select id="{{id}}-cycle" class="js-cycle" name="cycle" data-cycle-location="query" data-election-full="False"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some minor comments. I can merge it even without those being addressed.
@@ -48,7 +48,7 @@ | |||
{% if statement.fec_file_id %} | |||
<div class="t-small u-small-icon-padding--left"> {{ statement.fec_file_id }}</div> | |||
{% endif %} | |||
<div class="u-small-icon-padding--left"> Filed {{ statement.receipt_date }}</div> | |||
<div class="u-small-icon-padding--left"> Filed {{ statement.receipt_date|date }}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
fec/data/views.py
Outdated
@@ -126,7 +126,7 @@ def get_candidate(candidate_id, cycle, election_full): | |||
|
|||
result_type = 'candidates' | |||
duration = election_durations.get(candidate['office'], 2) | |||
min_cycle = cycle - duration if election_full else cycle | |||
cycle_start_year = cycle - duration if election_full else cycle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still confusing to me. If the cycle is 2016 and the office is "President", isn't the cycle start year 2011 and not 2010?
fec/data/views.py
Outdated
max_cycle = cycle if cycle <= utils.current_cycle() else utils.current_cycle() | ||
show_full_election = election_full if cycle <= utils.current_cycle() else False | ||
cycles = [ | ||
cycle_tmp for cycle_tmp in candidate['cycles'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor - it is cleaner to use cycle
as the list comprehension variable as done in line 164 below.
@@ -252,8 +254,7 @@ def candidate(request, candidate_id): | |||
if cycle is not None: | |||
cycle = int(cycle) | |||
|
|||
election_full = request.GET.get('election_full', True) | |||
election_full = bool(strtobool(str(election_full))) | |||
election_full = bool(strtobool(request.GET.get('election_full', 'True'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor - do we really need distutils.util.strtobool
? Isn't the input controlled by us or specified in our API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it seems overly complex - I'm planning to address this here so I can test thoroughly.
fec/data/views.py
Outdated
@@ -105,32 +105,6 @@ def get_candidate(candidate_id, cycle, election_full): | |||
election_full=show_full_election, | |||
) | |||
|
|||
# cycle corresponds to the two-year period for which the committee has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Nice work on the commit message as well.
fec/data/views.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and runs well.
Summary (required)
Refactor candidate view, fix 404's for future cycle candidates without committees, simplify 2-year select macro and use it for the candidate raising/spending pages
Impacted areas of the application
List general components of the application that this PR will affect:
Candidate profile pages
Candidate raising/spending pages now show two-year period label (that's what we display) instead of election (election label was incorrect). Committee two-year period dropdowns should be unchanged - renamed to
two_year_select
Test previously 404-ing candidate pages:
http://localhost:8000/data/candidate/H0TX09168/
http://localhost:8000/data/candidate/P40003832/
Test future/past House/Senate/Presidential pages
Screenshots:
Before
After
Related PRs
#2302 Add tests for candidate view
#2311 Refactor tests for candidate view