Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Merge pull request #74 from 18F/election-cycle
Browse files Browse the repository at this point in the history
Adds election cycle picker to candidate pages
  • Loading branch information
Marco Segreto committed Apr 16, 2015
2 parents 3715019 + ef10f55 commit d0f160b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
9 changes: 7 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ def search():
else:
return render_template('search.html');

@app.route('/candidate/<c_id>/<cycle>')
def candidate_page_with_cycle(c_id, cycle):
data = load_single_type('candidate', c_id, {'year': cycle})
return render_page('candidate', data)

@app.route('/candidate/<c_id>')
def candidate_page(c_id):
data = load_single_type('candidate', c_id)
data = load_single_type('candidate', c_id, {})
return render_page('candidate', data)

@app.route('/committee/<c_id>')
def committee_page(c_id):
data = load_single_type('committee', c_id)
data = load_single_type('committee', c_id, {})
return render_page('committee', data)

@app.route('/candidates')
Expand Down
3 changes: 1 addition & 2 deletions openfecwebapp/api_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ def load_single_type_summary(data_type, filters):

return _call_api(url, filters)

def load_single_type(data_type, c_id):
def load_single_type(data_type, c_id, filters):
url = '/' + data_type + '/' + c_id
filters = {'year': '*'}

return _call_api(url, filters)

Expand Down
17 changes: 14 additions & 3 deletions openfecwebapp/tests/selenium/single_candidate_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@
class SingleCandidatePageTests(BaseTest):

def setUp(self):
self.url = self.base_url + '/candidate/H4MA09052'
self.url = self.base_url + '/candidate/P80003338'

def testSingleCandidatePageLoads(self):
self.driver.get(self.url)
self.assertEqual(
self.driver.find_element_by_tag_name('h1').text,
'ALLIEGRO, MARK C')
'OBAMA, BARACK')

def testCommitteeLink(self):
self.driver.get(self.url)
self.assertTrue(self.elementExistsByXPath('//a[contains(@href, "committee/")]'))
link = self.driver.find_element_by_xpath('//a[contains(@href, "committees/")]')
self.assertEqual(link.text, 'COMMITTEE TO ELECT MARK ALLIEGRO')
self.assertEqual(link.text, 'OBAMA FOR AMERICA')

def testElectionCycleChooser(self):
self.driver.get(self.url)
self.assertEqual(
self.driver.find_element_by_css_selector('select[name=election_cycle] .chosen-container .chosen-single span').text,
'2011 - 2012'))
// election cycle chooser drop down arrow
self.driver.find_element_by_xpath('//*[@id="main"]/div/header/div/div[1]/div[2]/div/a/div').click()
self.assertEqual(
self.driver.find_element_by_xpath('//*[@id="main"]/div/header/div/div[1]/div[2]/div/div/ul/li[2]'.text,
'2007 - 2008'))
16 changes: 15 additions & 1 deletion static/js/modules/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var deactivateFilter = function() {
};

var bindFilters = function(e) {
$('#category-filters select').chosen({
$('#category-filters select, select[name=election_cycle]').chosen({
width: "100%",
allow_single_deselect: true
});
Expand Down Expand Up @@ -67,6 +67,20 @@ var bindFilters = function(e) {
}
});

// election cycle dropdown functionality
$('select[name=election_cycle]').chosen().change(function(e, selected) {
var $e = $(e.target),
url = document.location.origin
+ '/'
+ $e.attr('data-type')
+ '/'
+ $e.attr('data-id')
+ '/'
+ selected.selected;

document.location = url;
});

// apply name filter
$('#category-filters').on('click', '.add-filter__button', function() {
var $plusButton = $(this);
Expand Down
15 changes: 13 additions & 2 deletions templates/candidates-single.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@
<header class="page-header entity__header">
<div class="container">
<div class="entity__header--top row">
<h1 class="entity__name">{{ name }}</h1>
<span class="entity__type"><img class="category-icon" width="20" height="20" src="/static/img/icon-candidate--white.svg" alt="Icon representing candidates">Candidate for {{ office }}</span>
<div class="chunk--two-thirds">
<h1 class="entity__name">{{ name }}</h1>
<span class="entity__type"><img class="category-icon" width="20" height="20" src="/static/img/icon-candidate--white.svg" alt="Icon representing candidates">Candidate for {{ office }}</span>
</div>
{% if election_years %}
<div class="chunk--third u-float-right">
<select name="election_cycle" data-id="{{ candidate_id }}" data-type="candidate">
{% for year in election_years|sort(reverse=True) %}
<option value="{{ year }}">{{ year|int - 1 }} - {{ year }}</option>
{% endfor %}
</select>
</div>
{% endif %}
</div>
<div class="entity__header--bottom row">
<ul class="entity__info">
Expand Down

0 comments on commit d0f160b

Please sign in to comment.