def get_candidate(request, cycle, candidate_id, sked): if not is_valid_four_digit_string_cycle(cycle): return None celery_request = dump_candidate_sked_celery.apply_async( [cycle, sked, candidate_id], queue='fast', routing_key="fast") task_id = celery_request.id return redirect('/download/build_file/%s/' % task_id)
def senate(request, cycle): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 title="Senate - Cycle Summary" explanatory_text="Fundraising totals are for the selected two-year election cycle for Senate candidates who reported having $1,000 or more, or who have been targeted by $1,000 or more in independent expenditures. Only candidates actually running in the current cycle who filed a statement of candidacy are included. If we included anyone who isn't running--or missed anyone who is, please <a href='mailto:[email protected]'>let us know</a>. Please note these totals reflect current FEC filings and may not match the summarized data available elsewhere on Influence Explorer." # Give up on ORM for data; we're not willing to enforce all the relationships required for them districts = District.objects.filter(office='S', cycle=cycle) legislators = Candidate_Overlay.objects.filter(office='S', cycle=cycle).filter(Q(cash_on_hand__gte=1000)|Q(is_incumbent=True)|Q(total_expenditures__gte=1000)).select_related('district').order_by('-cash_on_hand') districts = District.objects.filter(office='H', cycle=cycle) other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [cycle_fake(cycle, "/senate/%s/" % cycle), cycle_fake(other_year, "/senate/%s/" % other_year)] return render_to_response('datapages/senate_legislator_list.html', { 'STATE_LIST':STATE_LIST, 'districts':districts, 'object_list':legislators, 'title':title, 'explanatory_text':explanatory_text, 'cycle_list':cycle_list }, context_instance=RequestContext(request) )
def downloads(request, cycle): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [ cycle_fake(cycle, "/download-index/%s/" % cycle), cycle_fake(other_year, "/download-index/%s/" % other_year) ] title = "Bulk Downloads" update_time = get_update_time(BULK_EXPORT_KEY) return render_to_response('datapages/downloads.html', { 'title': title, 'cycle': cycle, 'cycle_list': cycle_list, 'update_time': update_time, }, context_instance=RequestContext(request))
def downloads(request, cycle): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [cycle_fake(cycle, "/download-index/%s/" % cycle), cycle_fake(other_year, "/download-index/%s/" % other_year)] title="Bulk Downloads" update_time = get_update_time(BULK_EXPORT_KEY) return render_to_response('datapages/downloads.html', { 'title':title, 'cycle':cycle, 'cycle_list':cycle_list, 'update_time':update_time, }, context_instance=RequestContext(request) )
def races(request, cycle): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 title="Race-wide spending totals for %s cycle" % (cycle) explanatory_text="District totals (ie. House and Senate races) are based on the most recent information available, but different political groups report to the FEC on different schedules. Super PACs must report independent expenditures within 48- or 24-hours, but candidate committees only disclose on a quarterly basis. Please note these totals reflect current FEC filings and may not match the summarized data available elsewhere on Influence Explorer. <br>For primary contests see our list of <a href='/competitive-primaries/'>competitive primaries</a>." other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [cycle_fake(cycle, "/races/%s/" % cycle), cycle_fake(other_year, "/races/%s/" % other_year)] districts = District.objects.filter(cycle=cycle) return render_to_response('datapages/races.html', { 'STATE_LIST':STATE_LIST, 'title':title, 'explanatory_text':explanatory_text, 'races':districts, 'cycle_list':cycle_list }, context_instance=RequestContext(request) )
def races(request, cycle): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 title = "Race-wide spending totals for %s cycle" % (cycle) explanatory_text = "District totals (ie. House and Senate races) are based on the most recent information available, but different political groups report to the FEC on different schedules. Super PACs must report independent expenditures within 48- or 24-hours, but candidate committees only disclose on a quarterly basis. Please note these totals reflect current FEC filings and may not match the summarized data available elsewhere on Influence Explorer. <br>For primary contests see our list of <a href='/competitive-primaries/'>competitive primaries</a>." other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [ cycle_fake(cycle, "/races/%s/" % cycle), cycle_fake(other_year, "/races/%s/" % other_year) ] districts = District.objects.filter(cycle=cycle) return render_to_response('datapages/races.html', { 'STATE_LIST': STATE_LIST, 'title': title, 'explanatory_text': explanatory_text, 'races': districts, 'cycle_list': cycle_list }, context_instance=RequestContext(request))
def committee_cycle(request, cycle, committee_id): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 cycle_endpoints = get_cycle_endpoints(int(cycle)) committee_overlay = get_object_or_404(Committee_Overlay, fec_id=committee_id, cycle=int(cycle)) title = committee_overlay.name + " (%s cycle )" % (cycle) report_list = Committee_Time_Summary.objects.filter(com_id=committee_id, coverage_from_date__gte=cycle_endpoints['start'], coverage_from_date__lte=cycle_endpoints['end']).order_by('-coverage_through_date') end_of_coverage_date = committee_overlay.cash_on_hand_date recent_report_list = None if end_of_coverage_date: relevant_date = max(end_of_coverage_date, cycle_endpoints['start']) recent_report_list = new_filing.objects.filter(fec_id=committee_id, coverage_from_date__gte=relevant_date, coverage_to_date__lte=cycle_endpoints['end'], form_type__in=['F5A', 'F5', 'F5N', 'F24', 'F24A', 'F24N', 'F6', 'F6A', 'F6N']).exclude(is_f5_quarterly=True).exclude(is_superceded=True) else: recent_report_list = new_filing.objects.filter(fec_id=committee_id, coverage_from_date__gte=cycle_endpoints['start'], coverage_to_date__lte=cycle_endpoints['end'], form_type__in=['F5A', 'F5', 'F5N', 'F24', 'F24A', 'F24N', 'F6', 'F6A', 'F6N']).exclude(is_f5_quarterly=True).exclude(is_superceded=True) independent_spending = Pac_Candidate.objects.filter(committee=committee_overlay, total_ind_exp__gte=5000, cycle=cycle).select_related('candidate') recent_ies = None if committee_overlay.total_indy_expenditures > 5000: recent_ies = SkedE.objects.filter(filer_committee_id_number=committee_id, expenditure_amount__gte=5000, superceded_by_amendment=False, expenditure_date_formatted__gte=cycle_endpoints['start'], expenditure_date_formatted__lte=cycle_endpoints['end']).select_related('candidate_checked').order_by('-expenditure_date_formatted')[:10] # figure out which cycles are available. The current one goes first, because it is being displayed. cycle_values = Committee_Overlay.objects.filter(fec_id=committee_id).exclude(cycle=cycle) cycle_list = [committee_overlay] + list(cycle_values) return render_to_response('datapages/committee_cycle.html', { 'title':title, 'report_list':report_list, 'recent_report_list':recent_report_list, 'committee':committee_overlay, 'independent_spending':independent_spending, 'recent_ies':recent_ies, 'cycle_list':cycle_list, 'cycle':cycle, }, context_instance=RequestContext(request) )
def pacs(request, cycle): if not is_valid_four_digit_string_cycle(cycle): raise Http404 other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [cycle_fake(cycle, "/pacs/%s/" % cycle), cycle_fake(other_year, "/pacs/%s/" % other_year)] return render_to_response('datapages/dynamic_pacs.html', { 'explanatory_text':'Find and filter committee summary information for an entire two-year cycle (2016 or 2014). Review how much groups raised and spent, their debts and cash on hand. Click the committee name to see filings. For more, see a <a href="/about/#pacs">more detailed explanation</a>.', 'title':'Political action committee summaries', 'PAGINATE_BY':PAGINATE_BY, 'cycle_list':cycle_list }, context_instance=RequestContext(request) )
def senate(request, cycle): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 title = "Senate - Cycle Summary" explanatory_text = "Fundraising totals are for the selected two-year election cycle for Senate candidates who reported having $1,000 or more, or who have been targeted by $1,000 or more in independent expenditures. Only candidates actually running in the current cycle who filed a statement of candidacy are included. If we included anyone who isn't running--or missed anyone who is, please <a href='mailto:[email protected]'>let us know</a>. Please note these totals reflect current FEC filings and may not match the summarized data available elsewhere on Influence Explorer." # Give up on ORM for data; we're not willing to enforce all the relationships required for them districts = District.objects.filter(office='S', cycle=cycle) legislators = Candidate_Overlay.objects.filter( office='S', cycle=cycle).filter( Q(cash_on_hand__gte=1000) | Q(is_incumbent=True) | Q(total_expenditures__gte=1000)).select_related( 'district').order_by('-cash_on_hand') districts = District.objects.filter(office='H', cycle=cycle) other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [ cycle_fake(cycle, "/senate/%s/" % cycle), cycle_fake(other_year, "/senate/%s/" % other_year) ] return render_to_response('datapages/senate_legislator_list.html', { 'STATE_LIST': STATE_LIST, 'districts': districts, 'object_list': legislators, 'title': title, 'explanatory_text': explanatory_text, 'cycle_list': cycle_list }, context_instance=RequestContext(request))
def pacs(request, cycle): if not is_valid_four_digit_string_cycle(cycle): raise Http404 other_year = None if cycle == '2016': other_year = '2014' elif cycle == '2014': other_year = '2016' cycle_list = [ cycle_fake(cycle, "/pacs/%s/" % cycle), cycle_fake(other_year, "/pacs/%s/" % other_year) ] return render_to_response('datapages/dynamic_pacs.html', { 'explanatory_text': 'Find and filter committee summary information for an entire two-year cycle (2016 or 2014). Review how much groups raised and spent, their debts and cash on hand. Click the committee name to see filings. For more, see a <a href="/about/#pacs">more detailed explanation</a>.', 'title': 'Political action committee summaries', 'PAGINATE_BY': PAGINATE_BY, 'cycle_list': cycle_list }, context_instance=RequestContext(request))
def get_candidate(request, cycle, candidate_id, sked): if not is_valid_four_digit_string_cycle(cycle): return None celery_request = dump_candidate_sked_celery.apply_async([cycle,sked,candidate_id], queue='fast',routing_key="fast") task_id = celery_request.id return redirect('/download/build_file/%s/' % task_id)
def candidate_cycle(request, slug, candidate_id, cycle): if not is_valid_four_digit_string_cycle(cycle): raise Http404 # figure out which cycles are available. The current one goes first, because it is being displayed. cycles = Candidate_Overlay.objects.filter(fec_id=candidate_id) candidate_overlay = None try: candidate_overlay = cycles.get(cycle=cycle) except Candidate_Overlay.DoesNotExist: if len(cycles) > 0: candidate_overlay = cycles.order_by('-cycle')[0] return redirect("/candidate/%s/%s/%s/" % (candidate_overlay.cycle, slug, candidate_id)) else: raise Http404 other_cycles = cycles.exclude(cycle=cycle) cycle_list = [candidate_overlay] + list(other_cycles) cycle_endpoints = get_cycle_endpoints(int(cycle)) title = "%s (%s) (%s cycle)" % (candidate_overlay.name, candidate_overlay.party, cycle) authorized_committee_list = Authorized_Candidate_Committees.objects.filter(candidate_id=candidate_id, cycle=cycle) committee_list = [x.get('committee_id') for x in authorized_committee_list.values('committee_id')] report_list = Committee_Time_Summary.objects.filter(com_id__in=committee_list, coverage_from_date__gte=cycle_endpoints['start'], coverage_through_date__lte=cycle_endpoints['end']).order_by('-coverage_through_date') end_of_coverage_date = None recent_report_list = None if report_list: end_of_coverage_date = report_list[0].coverage_through_date recent_report_total = 0 if end_of_coverage_date: recent_report_list = new_filing.objects.filter(fec_id__in=committee_list, coverage_from_date__gte=end_of_coverage_date, coverage_to_date__lte=cycle_endpoints['end'], form_type__in=['F6', 'F6A', 'F6N']).exclude(is_superceded=True) if recent_report_list: recent_report_total = recent_report_list.aggregate(spending_total=Sum('tot_raised'))['spending_total'] else: recent_report_list = new_filing.objects.filter(fec_id__in=committee_list, coverage_from_date__gte=cycle_endpoints['start'], coverage_to_date__lte=cycle_endpoints['end'], form_type__in=['F6', 'F6A', 'F6N']).exclude(is_superceded=True) # are their outside groups who've spent for/against this candidate? outside_spenders = Pac_Candidate.objects.filter(candidate=candidate_overlay, cycle=cycle, total_ind_exp__gte=1000).select_related('committee') recent_ies = None if outside_spenders: recent_ies = SkedE.objects.filter(candidate_checked=candidate_overlay, expenditure_amount__gte=5000, superceded_by_amendment=False, expenditure_date_formatted__gte=cycle_endpoints['start'], expenditure_date_formatted__lte=cycle_endpoints['end'] ).select_related('candidate_checked').order_by('-expenditure_date_formatted')[:10] return render_to_response('datapages/candidate.html', { 'title':title, 'report_list':report_list, 'candidate':candidate_overlay, 'authorized_committee_list':authorized_committee_list, 'outside_spenders':outside_spenders, 'recent_report_list':recent_report_list, 'recent_ies':recent_ies, 'recent_report_total':recent_report_total, 'cycle_list':cycle_list, 'current_cycle':cycle }, context_instance=RequestContext(request) )
def candidate_cycle(request, slug, candidate_id, cycle): if not is_valid_four_digit_string_cycle(cycle): raise Http404 # figure out which cycles are available. The current one goes first, because it is being displayed. cycles = Candidate_Overlay.objects.filter(fec_id=candidate_id) candidate_overlay = None try: candidate_overlay = cycles.get(cycle=cycle) except Candidate_Overlay.DoesNotExist: if len(cycles) > 0: candidate_overlay = cycles.order_by('-cycle')[0] return redirect("/candidate/%s/%s/%s/" % (candidate_overlay.cycle, slug, candidate_id)) else: raise Http404 other_cycles = cycles.exclude(cycle=cycle) cycle_list = [candidate_overlay] + list(other_cycles) cycle_endpoints = get_cycle_endpoints(int(cycle)) title = "%s (%s) (%s cycle)" % (candidate_overlay.name, candidate_overlay.party, cycle) authorized_committee_list = Authorized_Candidate_Committees.objects.filter( candidate_id=candidate_id, cycle=cycle) committee_list = [ x.get('committee_id') for x in authorized_committee_list.values('committee_id') ] report_list = Committee_Time_Summary.objects.filter( com_id__in=committee_list, coverage_from_date__gte=cycle_endpoints['start'], coverage_through_date__lte=cycle_endpoints['end']).order_by( '-coverage_through_date') end_of_coverage_date = None recent_report_list = None if report_list: end_of_coverage_date = report_list[0].coverage_through_date recent_report_total = 0 if end_of_coverage_date: recent_report_list = new_filing.objects.filter( fec_id__in=committee_list, coverage_from_date__gte=end_of_coverage_date, coverage_to_date__lte=cycle_endpoints['end'], form_type__in=['F6', 'F6A', 'F6N']).exclude(is_superceded=True) if recent_report_list: recent_report_total = recent_report_list.aggregate( spending_total=Sum('tot_raised'))['spending_total'] else: recent_report_list = new_filing.objects.filter( fec_id__in=committee_list, coverage_from_date__gte=cycle_endpoints['start'], coverage_to_date__lte=cycle_endpoints['end'], form_type__in=['F6', 'F6A', 'F6N']).exclude(is_superceded=True) # are their outside groups who've spent for/against this candidate? outside_spenders = Pac_Candidate.objects.filter( candidate=candidate_overlay, cycle=cycle, total_ind_exp__gte=1000).select_related('committee') recent_ies = None if outside_spenders: recent_ies = SkedE.objects.filter( candidate_checked=candidate_overlay, expenditure_amount__gte=5000, superceded_by_amendment=False, expenditure_date_formatted__gte=cycle_endpoints['start'], expenditure_date_formatted__lte=cycle_endpoints['end'] ).select_related('candidate_checked').order_by( '-expenditure_date_formatted')[:10] return render_to_response('datapages/candidate.html', { 'title': title, 'report_list': report_list, 'candidate': candidate_overlay, 'authorized_committee_list': authorized_committee_list, 'outside_spenders': outside_spenders, 'recent_report_list': recent_report_list, 'recent_ies': recent_ies, 'recent_report_total': recent_report_total, 'cycle_list': cycle_list, 'current_cycle': cycle }, context_instance=RequestContext(request))
def committee_cycle(request, cycle, committee_id): if not is_valid_four_digit_string_cycle(cycle): # should redirect, but for now: raise Http404 cycle_endpoints = get_cycle_endpoints(int(cycle)) committee_overlay = get_object_or_404(Committee_Overlay, fec_id=committee_id, cycle=int(cycle)) title = committee_overlay.name + " (%s cycle )" % (cycle) report_list = Committee_Time_Summary.objects.filter( com_id=committee_id, coverage_from_date__gte=cycle_endpoints['start'], coverage_from_date__lte=cycle_endpoints['end']).order_by( '-coverage_through_date') end_of_coverage_date = committee_overlay.cash_on_hand_date recent_report_list = None if end_of_coverage_date: relevant_date = max(end_of_coverage_date, cycle_endpoints['start']) recent_report_list = new_filing.objects.filter( fec_id=committee_id, coverage_from_date__gte=relevant_date, coverage_to_date__lte=cycle_endpoints['end'], form_type__in=[ 'F5A', 'F5', 'F5N', 'F24', 'F24A', 'F24N', 'F6', 'F6A', 'F6N' ]).exclude(is_f5_quarterly=True).exclude(is_superceded=True) else: recent_report_list = new_filing.objects.filter( fec_id=committee_id, coverage_from_date__gte=cycle_endpoints['start'], coverage_to_date__lte=cycle_endpoints['end'], form_type__in=[ 'F5A', 'F5', 'F5N', 'F24', 'F24A', 'F24N', 'F6', 'F6A', 'F6N' ]).exclude(is_f5_quarterly=True).exclude(is_superceded=True) independent_spending = Pac_Candidate.objects.filter( committee=committee_overlay, total_ind_exp__gte=5000, cycle=cycle).select_related('candidate') recent_ies = None if committee_overlay.total_indy_expenditures > 5000: recent_ies = SkedE.objects.filter( filer_committee_id_number=committee_id, expenditure_amount__gte=5000, superceded_by_amendment=False, expenditure_date_formatted__gte=cycle_endpoints['start'], expenditure_date_formatted__lte=cycle_endpoints['end'] ).select_related('candidate_checked').order_by( '-expenditure_date_formatted')[:10] # figure out which cycles are available. The current one goes first, because it is being displayed. cycle_values = Committee_Overlay.objects.filter( fec_id=committee_id).exclude(cycle=cycle) cycle_list = [committee_overlay] + list(cycle_values) return render_to_response('datapages/committee_cycle.html', { 'title': title, 'report_list': report_list, 'recent_report_list': recent_report_list, 'committee': committee_overlay, 'independent_spending': independent_spending, 'recent_ies': recent_ies, 'cycle_list': cycle_list, 'cycle': cycle, }, context_instance=RequestContext(request))