Exemplo n.º 1
0
def candidate_page(c_id, flag=None, cycle=None, election_full=True):
    """Fetch and render data for candidate detail page.

    :param int cycle: Optional cycle for associated committees and financials.
    :param bool election_full: Load full election period

    TEMPORARY: feature flag (flag) to load in a different template.
    """
    candidate, committees, cycle = api_caller.load_with_nested(
        'candidate', c_id, 'committees',
        cycle=cycle, cycle_key='two_year_period',
        election_full=election_full,
    )

    if election_full and cycle and cycle not in candidate['election_years']:
        next_cycle = next(
            (
                year for year in sorted(candidate['election_years'])
                if year > cycle
            ),
            max(candidate['election_years']),
        )
        if flag:
            return redirect(
                url_for('candidate_page', c_id=c_id, flag=flag, cycle=next_cycle, election_full='true')
            )
        else:
            return redirect(
                url_for('candidate_page', c_id=c_id, cycle=next_cycle, election_full='true')
            )

    return views.render_candidate(candidate, committees, flag, cycle, election_full)
Exemplo n.º 2
0
def candidate_page(c_id, cycle=None):
    """Fetch and render data for candidate detail page.

    :param int cycle: Optional cycle for associated committees and financials.
    """
    candidate, committees, cycle = load_with_nested("candidate", c_id, "committees", cycle)
    return views.render_candidate(candidate, committees, cycle)
Exemplo n.º 3
0
def candidate_page(c_id, cycle=None, election_full=True):
    """Fetch and render data for candidate detail page.

    :param int cycle: Optional cycle for associated committees and financials.
    :param bool election_full: Load full election period

    """
    candidate, committees, cycle = api_caller.load_with_nested(
        'candidate', c_id, 'committees',
        cycle=cycle, cycle_key='two_year_period',
        election_full=election_full,
    )

    if election_full and cycle and cycle not in candidate['election_years']:
        next_cycle = next(
            (
                year for year in sorted(candidate['election_years'])
                if year > cycle
            ),
            max(candidate['election_years']),
        )

        # If the next_cycle is odd set it to whatever the cycle value was
        # and then set election_full to false
        # This solves an issue with special elections
        if next_cycle % 2 > 0:
            next_cycle = cycle
            election_full = False

        return redirect(
            url_for('candidate_page', c_id=c_id, cycle=next_cycle, election_full=election_full)
        )

    return views.render_candidate(candidate, committees, cycle, election_full)
Exemplo n.º 4
0
def candidate_page(c_id, cycle=None, election_full=True):
    """Fetch and render data for candidate detail page.

    :param int cycle: Optional cycle for associated committees and financials.
    :param bool election_full: Load full election period
    """
    candidate, committees, cycle = api_caller.load_with_nested(
        'candidate', c_id, 'committees',
        cycle=cycle, cycle_key='two_year_period',
        election_full=election_full,
    )
    if election_full and cycle and cycle not in candidate['election_years']:
        next_cycle = next(
            (
                year for year in sorted(candidate['election_years'])
                if year > cycle
            ),
            max(candidate['election_years']),
        )
        return redirect(
            url_for('candidate_page', c_id=c_id, cycle=next_cycle, election_full='true')
        )
    return views.render_candidate(candidate, committees, cycle, election_full)
Exemplo n.º 5
0
def candidate_page(c_id, cycle=None, election_full=True):
    """Fetch and render data for candidate detail page.

    :param int cycle: Optional cycle for associated committees and financials.
    :param bool election_full: Load full election period

    """
    candidate, committees, cycle = api_caller.load_with_nested(
        'candidate',
        c_id,
        'committees',
        cycle=cycle,
        cycle_key='two_year_period',
        election_full=election_full,
    )

    if election_full and cycle and cycle not in candidate['election_years']:
        next_cycle = next(
            (year
             for year in sorted(candidate['election_years']) if year > cycle),
            max(candidate['election_years']),
        )

        # If the next_cycle is odd set it to whatever the cycle value was
        # and then set election_full to false
        # This solves an issue with special elections
        if next_cycle % 2 > 0:
            next_cycle = cycle
            election_full = False

        return redirect(
            url_for('candidate_page',
                    c_id=c_id,
                    cycle=next_cycle,
                    election_full=election_full))

    return views.render_candidate(candidate, committees, cycle, election_full)