<s> """<STR_LIT>""" <EOL> from datetime import date <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . db . models import Sum <EOL> from formdata . models import SkedE <EOL> from summary_data . models import Pac_Candidate , Candidate_Overlay <EOL> from shared_utils . cycle_utils import cycle_calendar <EOL> from django . conf import settings <EOL> try : <EOL> ACTIVE_CYCLES = settings . ACTIVE_CYCLES <EOL> except : <EOL> print "<STR_LIT>" <EOL> ACTIVE_CYCLES = [ '<STR_LIT>' ] <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> this_cycle_calendar = cycle_calendar [ int ( cycle ) ] <EOL> this_cycle_start = this_cycle_calendar [ '<STR_LIT:start>' ] <EOL> this_cycle_end = this_cycle_calendar [ '<STR_LIT:end>' ] <EOL> candidate_ids = SkedE . objects . filter ( superceded_by_amendment = False , expenditure_date_formatted__gte = this_cycle_start , expenditure_date_formatted__lte = this_cycle_end ) . exclude ( candidate_id_checked__isnull = True ) . values ( '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) . distinct ( ) <EOL> for candidate_id in candidate_ids : <EOL> print "<STR_LIT>" % ( candidate_id [ '<STR_LIT>' ] ) <EOL> try : <EOL> candidate = Candidate_Overlay . objects . get ( fec_id = candidate_id [ '<STR_LIT>' ] , cycle = cycle ) <EOL> total_supporting = SkedE . objects . filter ( expenditure_date_formatted__gte = this_cycle_start , expenditure_date_formatted__lte = this_cycle_end , superceded_by_amendment = False , candidate_checked = candidate , support_oppose_checked__iexact = '<STR_LIT:S>' ) . aggregate ( total = Sum ( '<STR_LIT>' ) ) <EOL> total_opposing = SkedE . objects . filter ( expenditure_date_formatted__gte = this_cycle_start , expenditure_date_formatted__lte = this_cycle_end , superceded_by_amendment = False , candidate_checked = candidate , support_oppose_checked__iexact = '<STR_LIT:O>' ) . aggregate ( total = Sum ( '<STR_LIT>' ) ) <EOL> total = SkedE . objects . filter ( expenditure_date_formatted__gte = this_cycle_start , expenditure_date_formatted__lte = this_cycle_end , superceded_by_amendment = False , candidate_checked = candidate ) . aggregate ( total = Sum ( '<STR_LIT>' ) ) <EOL> candidate . total_expenditures = total [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> candidate . expenditures_supporting = total_supporting [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> candidate . expenditures_opposing = total_opposing [ '<STR_LIT>' ] or <NUM_LIT:0> <EOL> candidate . save ( ) <EOL> except Candidate_Overlay . DoesNotExist : <EOL> print "<STR_LIT>" % ( candidate_id [ '<STR_LIT>' ] ) <EOL> continue <EOL> except Candidate_Overlay . MultipleObjectsReturned : <EOL> print "<STR_LIT>" % ( candidate_id [ '<STR_LIT>' ] ) <EOL> continue </s>
