def test_get_cycles(self, current_cycle): # Mock out the current_cycle so it doesn't change in the future current_cycle.return_value = 2016 # Check that it returns the correct default when no arg supplied assert utils.get_cycles() == range(2016, 1979, -2) # Check that it returns the correct range when an arg is supplied assert utils.get_cycles(2020) == range(2020, 1979, -2)
def elections(office, cycle, state=None, district=None): # Get all cycles up until the cycle from the URL if it's beyond the current cycle # this fixes the issue of an election page not showing user-provided cycle # in the cycle select max_cycle = cycle if cycle > utils.current_cycle( ) else utils.current_cycle() cycles = utils.get_cycles(max_cycle) if office.lower() == 'president': cycles = [each for each in cycles if each % 4 == 0] elif office.lower() == 'senate': cycles = utils.get_state_senate_cycles(state) if office.lower() not in ['president', 'senate', 'house']: abort(404) if state and state.upper() not in constants.states: abort(404) return render_template( 'elections.html', office=office, office_code=office[0], parent='data', cycle=cycle, cycles=cycles, state=state, state_full=constants.states[state.upper()] if state else None, district=district, title=utils.election_title(cycle, office, state, district), )
def elections(office, cycle, state=None, district=None): # Get all cycles up until the cycle from the URL if it's beyond the current cycle # this fixes the issue of an election page not showing user-provided cycle # in the cycle select max_cycle = cycle if cycle > utils.current_cycle() else utils.current_cycle() cycles = utils.get_cycles(max_cycle) if office.lower() == 'president': cycles = [each for each in cycles if each % 4 == 0] elif office.lower() == 'senate': cycles = utils.get_state_senate_cycles(state) if office.lower() not in ['president', 'senate', 'house']: abort(404) if state and state.upper() not in constants.states: abort(404) return render_template( 'elections.html', office=office, office_code=office[0], parent='data', cycle=cycle, cycles=cycles, state=state, state_full=constants.states[state.upper()] if state else None, district=district, title=utils.election_title(cycle, office, state, district), )
def elections(office, cycle, state=None, district=None): if office.lower() not in ['president', 'senate', 'house']: abort(404) if state and state.upper() not in constants.states: abort(404) cycles = utils.get_cycles() if office.lower() == 'president': cycles = [each for each in cycles if each % 4 == 0] return render_template( 'elections.html', office=office, office_code=office[0], cycle=cycle, cycles=cycles, state=state, state_full=constants.states[state.upper()] if state else None, district=district, title=utils.election_title(cycle, office, state, district), )
app.jinja_env.globals.update(vars(config)) app.jinja_env.globals.update({ 'min': min, 'max': max, 'context': filters.get_context, 'absolute_url': get_absolute_url, 'contact_email': '*****@*****.**', 'default_cycles': _get_default_cycles(), 'series_has_data': series_has_data, 'group_has_data': group_has_data, 'series_group_has_data': series_group_has_data, 'cycle_start': cycle_start, 'cycle_end': cycle_end, 'election_url': get_election_url, 'constants': constants, 'cycles': utils.get_cycles(), 'assets': assets, 'asset_for': asset_for, 'asset_for_page': asset_for_page, 'base_path': get_base_path, 'today': datetime.date.today, 'format_election_years': format_election_years, 'clean_id': clean_id, }) app.add_url_rule('/issue/', view_func=views.GithubView.as_view('issue')) @app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404