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

Conversation

lbeaufort
Copy link
Member

Summary (required)

Impacted areas of the application

List general components of the application that this PR will affect:

Screenshots:

Before

screen shot 2018-08-29 at 9 43 12 am

After

screen shot 2018-08-29 at 9 43 21 am

Related PRs

#2302 Add tests for candidate view
#2311 Refactor tests for candidate view

lbeaufort and others added 6 commits August 28, 2018 14:56
@lbeaufort lbeaufort changed the title Feature/refactor candidate view Refactor candidate view, fix 404's for future candidates Aug 29, 2018
@patphongs patphongs changed the title Refactor candidate view, fix 404's for future candidates [WIP] Refactor candidate view, fix 404's for future candidates Aug 29, 2018
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
@lbeaufort lbeaufort force-pushed the feature/refactor-candidate-view branch from a9c5787 to 32abdd3 Compare August 29, 2018 20:13
@lbeaufort lbeaufort changed the title [WIP] Refactor candidate view, fix 404's for future candidates Refactor candidate view, fix 404's for future candidates Aug 29, 2018
@codecov-io
Copy link

Codecov Report

Merging #2320 into develop will increase coverage by 0.01%.
The diff coverage is 87.5%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
fec/data/tests/test_candidate.py 100% <100%> (ø) ⬆️
fec/data/views.py 33.51% <85%> (-1.9%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6f7998...32abdd3. Read the comment docs.

{% 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">
Copy link
Member Author

@lbeaufort lbeaufort Aug 29, 2018

Choose a reason for hiding this comment

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

This should be data-election-full="false", lower case (fixed with this commit). It was causing a bug where going from raising/spending pages on an off-election year and then back to the financial summary tab wasn't selecting the 2-year time period button:
screen shot 2018-08-29 at 4 49 23 pm

Copy link
Contributor

@vrajmohan vrajmohan left a 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>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -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
Copy link
Contributor

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?

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']
Copy link
Contributor

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')))
Copy link
Contributor

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?

Copy link
Member Author

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.

@@ -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
Copy link
Contributor

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.

@@ -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.

Copy link
Contributor

@apburnes apburnes left a 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.

@vrajmohan vrajmohan merged commit d1cc4f8 into develop Aug 31, 2018
@vrajmohan vrajmohan deleted the feature/refactor-candidate-view branch August 31, 2018 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

404 Errors when clicking through to individual candidate/committee pages
4 participants