def add_mp(obj): party, occupation, name, dob, votes, image, marital_status, religion, hometown, last_employment, constituency, region, education, gender, summary, term_start, term_end = [ obj.get(k, "") for k in MP_FIELDS ] try: last, first, middle, title = split_name(name) except: print ">>> Error splitting name:", name, "=> ", title, first, middle, last return person = add_person( name=legal_name(last, first, middle), gender=gender, title=title, dob=dob, image=image, summary=summary ) print constituency, slugify(constituency), constituency_kind, region, slugify(region), region_kind region, _ = Place.objects.get_or_create(slug=slugify(region), defaults={"name": region, "kind": region_kind}) constituency, _ = Place.objects.get_or_create( slug=slugify(constituency), defaults={"name": constituency, "kind": constituency_kind} ) party, _ = Organisation.objects.get_or_create(slug=slugify(party), defaults={"name": party, "kind": party_kind}) # add to party party_position, _ = Position.objects.get_or_create(person=person, title=member_job_title, organisation=party) # add to parliament (as mp) if term_start: term_start = datetime.strptime(term_start, "%B %d %Y").strftime("%Y-%m-%d") if term_end: term_end = datetime.strptime(term_end, "%B %d %Y").strftime("%Y-%m-%d") mp_position, _ = Position.objects.get_or_create( person=person, title=mp_job_title, organisation=parliament, place=constituency, start_date=term_start, end_date=term_end, category=str("political"), ) mp, _ = MP.objects.get_or_create(person=person, party_position=party_position, parliament_position=mp_position) mp.first_name = first mp.middle_name = middle mp.last_name = last mp.occupation = occupation mp.marital_status = marital_status mp.hometown = hometown mp.education = education mp.religion = religion mp.last_employment = last_employment[:150] mp.votes_obtained = votes[:150] mp.save()
def add_person_object(obj): name, dob, gender, image, summary = [obj.get(k, "") for k in PERSON_FIELDS] try: last, first, middle, title = split_name(name) except: print ">>> Error splitting name:", name return add_person(name=legal_name(last, first, middle), gender=gender, title=title, dob=dob, image=image, summary=summary)
def add_person_object(obj): name, dob, gender, image, summary = \ [obj.get(k, '') for k in PERSON_FIELDS] try: last, first, middle, title = split_name(name) except: print ">>> Error splitting name:", name return add_person(name=legal_name(last, first, middle), gender=gender, title=title, dob=dob, image=image, summary=summary)
def add_mp(obj): party, occupation, name, dob, votes, image, \ marital_status, religion, hometown, last_employment, constituency, \ region, education, gender, summary, term_start, term_end = [obj.get(k, '') for k in MP_FIELDS] try: last, first, middle, title = split_name(name) except: print ">>> Error splitting name:", name, "=> ", title, first, middle, last return person = add_person(name=legal_name(last, first, middle), gender=gender, title=title, dob=dob, image=image, summary=summary) print constituency, slugify( constituency), constituency_kind, region, slugify(region), region_kind region, _ = Place.objects.get_or_create(slug=slugify(region), defaults={ 'name': region, 'kind': region_kind }) constituency, _ = Place.objects.get_or_create(slug=slugify(constituency), defaults={ 'name': constituency, 'kind': constituency_kind }) party, _ = Organisation.objects.get_or_create(slug=slugify(party), defaults={ 'name': party, 'kind': party_kind }) # add to party party_position, _ = Position.objects.get_or_create(person=person, title=member_job_title, organisation=party) # add to parliament (as mp) if (term_start): term_start = datetime.strptime(term_start, '%B %d %Y').strftime("%Y-%m-%d") if (term_end): term_end = datetime.strptime(term_end, '%B %d %Y').strftime("%Y-%m-%d") mp_position, _ = Position.objects.get_or_create(person=person, title=mp_job_title, organisation=parliament, place=constituency, start_date=term_start, end_date=term_end, category=str('political')) mp, _ = MP.objects.get_or_create(person=person, party_position=party_position, parliament_position=mp_position) mp.first_name = first mp.middle_name = middle mp.last_name = last mp.occupation = occupation mp.marital_status = marital_status mp.hometown = hometown mp.education = education mp.religion = religion mp.last_employment = last_employment[:150] mp.votes_obtained = votes[:150] mp.save()
def test_split_name(self): for name, split, legal in self.NAMES: self.assertEqual(split, split_name(name)) last_name, first_name, middle_name, title = split self.assertEqual(legal, legal_name(last_name, first_name, middle_name))