def create_senate_districts(): # pull this from us_congress repo data--which is in the legislators app senate_districts = Term.objects.filter(start__lte=cycle_end, end__gte=cycle_start, term_type='sen').order_by( 'state', 'term_class') unique_sd = senate_districts.values('state', 'term_class').distinct() for s in unique_sd: term_class = s['term_class'] election_year = get_election_year_from_term_class(term_class) election_cycle = str(election_year) print s thisdistrict, created = District.objects.get_or_create( cycle=election_cycle, state=s['state'], office='S', term_class=s['term_class'], election_year=election_year) incumbent_term = Term.objects.filter( start__lte=cycle_end, end__gte=cycle_start, term_type='sen', term_class=s['term_class'], state=s['state']).order_by('-start')[0] party = get_party_from_term_party(incumbent_term.party) name = incumbent_term.legislator.official_full thisdistrict.incumbent_party = party thisdistrict.incumbent_legislator = incumbent_term.legislator thisdistrict.incumbent_name = name thisdistrict.save()
def create_house_districts(): # pull this from us_congress repo data--which is in the legislators app house_districts = Term.objects.filter(start__lte=cycle_end, end__gte=cycle_start, term_type='rep').order_by( 'state', 'district') unique_hd = house_districts.values('state', 'district').distinct() for d in unique_hd: print d district_fixed = d['district'].zfill(2) thisdistrict, created = District.objects.get_or_create( cycle=cycle, state=d['state'], office='H', office_district=district_fixed, election_year='2014') incumbent_term = Term.objects.filter( start__lte=cycle_end, end__gte=cycle_start, term_type='rep', district=d['district'], state=d['state']).order_by('-start')[0] party = get_party_from_term_party(incumbent_term.party) name = incumbent_term.legislator.official_full thisdistrict.incumbent_party = party thisdistrict.incumbent_legislator = incumbent_term.legislator thisdistrict.incumbent_name = name thisdistrict.save()
def create_house_districts(): # pull this from us_congress repo data--which is in the legislators app house_districts = Term.objects.filter(start__lte=cycle_end, end__gte=cycle_start, term_type='rep').order_by('state', 'district') unique_hd = house_districts.values('state', 'district').distinct() for d in unique_hd: print d district_fixed = d['district'].zfill(2) thisdistrict, created = District.objects.get_or_create(cycle=cycle,state=d['state'], office='H', office_district=district_fixed, election_year=cycle) incumbent_term = Term.objects.filter(start__lte=cycle_end, end__gte=cycle_start, term_type='rep', district=d['district'], state=d['state']).order_by('-start')[0] party = get_party_from_term_party(incumbent_term.party) name = incumbent_term.legislator.official_full thisdistrict.incumbent_party = party thisdistrict.incumbent_legislator = incumbent_term.legislator thisdistrict.incumbent_name = name thisdistrict.save()
def create_senate_districts(): # pull this from us_congress repo data--which is in the legislators app senate_districts = Term.objects.filter(start__lte=cycle_end, end__gte=cycle_start, term_type='sen').order_by('state', 'term_class') unique_sd = senate_districts.values('state', 'term_class').distinct() for s in unique_sd: term_class = s['term_class'] election_year = get_election_year_from_term_class(term_class) election_cycle = str(election_year) print s thisdistrict, created = District.objects.get_or_create(cycle=election_cycle,state=s['state'], office='S', term_class=s['term_class'], election_year = election_year) incumbent_term = Term.objects.filter(start__lte=cycle_end, end__gte=cycle_start, term_type='sen', term_class = s['term_class'], state=s['state']).order_by('-start')[0] party = get_party_from_term_party(incumbent_term.party) name = incumbent_term.legislator.official_full thisdistrict.incumbent_party = party thisdistrict.incumbent_legislator = incumbent_term.legislator thisdistrict.incumbent_name = name thisdistrict.save()