Example #1
0
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()
Example #2
0
def get_senate_incumbents():
    # Get the incumbents
    for member in senate_crosswalk:
        bio = member['bioguide']
        fec_id = member['fec_id']
        
        if not fec_id:
            # ignore 
            continue
        #print "handling %s %s" % (bio, fec_id)
        # term class isn't kept in the fec records...
        
        
        thisterm = Term.objects.get(start__lte=cycle_end, end__gte=cycle_start, term_type='sen', legislator__bioguide=bio)
        
        thiscandidate = Candidate.objects.get(cand_id=fec_id, cycle=cycle)
        office = thiscandidate.cand_office
        term_class = thisterm.term_class
        state = thiscandidate.cand_office_st

        #print "processing %s: %s %s %s" % (thiscandidate.cand_name, office, state, term_class)
        election_year = get_election_year_from_term_class(term_class)
        senate_cycle = str(election_year)
        this_district = District.objects.get(cycle=senate_cycle,state=state, office='S', term_class=term_class)


        this_overlay, created = Candidate_Overlay.objects.get_or_create(fec_id=fec_id, cycle=senate_cycle, district=this_district)
        this_overlay.name = thiscandidate.cand_name
        this_overlay.slug = slugify(thiscandidate.cand_name)
        this_overlay.candidate = thiscandidate
        this_overlay.office='S'
        this_overlay.state = thiscandidate.cand_office_st
        this_overlay.pty = thiscandidate.cand_pty_affiliation
        this_overlay.party = get_party_from_pty(thiscandidate.cand_pty_affiliation)        
        this_overlay.pcc = thiscandidate.cand_pcc
        this_overlay.cand_ici = 'I'
        this_overlay.election_year = election_year
        this_overlay.term_class=term_class
        this_overlay.save()

        try:
            senate_casualty_hash[fec_id]
            this_overlay.not_seeking_reelection = True
            this_overlay.save()
            this_district.open_seat = True
            this_district.save()

        except KeyError:
            pass
Example #3
0
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()