def get_senate_challengers(): # then get the candidates who are declared. While we set the incumbents' election year as 2014--overriding whatever they have in their FEC filings, we don't do that here. allSenateCandidates = Candidate.objects.filter(cycle=cycle, cand_office='S', cand_election_year__gte=2013) for thiscandidate in allSenateCandidates: fec_id = thiscandidate.cand_id try: senate_exclusion_hash[fec_id] continue except KeyError: pass #print "handling %s" % (thiscandidate.cand_name) # do we already have this candidate entered ? try: entered_candidate = Candidate_Overlay.objects.get(election_year__gte=2013, fec_id=fec_id) #print "Found candidate %s status %s" % (entered_candidate.name, entered_candidate.cand_ici) except Candidate_Overlay.DoesNotExist: # don't enter if they say they're an incumbent. Problaby an error. if thiscandidate.cand_ici == 'I': print "!! Not-yet-entered Senate candidate %s %s %s claims incumbency. Perhaps they've retired?" % (thiscandidate.cand_name, thiscandidate.cand_election_year, thiscandidate.cand_office_st) else: # It's a new candidate. Enter it. state = thiscandidate.cand_office_st term_class = get_term_class_from_election_year(thiscandidate.cand_election_year) if thiscandidate.cand_election_year < 2013: print "!! Disregarding old candidate %s %s %s" % (thiscandidate.cand_name, thiscandidate.cand_election_year, state) election_year = str(thiscandidate.cand_election_year) try: this_district = District.objects.get(election_year=election_year, state=state, office='S') # Only make it an open seat if we've already marked the district as open. cand_ici = 'C' if this_district.open_seat: cand_ici='O' Candidate_Overlay.objects.create( district=this_district, cycle=cycle, fec_id=fec_id, name=thiscandidate.cand_name, slug = slugify(thiscandidate.cand_name), pty=thiscandidate.cand_pty_affiliation, party = get_party_from_pty(thiscandidate.cand_pty_affiliation), #pcc=thiscandidate.cand_pcc, term_class=term_class, election_year=thiscandidate.cand_election_year, state=thiscandidate.cand_office_st, office='S', cand_ici=cand_ici, candidate_status='D' ) except District.DoesNotExist: print "!! Invalid senate district for %s %s %s %s" % (thiscandidate.cand_name, term_class, thiscandidate.cand_election_year, state) continue
def make_candidate_overlay_from_masterfile(candidate_id, cycle_to_copy_from=2014, election_year=2014, cycle_to_copy_to=2014, verify_does_not_exist=True, display_candidate=False): ## Returns overlay if created, None if not. if verify_does_not_exist: try: # If there's already a candidate overlay, don't do this. entered_candidate = Candidate_Overlay.objects.get(cycle=cycle_to_copy_to, fec_id=candidate_id) #print "Found candidate %s status %s" % (entered_candidate.name, entered_candidate.cand_ici) return None except Candidate_Overlay.DoesNotExist: pass thiscandidate = None try: thiscandidate = Candidate.objects.get(cycle=cycle_to_copy_from, cand_id=candidate_id, cand_election_year=election_year) except Candidate.DoesNotExist: print "Couldn't find candidate in masterfile id=%s election_year=%s cycle=%s" % (candidate_id, election_year, cycle_to_copy_from) return None state = thiscandidate.cand_office_st term_class = None if thiscandidate.cand_office == 'S': term_class = get_term_class_from_election_year(thiscandidate.cand_election_year) this_district = None try: if thiscandidate.cand_office == 'S': this_district = District.objects.get(election_year=election_year, state=state, office=thiscandidate.cand_office, term_class=term_class) elif thiscandidate.cand_office == 'H': this_district = District.objects.get(election_year=election_year, state=state, office=thiscandidate.cand_office, office_district=thiscandidate.cand_office_district) elif thiscandidate.cand_office == 'P': # there's no district, so pass # do we need a presidential placeholder ? pass except District.DoesNotExist: print "!! Invalid district for %s %s %s %s" % (thiscandidate.cand_name, term_class, thiscandidate.cand_election_year, state) # If we can't find a district, override the display setting--just don't display it. display_candidate = False co = Candidate_Overlay.objects.create( district=this_district, office_district=thiscandidate.cand_office_district, cycle=cycle_to_copy_to, fec_id=candidate_id, name=thiscandidate.cand_name, slug = slugify(thiscandidate.cand_name), pty=thiscandidate.cand_pty_affiliation, party = get_party_from_pty(thiscandidate.cand_pty_affiliation), pcc=thiscandidate.cand_pcc, term_class=term_class, election_year=thiscandidate.cand_election_year, curated_election_year=thiscandidate.cand_election_year, state=thiscandidate.cand_office_st, office=thiscandidate.cand_office, cand_ici=thiscandidate.cand_ici, candidate_status='D', display = display_candidate, ) return co
def make_candidate_overlay_from_masterfile( candidate_id, cycle_to_copy_from=2016, election_year=2016, cycle_to_copy_to=2016, verify_does_not_exist=True, display_candidate=False, ): if candidate_id == "P20003851": return None ## Returns overlay if created, None if not. if verify_does_not_exist: try: # If there's already a candidate overlay, don't do this. entered_candidate = Candidate_Overlay.objects.get(cycle=cycle_to_copy_to, fec_id=candidate_id) # print "Found candidate %s status %s" % (entered_candidate.name, entered_candidate.cand_ici) return None except Candidate_Overlay.DoesNotExist: pass thiscandidate = None try: thiscandidate = Candidate.objects.get( cycle=cycle_to_copy_from, cand_id=candidate_id, cand_election_year=election_year ) except Candidate.DoesNotExist: print "Couldn't find candidate in masterfile id=%s election_year=%s cycle=%s" % ( candidate_id, election_year, cycle_to_copy_from, ) return None state = thiscandidate.cand_office_st term_class = None if thiscandidate.cand_office == "S": term_class = get_term_class_from_election_year(thiscandidate.cand_election_year) this_district = None try: if thiscandidate.cand_office == "S": this_district = District.objects.get( election_year=election_year, state=state, office=thiscandidate.cand_office, term_class=term_class ) elif thiscandidate.cand_office == "H": this_district = District.objects.get( election_year=election_year, state=state, office=thiscandidate.cand_office, office_district=thiscandidate.cand_office_district, ) elif thiscandidate.cand_office == "P": # there's a single presidential district per cycle, it needs to be created manually this_district = District.objects.get(election_year=election_year, office=thiscandidate.cand_office) except District.DoesNotExist: print "!! Invalid %s district for %s term_class=%s district=%s election_year=%s state=%s" % ( thiscandidate.cand_office, thiscandidate.cand_name, term_class, thiscandidate.cand_office_district, thiscandidate.cand_election_year, state, ) # If we can't find a district, override the display setting--just don't display it. display_candidate = False co = Candidate_Overlay.objects.create( district=this_district, office_district=thiscandidate.cand_office_district, cycle=cycle_to_copy_to, fec_id=candidate_id, name=thiscandidate.cand_name, slug=slugify(thiscandidate.cand_name), pty=thiscandidate.cand_pty_affiliation, party=get_party_from_pty(thiscandidate.cand_pty_affiliation), pcc=thiscandidate.cand_pcc, term_class=term_class, election_year=thiscandidate.cand_election_year, curated_election_year=thiscandidate.cand_election_year, state=thiscandidate.cand_office_st, office=thiscandidate.cand_office, cand_ici=thiscandidate.cand_ici, candidate_status="D", display=display_candidate, ) return co
def make_candidate_overlay_from_masterfile(candidate_id, cycle_to_copy_from=2014, election_year=2014, cycle_to_copy_to=2014, verify_does_not_exist=True, display_candidate=False): if candidate_id == 'P20003851': return None ## Returns overlay if created, None if not. if verify_does_not_exist: try: # If there's already a candidate overlay, don't do this. entered_candidate = Candidate_Overlay.objects.get(cycle=cycle_to_copy_to, fec_id=candidate_id) #print "Found candidate %s status %s" % (entered_candidate.name, entered_candidate.cand_ici) return None except Candidate_Overlay.DoesNotExist: pass thiscandidate = None try: thiscandidate = Candidate.objects.get(cycle=cycle_to_copy_from, cand_id=candidate_id, cand_election_year=election_year) except Candidate.DoesNotExist: print "Couldn't find candidate in masterfile id=%s election_year=%s cycle=%s" % (candidate_id, election_year, cycle_to_copy_from) return None state = thiscandidate.cand_office_st term_class = None if thiscandidate.cand_office == 'S': term_class = get_term_class_from_election_year(thiscandidate.cand_election_year) this_district = None try: if thiscandidate.cand_office == 'S': this_district = District.objects.get(election_year=election_year, state=state, office=thiscandidate.cand_office, term_class=term_class) elif thiscandidate.cand_office == 'H': this_district = District.objects.get(election_year=election_year, state=state, office=thiscandidate.cand_office, office_district=thiscandidate.cand_office_district) elif thiscandidate.cand_office == 'P': # there's no district, so pass # do we need a presidential placeholder ? pass except District.DoesNotExist: print "!! Invalid district for %s %s %s %s" % (thiscandidate.cand_name, term_class, thiscandidate.cand_election_year, state) # If we can't find a district, override the display setting--just don't display it. display_candidate = False co = Candidate_Overlay.objects.create( district=this_district, office_district=thiscandidate.cand_office_district, cycle=cycle_to_copy_to, fec_id=candidate_id, name=thiscandidate.cand_name, slug = slugify(thiscandidate.cand_name), pty=thiscandidate.cand_pty_affiliation, party = get_party_from_pty(thiscandidate.cand_pty_affiliation), pcc=thiscandidate.cand_pcc, term_class=term_class, election_year=thiscandidate.cand_election_year, curated_election_year=thiscandidate.cand_election_year, state=thiscandidate.cand_office_st, office=thiscandidate.cand_office, cand_ici=thiscandidate.cand_ici, candidate_status='D', display = display_candidate, ) return co