<s> from datetime import datetime , date <EOL> from django . template import Template <EOL> from django . template . loader import get_template <EOL> from django . template import Context <EOL> from django . conf import settings <EOL> from django . db . models import Sum , Count <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . contrib . flatpages . models import FlatPage <EOL> from django . contrib . sites . models import Site <EOL> from django . conf import settings <EOL> from formdata . models import SkedE <EOL> from summary_data . models import Committee_Overlay <EOL> from fec_alerts . models import WebK <EOL> from ftpdata . models import Committee <EOL> from shared_utils . cycle_utils import cycle_calendar , cycle_fake <EOL> this_site = Site . objects . all ( ) [ <NUM_LIT:0> ] <EOL> try : <EOL> ACTIVE_CYCLES = settings . ACTIVE_CYCLES <EOL> except : <EOL> print "<STR_LIT>" <EOL> ACTIVE_CYCLES = [ '<STR_LIT>' ] <EOL> PROJECT_ROOT = settings . PROJECT_ROOT <EOL> class Command ( BaseCommand ) : <EOL> help = "<STR_LIT>" <EOL> requires_model_validation = False <EOL> def handle ( self , * args , ** options ) : <EOL> for cycle in ACTIVE_CYCLES : <EOL> cycle_details = cycle_calendar [ int ( cycle ) ] <EOL> CYCLE_START = cycle_details [ '<STR_LIT:start>' ] <EOL> CYCLE_END = cycle_details [ '<STR_LIT:end>' ] <EOL> update_time = datetime . now ( ) <EOL> print "<STR_LIT>" <EOL> summary_obj = { } <EOL> all_independent_expenditures = SkedE . objects . filter ( superceded_by_amendment = False , effective_date__gte = CYCLE_START , effective_date__lte = CYCLE_END ) <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> print "<STR_LIT>" <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( support_oppose_checked = '<STR_LIT:S>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( support_oppose_checked = '<STR_LIT:O>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> print "<STR_LIT>" <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( support_oppose_checked = '<STR_LIT:S>' , candidate_party_checked = '<STR_LIT:D>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( support_oppose_checked = '<STR_LIT:S>' , candidate_party_checked = '<STR_LIT:R>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( support_oppose_checked = '<STR_LIT:O>' , candidate_party_checked = '<STR_LIT:D>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( support_oppose_checked = '<STR_LIT:O>' , candidate_party_checked = '<STR_LIT:R>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> print "<STR_LIT>" <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( candidate_office_checked = '<STR_LIT:S>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_independent_expenditures . filter ( candidate_office_checked = '<STR_LIT:H>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> all_outside_spenders = Committee_Overlay . nulls_last_objects . filter ( total_indy_expenditures__gt = <NUM_LIT:0> , cycle = str ( cycle ) ) <EOL> print "<STR_LIT>" <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( ctype__in = ( '<STR_LIT:X>' , '<STR_LIT:Y>' , '<STR_LIT>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( ctype__in = ( '<STR_LIT:O>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( ctype__in = ( '<STR_LIT:I>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( ctype__in = ( '<STR_LIT:N>' , '<STR_LIT>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( ctype__in = ( '<STR_LIT:H>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( ctype__in = ( '<STR_LIT:S>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> print "<STR_LIT>" <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( political_orientation = '<STR_LIT:D>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . filter ( political_orientation = '<STR_LIT:R>' ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> summary_obj [ '<STR_LIT>' ] = all_outside_spenders . exclude ( political_orientation__in = ( '<STR_LIT:R>' , '<STR_LIT:D>' ) ) . aggregate ( total_expenditures = Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> other_year = None <EOL> if cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> elif cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> cycle_list = [ cycle_fake ( cycle , "<STR_LIT>" % cycle ) , cycle_fake ( other_year , "<STR_LIT>" % other_year ) ] <EOL> page_title = "<STR_LIT>" % cycle <EOL> c = Context ( { "<STR_LIT>" : update_time , "<STR_LIT>" : summary_obj , "<STR_LIT>" : page_title , "<STR_LIT>" : cycle_list , "<STR_LIT>" : CYCLE_START , "<STR_LIT>" : CYCLE_END } ) <EOL> this_template = get_template ( '<STR_LIT>' ) <EOL> result = this_template . render ( c ) <EOL> thisurl = "<STR_LIT>" % cycle <EOL> thisflatpage , created = FlatPage . objects . get_or_create ( url = thisurl ) <EOL> thisflatpage . title = page_title <EOL> thisflatpage . content = result <EOL> thisflatpage . template_name = "<STR_LIT>" <EOL> if not thisflatpage . sites . all ( ) : <EOL> thisflatpage . sites . add ( this_site ) <EOL> thisflatpage . save ( ) <EOL> print "<STR_LIT>" <EOL> all_webk = WebK . objects . filter ( cycle = cycle ) . exclude ( com_des = '<STR_LIT>' ) <EOL> summary_types = [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' , '<STR_LIT>' : summary_obj [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' , '<STR_LIT>' : summary_obj [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:H>' , '<STR_LIT>' : summary_obj [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:S>' , '<STR_LIT>' : summary_obj [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' , '<STR_LIT>' : summary_obj [ '<STR_LIT>' ] } <EOL> ] <EOL> for s in summary_types : <EOL> code_list = [ i for i in s [ '<STR_LIT:code>' ] ] <EOL> sums = all_webk . filter ( com_typ__in = code_list ) . aggregate ( tot_rec = Sum ( '<STR_LIT>' ) , tot_dis = Sum ( '<STR_LIT>' ) , par_com_con = Sum ( '<STR_LIT>' ) , oth_com_con = Sum ( '<STR_LIT>' ) , ind_ite_con = Sum ( '<STR_LIT>' ) , ind_uni_con = Sum ( '<STR_LIT>' ) , fed_can_com_con = Sum ( '<STR_LIT>' ) , tot_ope_exp = Sum ( '<STR_LIT>' ) , ope_exp = Sum ( '<STR_LIT>' ) ) <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> s [ '<STR_LIT>' ] = ( sums [ '<STR_LIT>' ] or <NUM_LIT:0> ) + ( sums [ '<STR_LIT>' ] or <NUM_LIT:0> ) <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> if s [ '<STR_LIT:code>' ] in [ '<STR_LIT:H>' , '<STR_LIT:S>' ] : <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> else : <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> all_noncommittees = Committee_Overlay . objects . filter ( ctype__in = [ '<STR_LIT:I>' ] , cycle = cycle ) . exclude ( designation = '<STR_LIT>' ) <EOL> sums = all_noncommittees . aggregate ( tot_ie = Sum ( '<STR_LIT>' ) ) <EOL> dark_money_total_ies = sums [ '<STR_LIT>' ] <EOL> summary_types . append ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:I>' , '<STR_LIT>' : sums [ '<STR_LIT>' ] , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> print "<STR_LIT>" % summary_obj <EOL> print "<STR_LIT>" % summary_types <EOL> other_year = None <EOL> if cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> elif cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> cycle_list = [ cycle_fake ( cycle , "<STR_LIT>" % cycle ) , cycle_fake ( other_year , "<STR_LIT>" % other_year ) ] <EOL> page_title = "<STR_LIT>" % cycle <EOL> c = Context ( { "<STR_LIT>" : update_time , "<STR_LIT>" : summary_obj , "<STR_LIT>" : summary_types , "<STR_LIT>" : page_title , "<STR_LIT>" : cycle_list , "<STR_LIT>" : CYCLE_START , "<STR_LIT>" : CYCLE_END } ) <EOL> this_template = get_template ( '<STR_LIT>' ) <EOL> result = this_template . render ( c ) <EOL> thisurl = "<STR_LIT>" % cycle <EOL> thisflatpage , created = FlatPage . objects . get_or_create ( url = thisurl ) <EOL> thisflatpage . title = page_title <EOL> thisflatpage . content = result <EOL> thisflatpage . template_name = "<STR_LIT>" <EOL> if not thisflatpage . sites . all ( ) : <EOL> thisflatpage . sites . add ( this_site ) <EOL> thisflatpage . save ( ) <EOL> print "<STR_LIT>" <EOL> sp_summary_types = [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' } <EOL> ] <EOL> all_superpacs = Committee_Overlay . objects . filter ( cycle = cycle , ctype__in = [ '<STR_LIT>' , '<STR_LIT:O>' , '<STR_LIT>' , '<STR_LIT>' ] ) . exclude ( designation = '<STR_LIT>' ) <EOL> for s in sp_summary_types : <EOL> code_list = [ i for i in s [ '<STR_LIT:code>' ] ] <EOL> sums = all_superpacs . filter ( ctype__in = code_list ) . aggregate ( tot_ie = Sum ( '<STR_LIT>' ) , tot_rec = Sum ( '<STR_LIT>' ) , coh = Sum ( '<STR_LIT>' ) ) <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> s [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> top_superpacs = all_superpacs . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:20> ] <EOL> page_title = "<STR_LIT>" % ( cycle ) <EOL> other_year = None <EOL> if cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> elif cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> cycle_list = [ cycle_fake ( cycle , "<STR_LIT>" % cycle ) , cycle_fake ( other_year , "<STR_LIT>" % other_year ) ] <EOL> c = Context ( { "<STR_LIT>" : update_time , "<STR_LIT>" : sp_summary_types , "<STR_LIT>" : top_superpacs , "<STR_LIT>" : page_title , "<STR_LIT>" : cycle_list , "<STR_LIT>" : CYCLE_START , "<STR_LIT>" : CYCLE_END } ) <EOL> this_template = get_template ( '<STR_LIT>' ) <EOL> result = this_template . render ( c ) <EOL> thisurl = "<STR_LIT>" % cycle <EOL> thisflatpage , created = FlatPage . objects . get_or_create ( url = thisurl ) <EOL> thisflatpage . title = page_title <EOL> thisflatpage . content = result <EOL> thisflatpage . template_name = "<STR_LIT>" <EOL> if not thisflatpage . sites . all ( ) : <EOL> thisflatpage . sites . add ( this_site ) <EOL> thisflatpage . save ( ) <EOL> print "<STR_LIT>" <EOL> top_noncommittees = all_noncommittees . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] <EOL> page_title = "<STR_LIT>" % ( cycle ) <EOL> other_year = None <EOL> if cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> elif cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> cycle_list = [ cycle_fake ( cycle , "<STR_LIT>" % cycle ) , cycle_fake ( other_year , "<STR_LIT>" % other_year ) ] <EOL> c = Context ( { "<STR_LIT>" : update_time , "<STR_LIT>" : dark_money_total_ies , "<STR_LIT>" : top_noncommittees , "<STR_LIT>" : page_title , "<STR_LIT>" : cycle_list , "<STR_LIT>" : CYCLE_START , "<STR_LIT>" : CYCLE_END } ) <EOL> this_template = get_template ( '<STR_LIT>' ) <EOL> result = this_template . render ( c ) <EOL> thisurl = "<STR_LIT>" % cycle <EOL> thisflatpage , created = FlatPage . objects . get_or_create ( url = thisurl ) <EOL> thisflatpage . title = page_title <EOL> thisflatpage . content = result <EOL> thisflatpage . template_name = "<STR_LIT>" <EOL> if not thisflatpage . sites . all ( ) : <EOL> thisflatpage . sites . add ( this_site ) <EOL> thisflatpage . save ( ) <EOL> all_webk = WebK . objects . filter ( cycle = cycle ) . exclude ( com_des = '<STR_LIT>' ) <EOL> connected_org_types = [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:C>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:L>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:M>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT:T>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' } <EOL> ] <EOL> for j in connected_org_types : <EOL> committees = Committee . objects . filter ( cmte_tp__in = [ '<STR_LIT:N>' , '<STR_LIT>' ] , cycle = str ( cycle ) , org_tp = j [ '<STR_LIT:code>' ] ) <EOL> committee_id_list = [ i . cmte_id for i in committees ] <EOL> sums = all_webk . filter ( com_id__in = committee_id_list ) . aggregate ( tot_rec = Sum ( '<STR_LIT>' ) , tot_dis = Sum ( '<STR_LIT>' ) , par_com_con = Sum ( '<STR_LIT>' ) , oth_com_con = Sum ( '<STR_LIT>' ) , ind_ite_con = Sum ( '<STR_LIT>' ) , ind_uni_con = Sum ( '<STR_LIT>' ) , fed_can_com_con = Sum ( '<STR_LIT>' ) , tot_ope_exp = Sum ( '<STR_LIT>' ) , ope_exp = Sum ( '<STR_LIT>' ) ) <EOL> j [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> j [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> j [ '<STR_LIT>' ] = ( sums [ '<STR_LIT>' ] or <NUM_LIT:0> ) + ( sums [ '<STR_LIT>' ] or <NUM_LIT:0> ) <EOL> j [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> j [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> j [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> j [ '<STR_LIT>' ] = sums [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> print "<STR_LIT>" % ( connected_org_types ) <EOL> page_title = "<STR_LIT>" % cycle <EOL> other_year = None <EOL> if cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> elif cycle == '<STR_LIT>' : <EOL> other_year = '<STR_LIT>' <EOL> cycle_list = [ cycle_fake ( cycle , "<STR_LIT>" % cycle ) , cycle_fake ( other_year , "<STR_LIT>" % other_year ) ] <EOL> c = Context ( { "<STR_LIT>" : update_time , "<STR_LIT>" : connected_org_types , "<STR_LIT>" : page_title , "<STR_LIT>" : cycle_list , "<STR_LIT>" : CYCLE_START , "<STR_LIT>" : CYCLE_END } ) <EOL> this_template = get_template ( '<STR_LIT>' ) <EOL> result = this_template . render ( c ) <EOL> thisurl = "<STR_LIT>" % cycle <EOL> thisflatpage , created = FlatPage . objects . get_or_create ( url = thisurl ) <EOL> thisflatpage . title = page_title <EOL> thisflatpage . content = result <EOL> thisflatpage . template_name = "<STR_LIT>" <EOL> if not thisflatpage . sites . all ( ) : <EOL> thisflatpage . sites . add ( this_site ) <EOL> thisflatpage . save ( ) </s>
