Esempio n. 1
0
def raising_breakdown(top_category, cycle):
    if top_category in ['pac']:
        top_raisers = api_caller.load_top_pacs('-receipts', cycle=cycle, per_page=10)
    elif top_category in ['party']:
        top_raisers = api_caller.load_top_parties('-receipts', cycle=cycle, per_page=10)
    else:
        top_raisers = api_caller.load_top_candidates('-receipts', office=top_category, cycle=cycle, per_page=10)

    if cycle == datetime.datetime.today().year:
        coverage_end_date = datetime.datetime.today()
    else:
        coverage_end_date = datetime.date(cycle, 12, 31)

    page_info = top_raisers['pagination']
    return render_template(
        'raising-breakdown.html',
        parent='data',
        title='Raising breakdown',
        top_category=top_category,
        coverage_start_date=datetime.date(cycle - 1, 1, 1),
        coverage_end_date=coverage_end_date,
        cycle=cycle,
        top_raisers=top_raisers['results'],
        page_info=utils.page_info(top_raisers['pagination'])
    )
Esempio n. 2
0
def raising_breakdown(top_category, cycle):
    if top_category in ['pac']:
        top_raisers = api_caller.load_top_pacs('-receipts', cycle=cycle, per_page=10)
    elif top_category in ['party']:
        top_raisers = api_caller.load_top_parties('-receipts', cycle=cycle, per_page=10)
    else:
        top_raisers = api_caller.load_top_candidates('-receipts', office=top_category, cycle=cycle, per_page=10)

    if cycle == datetime.datetime.today().year:
        coverage_end_date = datetime.datetime.today()
    else:
        coverage_end_date = datetime.date(cycle, 12, 31)

    page_info = top_raisers['pagination']
    return render_template(
        'raising-breakdown.html',
        parent='data',
        title='Raising breakdown',
        top_category=top_category,
        coverage_start_date=datetime.date(cycle - 1, 1, 1),
        coverage_end_date=coverage_end_date,
        cycle=cycle,
        top_raisers=top_raisers['results'],
        page_info=utils.page_info(top_raisers['pagination'])
    )
Esempio n. 3
0
def search():
    query = request.args.get('search')
    if query:
        result_type = request.args.get('search_type') or 'candidates'
        results = api_caller.load_search_results(query, result_type)
        return views.render_search_results(results, query, result_type)
    else:
        return render_template('landing.html',
            page='home',
            parent='data',
            dates=utils.date_ranges(),
            top_candidates_raising = api_caller.load_top_candidates('-receipts')['results'],
            top_candidates_spending = api_caller.load_top_candidates('-disbursements')['results'],
            top_pacs_raising = api_caller.load_top_pacs('-receipts')['results'],
            top_pacs_spending = api_caller.load_top_pacs('-disbursements')['results'],
            top_parties_raising = api_caller.load_top_parties('-receipts')['results'],
            top_parties_spending = api_caller.load_top_parties('-disbursements')['results'],
            title='Campaign finance data')