def test_find_member_surname_prefix(self): surname = 'Weyenberg van' forename = 'Steven' initials = 'S.P.R.A.' member = ParliamentMember.find(surname=surname, initials=initials) self.assertEqual(member.person.forename, forename) surname = 'van Weyenberg' member = ParliamentMember.find(surname=surname, initials=initials) self.assertEqual(member.person.forename, forename)
def test_find_member_non_ascii(self): surname = 'Koser Kaya' forename = 'Fatma' initials = 'F.' member = ParliamentMember.find(surname=surname, initials=initials) self.assertEqual(member.person.forename, forename) surname = 'Koşer Kaya' member = ParliamentMember.find(surname=surname, initials=initials) self.assertEqual(member.person.forename, forename)
def test_find_members(self): person = Person.find_by_fullname('Diederik Samsom') member = ParliamentMember.find('Samsom', initials='D.M.') self.assertEqual(member.person, person) member = ParliamentMember.find('Samsom', initials='D.M.', date=datetime.date(year=2004, month=6, day=1)) self.assertEqual(member.person, person) self.assertEqual(member.joined, datetime.date(year=2003, month=1, day=30)) member = ParliamentMember.find('Samsom', initials='D.M.', date=datetime.date(year=2016, month=6, day=1)) self.assertEqual(member.person, person) self.assertEqual(member.joined, datetime.date(year=2012, month=9, day=20))
def test_get_member_for_person_at_date(self): person = Person.find_by_fullname('Diederik Samsom') members_all = ParliamentMember.objects.filter(person=person) self.assertEqual(members_all.count(), 4) members = ParliamentMember.find_at_date(person, datetime.date(year=2016, month=6, day=1)) self.assertEqual(members[0].joined, datetime.date(year=2012, month=9, day=20)) self.assertEqual(members.count(), 1) self.assertEqual(members[0].person, person) members = ParliamentMember.find_at_date(person, datetime.date(year=2004, month=6, day=1)) self.assertEqual(members[0].joined, datetime.date(year=2003, month=1, day=30)) self.assertEqual(members.count(), 1) self.assertEqual(members[0].person, person)
def set_derived(self): initials, surname, surname_prefix = parse_name_surname_initials( self.person_name) self.parliament_member = ParliamentMember.find(surname=surname, initials=initials, date=self.voting.date) self.save()
def create_votes_individual(self, voting, stemmingen): logger.info('BEGIN') for stemming in stemmingen: persoon = stemming.persoon if persoon: initials = persoon.initialen surname = persoon.achternaam forname = persoon.roepnaam else: logger.error('Persoon not found for stemming: ' + stemming.id) surname_initials = stemming.json['AnnotatieActorNaam'] forname = '' initials, surname, surname_prefix = parse_name_surname_initials(surname_initials) parliament_member = ParliamentMember.find(surname=surname, initials=initials) if not parliament_member: logger.error('parliament member not found for vote: ' + str(stemming.id)) logger.error('creating vote with empty parliament member') person_name = ' '.join([forname, surname, initials]).strip() VoteIndividual.objects.create( voting=voting, person_name=person_name, parliament_member=parliament_member, number_of_seats=1, decision=self.get_decision(stemming.soort), details='', is_mistake=stemming.vergissing if stemming.vergissing is not None else False ) logger.info('END')
def create_votes_individual(voting, votes): logger.info('BEGIN') for vote in votes: initials, surname, surname_prefix = parse_name_surname_initials( vote.parliament_member) parliament_member = ParliamentMember.find(surname=surname, initials=initials) if not parliament_member: logger.error('parliament member not found for vote: ' + str(vote)) logger.error('creating vote with empty parliament member') if voting.kamerstuk: logger.error('on kamerstuk: ' + str(voting.kamerstuk) + ', in dossier: ' + str(voting.kamerstuk.document.dossier) + ', for name: ' + surname + ' ' + initials) else: logger.error('voting.kamerstuk does not exist') VoteIndividual.objects.create(voting=voting, person_name=vote.parliament_member, parliament_member=parliament_member, number_of_seats=vote.number_of_seats, decision=get_decision(vote.decision), details=vote.details, is_mistake=vote.is_mistake) logger.info('END')
def save(self, *args, **kwargs): party_members = PartyMember.get_at_date(self.person, self.date) self.party = party_members[0].party if party_members else None parliament_members = ParliamentMember.find_at_date( self.person, self.date) self.parliament_member = parliament_members[ 0] if parliament_members else None super().save(*args, **kwargs)
def get_active_persons(date): pms = ParliamentMember.active_at_date(date) gms = GovernmentMember.active_at_date(date) person_ids = [] for pm in pms: person_ids.append(pm.person.id) for gm in gms: person_ids.append(gm.person.id) return Person.objects.filter(id__in=person_ids)
def test_delete_parliament_member(self): member = ParliamentMember.find('Dijkstra', initials='P.A.') vote = VoteIndividual.objects.create(voting=self.voting, person_name='Dijkstra, P.A.', number_of_seats=1) vote.set_derived() self.assertEqual(member, vote.parliament_member) ParliamentMember.objects.all().delete() vote = VoteIndividual.objects.filter(id=vote.id) self.assertEqual(vote, vote)
def test_delete_parliament_member(self): member = ParliamentMember.find('Dijkstra', initials='P.A.') vote = VoteIndividual.objects.create( voting=self.voting, person_name='Dijkstra, P.A.', number_of_seats=1 ) vote.set_derived() self.assertEqual(member, vote.parliament_member) ParliamentMember.objects.all().delete() vote = VoteIndividual.objects.filter(id=vote.id) self.assertEqual(vote, vote)
def create_votes_individual(self, voting, stemmingen): logger.info('BEGIN') for stemming in stemmingen: persoon = stemming.persoon parliament_member = None persons = Person.objects.filter(tk_id=persoon.id) if persons: person = persons[0] members = ParliamentMember.objects.filter(person=person).order_by('-joined') parliament_member = members[0] if members.exists() else None person_name = ' '.join([person.forename, person.surname, person.initials]).strip() # TODO BR: this is a fallback, remove or extract function and log if parliament_member is None: if persoon: initials = persoon.initialen surname = persoon.achternaam forname = persoon.roepnaam else: logger.error('Persoon not found for stemming: {}'.format(stemming.id)) surname_initials = stemming.json['AnnotatieActorNaam'] forname = '' initials, surname, surname_prefix = parse_name_surname_initials(surname_initials) parliament_member = ParliamentMember.find(surname=surname, initials=initials) if not parliament_member: logger.error('parliament member not found for vote: {}'.format(stemming.id)) logger.error('creating vote with empty parliament member') person_name = ' '.join([forname, surname, initials]).strip() VoteIndividual.objects.create( voting=voting, person_name=person_name, person_tk_id=persoon.id, parliament_member=parliament_member, number_of_seats=1, decision=self.get_decision(stemming.soort), details='', is_mistake=stemming.vergissing if stemming.vergissing is not None else False ) logger.info('END')
def set_derived(self): initials, surname, surname_prefix = parse_name_surname_initials(self.person_name) self.parliament_member = ParliamentMember.find(surname=surname, initials=initials, date=self.voting.date) self.save()
def test_find_member(self): surname = 'Zijlstra' forename = 'Halbe' initials = 'H.' member = ParliamentMember.find(surname=surname, initials=initials) self.assertEqual(member.person.forename, forename)
def save(self, *args, **kwargs): party_members = PartyMember.get_at_date(self.person, self.date) self.party = party_members[0].party if party_members else None parliament_members = ParliamentMember.find_at_date(self.person, self.date) self.parliament_member = parliament_members[0] if parliament_members else None super().save(*args, **kwargs)