コード例 #1
0
ファイル: views.py プロジェクト: itbidhan/openFEC-web-app
def render_committee(committee, candidates, cycle, redirect_to_previous):
    # committee fields will be top-level in the template
    tmpl_vars = committee

    tmpl_vars['parent'] = 'data'
    tmpl_vars['cycle'] = cycle
    tmpl_vars['year'] = to_date(committee, cycle)
    tmpl_vars['result_type'] = 'committees'

    # Link to current cycle if candidate has a corresponding page, else link
    # without cycle query parameter
    # See https://github.com/18F/openFEC/issues/1536
    for candidate in candidates:
        election_years = [
            election_year for election_year in candidate['election_years']
            if election_year - election_durations[candidate['office']] < cycle <= election_year
        ]
        candidate['related_cycle'] = max(election_years) if election_years else None

    # add related candidates a level below
    tmpl_vars['candidates'] = candidates
    financials = api_caller.load_cmte_financials(committee['committee_id'], cycle=cycle)

    tmpl_vars['report_type'] = report_types.get(committee['committee_type'], 'pac-party')
    tmpl_vars['reports'] = financials['reports']
    tmpl_vars['totals'] = financials['totals']

    tmpl_vars['context_vars'] = {
        'cycle': cycle,
        'timePeriod': str(cycle - 1) + '–' + str(cycle),
        'name': committee['name'],
    }

    if financials['reports'] and financials['totals']:
        # Format the current two-year-period's totals using the process utilities
        if committee['committee_type'] == 'I':
            # IE-only committees have very little data, so they just get this one
            tmpl_vars['ie_summary'] = utils.process_ie_data(financials['totals'][0])
        else:
            # All other committees have three tables
            tmpl_vars['raising_summary'] = utils.process_raising_data(financials['totals'][0])
            tmpl_vars['spending_summary'] = utils.process_spending_data(financials['totals'][0])
            tmpl_vars['cash_summary'] = utils.process_cash_data(financials['totals'][0])

    if redirect_to_previous and not financials['reports']:
        # If there's no reports, find the first year with reports and redirect there
        for c in sorted(committee['cycles'], reverse=True):
            financials = api_caller.load_cmte_financials(committee['committee_id'], cycle=c)
            if financials['reports']:
                return redirect(
                    url_for('committee_page', c_id=committee['committee_id'], cycle=c)
                )
    return render_template('committees-single-new.html', **tmpl_vars)
コード例 #2
0
def render_committee(committee, candidates, cycle):
    # committee fields will be top-level in the template
    tmpl_vars = committee

    tmpl_vars['cycle'] = cycle
    tmpl_vars['year'] = to_date(committee, cycle)
    tmpl_vars['result_type'] = 'committees'

    # Link to current cycle if candidate has a corresponding page, else link
    # without cycle query parameter
    # See https://github.com/18F/openFEC/issues/1536
    for candidate in candidates:
        election_years = [
            election_year for election_year in candidate['election_years']
            if election_year - election_durations[candidate['office']] < cycle <= election_year
        ]
        candidate['related_cycle'] = max(election_years) if election_years else None

    # add related candidates a level below
    tmpl_vars['candidates'] = candidates

    financials = api_caller.load_cmte_financials(committee['committee_id'], cycle=cycle)
    tmpl_vars['reports'] = financials['reports']
    tmpl_vars['totals'] = financials['totals']

    tmpl_vars['context_vars'] = {
        'cycle': cycle,
        'timePeriod': str(cycle - 1) + '–' + str(cycle),
        'name': committee['name']
    }
    return render_template('committees-single.html', **tmpl_vars)
コード例 #3
0
def render_candidate(candidate, committees, cycle):
    # candidate fields will be top-level in the template
    tmpl_vars = candidate

    tmpl_vars['cycle'] = cycle
    tmpl_vars['result_type'] = 'candidates'

    committee_groups = groupby(committees, lambda each: each['designation'])
    committees_authorized = committee_groups.get('P', []) + committee_groups.get('A', [])
    for committee in committees_authorized:
        committee.update(
            api_caller.load_cmte_financials(
                committee['committee_id'],
                cycle=cycle,
            )
        )

    tmpl_vars['committee_groups'] = committee_groups
    tmpl_vars['committees_authorized'] = committees_authorized
    tmpl_vars['committee_ids'] = [committee['committee_id'] for committee in committees_authorized]
    tmpl_vars['aggregate'] = aggregate_committees(committees_authorized)

    tmpl_vars['elections'] = sorted(
        zip(candidate['election_years'], candidate['election_districts']),
        key=lambda pair: pair[0],
        reverse=True,
    )

    return render_template('candidates-single.html', **tmpl_vars)
コード例 #4
0
def add_cmte_financial_data(context, data_type):
    full_cmtes = {}
    cmte_designation_map = {
        'P': 'primary_committee',
        'A': 'authorized_committees',
        'D': 'leadership_committees',
        'J': 'joint_committees'
    }

    if data_type == 'candidate':
        full_cmtes['primary_committee'] = []
        full_cmtes['authorized_committees'] = []
        full_cmtes['leadership_committees'] = []
        full_cmtes['joint_committees'] = []
        candidate = context
        cmtes = candidate.get('committees', [])
        for cmte in cmtes:
            if cmte.get('committee_designation') in ['P', 'A', 'D']:
                cmte.update(load_cmte_financials(cmte['committee_id']))
                cmte.update(_map_committee_financials(cmte))
                tmpl_group = cmte_designation_map[
                    cmte['committee_designation']]
                cmte.update(add_fake_chart_data())
                full_cmtes[tmpl_group].append(cmte)
            elif cmte['committee_designation'] is 'J':
                full_cmtes['joint_committees'].append(cmte)
            else:
                pass
    elif data_type == 'committee':
        cmte = context
        if cmte.get('committee_id'):
            cmte.update(load_cmte_financials(cmte['committee_id']))
            cmte.update(_map_committee_financials(cmte))
            cmte.update(add_fake_chart_data())
        full_cmtes = {'financial_summary': cmte}
    else:
        pass
    return full_cmtes
コード例 #5
0
def add_cmte_financial_data(context, data_type):
    full_cmtes = {}
    cmte_designation_map = {
        'P': 'primary_committee',
        'A': 'authorized_committees',
        'D': 'leadership_committees',
        'J': 'joint_committees'
    }

    if data_type == 'candidate':
        full_cmtes['primary_committee'] = []
        full_cmtes['authorized_committees'] = []
        full_cmtes['leadership_committees'] = []
        full_cmtes['joint_committees'] = []
        candidate = context
        cmtes = candidate.get('committees', [])
        for cmte in cmtes:
            if cmte.get('committee_designation') in ['P', 'A', 'D']:
                cmte.update(load_cmte_financials(cmte['committee_id']))
                cmte.update(_map_committee_financials(cmte))
                tmpl_group = cmte_designation_map[
                    cmte['committee_designation']]
                cmte.update(add_fake_chart_data())
                full_cmtes[tmpl_group].append(cmte)
            elif cmte['committee_designation'] is 'J':
                full_cmtes['joint_committees'].append(cmte)
            else:
                pass
    elif data_type == 'committee':
        cmte = context
        if cmte.get('committee_id'):
            cmte.update(load_cmte_financials(cmte['committee_id']))
            cmte.update(_map_committee_financials(cmte))
            cmte.update(add_fake_chart_data())
        full_cmtes = {'financial_summary': cmte}
    else:
        pass
    return full_cmtes
コード例 #6
0
ファイル: views.py プロジェクト: Guilding/openFEC-web-app
def render_committee(committee, candidates=None, cycle=None):
    # committee fields will be top-level in the template
    tmpl_vars = committee

    tmpl_vars['cycle'] = cycle
    tmpl_vars['year'] = to_date(committee, cycle)
    tmpl_vars['result_type'] = 'committees'

    # add related candidates a level below
    tmpl_vars['candidates'] = candidates

    financials = api_caller.load_cmte_financials(committee['committee_id'], cycle=cycle)
    tmpl_vars['reports'] = financials['reports']
    tmpl_vars['totals'] = financials['totals']

    return render_template('committees-single.html', **tmpl_vars)
コード例 #7
0
ファイル: views.py プロジェクト: 18F/openFEC-web-app
def render_committee(committee, candidates, cycle, redirect_to_previous):
    # committee fields will be top-level in the template
    tmpl_vars = committee

    tmpl_vars['parent'] = 'data'
    tmpl_vars['cycle'] = cycle
    tmpl_vars['year'] = to_date(committee, cycle)
    tmpl_vars['result_type'] = 'committees'

    # Link to current cycle if candidate has a corresponding page, else link
    # without cycle query parameter
    # See https://github.com/18F/openFEC/issues/1536
    for candidate in candidates:
        election_years = [
            election_year for election_year in candidate['election_years']
            if election_year - election_durations[candidate['office']] < cycle <= election_year
        ]
        candidate['related_cycle'] = max(election_years) if election_years else None

    # add related candidates a level below
    tmpl_vars['candidates'] = candidates
    financials = api_caller.load_cmte_financials(committee['committee_id'], cycle=cycle)

    tmpl_vars['report_type'] = report_types.get(committee['committee_type'], 'pac-party')
    tmpl_vars['reports'] = financials['reports']
    tmpl_vars['totals'] = financials['totals']

    tmpl_vars['context_vars'] = {
        'cycle': cycle,
        'timePeriod': str(cycle - 1) + '–' + str(cycle),
        'name': committee['name'],
    }

    if financials['reports'] and financials['totals']:
        # Format the current two-year-period's totals using the process utilities
        if committee['committee_type'] == 'I':
            # IE-only committees have very little data, so they just get this one
            tmpl_vars['ie_summary'] = utils.process_ie_data(financials['totals'][0])
        else:
            # All other committees have three tables
            tmpl_vars['raising_summary'] = utils.process_raising_data(financials['totals'][0])
            tmpl_vars['spending_summary'] = utils.process_spending_data(financials['totals'][0])
            tmpl_vars['cash_summary'] = utils.process_cash_data(financials['totals'][0])

    if redirect_to_previous and not financials['reports']:
        # If there's no reports, find the first year with reports and redirect there
        for c in sorted(committee['cycles'], reverse=True):
            financials = api_caller.load_cmte_financials(committee['committee_id'], cycle=c)
            if financials['reports']:
                return redirect(
                    url_for('committee_page', c_id=committee['committee_id'], cycle=c)
                )

    # If it's not a senate committee and we're in the current cycle
    # check if there's any raw filings in the last two days
    if committee['committee_type'] != 'S' and cycle == utils.current_cycle():
        raw_filings = api_caller._call_api(
            'efile', 'filings',
            cycle=cycle,
            committee_id=committee['committee_id'],
            min_receipt_date=utils.two_days_ago()
        )
        if len(raw_filings.get('results')) > 0:
            tmpl_vars['has_raw_filings'] = True
    else:
        tmpl_vars['has_raw_filings'] = False

    return render_template('committees-single.html', **tmpl_vars)