diff --git a/__init__.py b/__init__.py index cdb551cc4..1a34ce63d 100644 --- a/__init__.py +++ b/__init__.py @@ -36,14 +36,19 @@ def search(): else: return render_template('search.html'); +@app.route('/candidate//') +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/') 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/') 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') diff --git a/openfecwebapp/api_caller.py b/openfecwebapp/api_caller.py index 7d7e76f03..ad22b7dd2 100644 --- a/openfecwebapp/api_caller.py +++ b/openfecwebapp/api_caller.py @@ -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) diff --git a/openfecwebapp/tests/selenium/single_candidate_page.py b/openfecwebapp/tests/selenium/single_candidate_page.py index 6c7eace51..66e6f2a2b 100644 --- a/openfecwebapp/tests/selenium/single_candidate_page.py +++ b/openfecwebapp/tests/selenium/single_candidate_page.py @@ -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')) diff --git a/static/js/modules/filters.js b/static/js/modules/filters.js index f425f6dee..e31c0b7e7 100644 --- a/static/js/modules/filters.js +++ b/static/js/modules/filters.js @@ -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 }); @@ -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); diff --git a/templates/candidates-single.html b/templates/candidates-single.html index 4d2669924..1b90a5398 100644 --- a/templates/candidates-single.html +++ b/templates/candidates-single.html @@ -9,8 +9,19 @@