コード例 #1
0
ファイル: views_datatables.py プロジェクト: romatotti/fec-cms
def committees(request):
    committees = api_caller._call_api('committees')
    return render(
        request, 'datatable.jinja', {
            'parent': 'data',
            'result_type': 'committees',
            'slug': 'committees',
            'title': 'Committees',
            'data': committees['results'],
            'columns': constants.table_columns['committees']
        })
コード例 #2
0
ファイル: views_datatables.py プロジェクト: lhmzhou/fec-cms
def candidates(request):
    candidates = api_caller._call_api('candidates')
    return render(request, 'datatable.jinja', {
        'parent': 'data',
        'result_type': 'candidates',
        'slug': 'candidates',
        'title': 'Candidates',
        'data': candidates['results'],
        'columns': constants.table_columns['candidates'],
        'social_image_identifier': 'data',
    })
コード例 #3
0
def committee(request, committee_id):
    # grab url query string parameters
    cycle = request.GET.get('cycle', None)

    redirect_to_previous = False if cycle else True
    committee, candidates, cycle = api_caller.load_with_nested(
        'committee', committee_id, 'candidates', cycle)

    parent = 'data'
    cycle = int(cycle)
    year = to_date(committee, cycle)
    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
    financials = api_caller.load_cmte_financials(committee_id, cycle=cycle)

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

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

    template_variables = {
        'name': committee['name'],
        'committee': committee,
        'committee_id': committee_id,
        'committee_type_full': committee['committee_type_full'],
        'committee_type': committee['committee_type'],
        'designation_full': committee['designation_full'],
        'street_1': committee['street_1'],
        'city': committee['city'],
        'state': committee['state'],
        'zip': committee['zip'],
        'treasurer_name': committee['treasurer_name'],
        'parent': parent,
        'cycle': cycle,
        'cycles': committee['cycles'],
        'year': year,
        'result_type': result_type,
        'report_type': report_type,
        'reports': reports,
        'totals': totals,
        'min_receipt_date': utils.three_days_ago(),
        'context_vars': context_vars,
        'party_full': committee['party_full']
    }

    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
            template_variables['ie_summary'] = utils.process_ie_data(
                financials['totals'][0])
        else:
            # All other committees have three tables
            template_variables['raising_summary'] = utils.process_raising_data(
                financials['totals'][0])
            template_variables[
                'spending_summary'] = utils.process_spending_data(
                    financials['totals'][0])
            template_variables['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(
                    reverse('committee-by-id',
                            kwargs={'committee_id': committee['committee_id']})
                    + '?cycle=' + str(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 three 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=template_variables['min_receipt_date'])
        if len(raw_filings.get('results')) > 0:
            template_variables['has_raw_filings'] = True
    else:
        template_variables['has_raw_filings'] = False

    return render(request, 'committees-single.jinja', template_variables)