def setUp(self): lauren = User(username='******') lauren.save() lauren_token = Token(user=lauren) lauren_token.save() hagstjorn = Subject(name='Hagstjórn', number=1) hagstjorn.save() fjarreidur = Subject(name='Fjárreiður ríkisins', parent=hagstjorn, number=2) fjarreidur.save() parliament = Parliament(name='Parliament', start_date='2017-01-01', end_date='2017-01-01') parliament.save() promise1 = Promise(name='Promise 1', parliament=parliament) promise2 = Promise(name='Promise 2', parliament=parliament) promise1.save() promise2.save() promise1_hagstjorn = PromiseSubject(subject=hagstjorn, promise=promise1) promise2_fjarreidur = PromiseSubject(subject=fjarreidur, promise=promise2) promise1_hagstjorn.save() promise2_fjarreidur.save()
def get_context_data(self, at_date, **kwargs): context = super().get_context_data(**kwargs) tweedekamer = Parliament.get_or_create_tweede_kamer() members = tweedekamer.get_members_at_date(at_date) context['members'] = members context['date'] = at_date return context
def get_context_data(self, **kwargs): if not self.request.user.is_superuser: raise PermissionError("You need to be an admin to view this page.") context = super().get_context_data(**kwargs) start_date = datetime.date(year=2005, month=6, day=1) members_per_month = self.get_members_per_month(start_date) members = ParliamentMember.objects.all() members_overlap = [] for member in members: members_overlap += member.check_overlap() overlap_ids = [] for member in members_overlap: overlap_ids.append(member.id) parliament = Parliament.get_or_create_tweede_kamer() check_date = datetime.date.today() # check_date = datetime.date(year=2008, month=7, day=1) members_current = parliament.get_members_at_date(check_date) members_current_check = check.check_parliament_members_at_date( check_date) members_missing = check.get_members_missing(members_current, members_current_check) members_incorrect = check.get_members_incorrect( members_current, members_current_check) context['members'] = members context['members_current'] = sorted( members_current, key=lambda member: member.person.surname) context['members_current_missing'] = members_missing context['members_incorrect'] = sorted( members_incorrect, key=lambda member: member.person.surname) context['members_overlap'] = ParliamentMember.objects.filter( pk__in=overlap_ids).distinct() context['members_per_month'] = members_per_month return context
def test_submitter(self): date = datetime.date(day=30, month=1, year=2010) p1 = Person.objects.create(forename='Jeroen', surname='Dijsselbloem', initials='J.R.V.A.') parliament = Parliament.get_or_create_tweede_kamer() ParliamentMember.objects.create(person=p1, parliament=parliament, joined=datetime.date(2010, 1, 1), left=datetime.date(2010, 2, 1)) document = Document.objects.create(date_published=datetime.date.today()) submitter = SubmitterFactory.create_submitter(document, 'L. van Tongeren', date) self.assertEqual(submitter.person.initials, 'L.') submitter = SubmitterFactory.create_submitter(document, 'Tongeren C.S.', date) self.assertEqual(submitter.person.initials, '') submitter = SubmitterFactory.create_submitter(document, 'DIJSSELBLOEM', date) self.assertEqual(submitter.person, p1) p5 = Person.objects.create(forename='', surname='Dijsselbloem', initials='') submitter = SubmitterFactory.create_submitter(document, 'DIJSSELBLOEM', date) self.assertEqual(submitter.person, p1) p2 = Person.objects.create(forename='Pieter', surname='Dijsselbloem', initials='P.') ParliamentMember.objects.create(person=p2, parliament=parliament, joined=datetime.date(2010, 1, 1), left=datetime.date(2010, 2, 1)) submitter = SubmitterFactory.create_submitter(document, 'DIJSSELBLOEM', date) self.assertNotEqual(submitter.person, p1) self.assertNotEqual(submitter.person, p2) p3 = Person.objects.create(forename='Jan Jacob', surname_prefix='van', surname='Dijk', initials='J.J.') p4 = Person.objects.create(forename='Jasper', surname_prefix='van', surname='Dijk', initials='J.J.') submitter = SubmitterFactory.create_submitter(document, 'JAN JACOB VAN DIJK', date) self.assertEqual(submitter.person, p3) submitter = SubmitterFactory.create_submitter(document, 'JASPER VAN DIJK', date) self.assertEqual(submitter.person, p4)
def test_create_martin(self): person_wikidata_id = 'Q2801440' # Martin van Rooijen parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) self.assertEqual(len(members), 1) party_expected = PoliticalParty.find_party('50plus') self.assertEqual(members[0].party, party_expected)
def get_context_data(self, at_date, **kwargs): context = super().get_context_data(**kwargs) tweedekamer = Parliament.get_or_create_tweede_kamer() members = tweedekamer.get_members_at_date(at_date) context['members'] = members context['date'] = at_date return context
def get_context_data(self, **kwargs): if not self.request.user.is_superuser: raise PermissionError("You need to be an admin to view this page.") context = super().get_context_data(**kwargs) start_date = datetime.date(year=2005, month=6, day=1) members_per_month = self.get_members_per_month(start_date) members = ParliamentMember.objects.all() members_overlap = [] for member in members: members_overlap += member.check_overlap() overlap_ids = [] for member in members_overlap: overlap_ids.append(member.id) parliament = Parliament.get_or_create_tweede_kamer() check_date = datetime.date.today() # check_date = datetime.date(year=2008, month=7, day=1) members_current = parliament.get_members_at_date(check_date) members_current_check = check.check_parliament_members_at_date(check_date) members_missing = check.get_members_missing(members_current, members_current_check) members_incorrect = check.get_members_incorrect(members_current, members_current_check) context['members'] = members context['members_current'] = sorted(members_current, key=lambda member: member.person.surname) context['members_current_missing'] = members_missing context['members_incorrect'] = sorted(members_incorrect, key=lambda member: member.person.surname) context['members_overlap'] = ParliamentMember.objects.filter(pk__in=overlap_ids).distinct() context['members_per_month'] = members_per_month return context
def create_parliament_members(max_results=None, all_members=False, update_votes=True): logger.info('BEGIN') parliament = Parliament.get_or_create_tweede_kamer() if all_members: member_wikidata_ids = wikidata.search_parliament_member_ids() else: member_wikidata_ids = wikidata.search_parliament_member_ids_with_start_date( ) counter = 0 members = [] for person_wikidata_id in member_wikidata_ids: logger.info('=========================') try: members += create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) except (JSONDecodeError, ConnectionError, ConnectTimeout, ChunkedEncodingError) as error: logger.exception(error) except Exception as error: logger.exception(error) raise counter += 1 if max_results and counter >= max_results: logger.info('END: max results reached') break if update_votes: set_individual_votes_derived_info() logger.info('END') return members
def create_parliament_members(max_results=None, all_members=False, update_votes=True): logger.info('BEGIN') parliament = Parliament.get_or_create_tweede_kamer() if all_members: member_wikidata_ids = wikidata.search_parliament_member_ids() else: member_wikidata_ids = wikidata.search_parliament_member_ids_with_start_date() counter = 0 members = [] for person_wikidata_id in member_wikidata_ids: logger.info('=========================') try: members += create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) except (JSONDecodeError, ConnectionError, ConnectTimeout, ChunkedEncodingError) as error: logger.exception(error) except Exception as error: logger.exception(error) raise counter += 1 if max_results and counter >= max_results: logger.info('END: max results reached') break if update_votes: set_individual_votes_derived_info() logger.info('END') return members
def create_or_update_all(start_date): parliament = Parliament.get_or_create_tweede_kamer() end_date = datetime.date.today() date = start_date while date <= end_date: SeatsPerParty.create_for_date(parliament, date) date += datetime.timedelta(days=1) print('next date: ' + str(date))
def test_create_parliament_member_from_wikidata_martin(self): person_wikidata_id = 'Q2801440' # Martin van Rooijen parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) self.assertEqual(len(members), 1) party_expected = PoliticalParty.find_party('50plus') self.assertEqual(members[0].party, party_expected)
def update_current_parliament_members_list(): logger.info('BEGIN') current_pms = Parliament.get_or_create_tweede_kamer().get_members_at_date( datetime.date.today()) update_members_list(list_name='tweedekamerleden', list_owner_id='802459284646850560', members=current_pms) logger.info('END')
def create_all(start_date): parliament = Parliament.get_or_create_tweede_kamer() SeatsPerParty.objects.all().delete() end_date = datetime.date.today() date = start_date while date <= end_date: SeatsPerParty.create_for_date(parliament, date) date += datetime.timedelta(days=1) logger.info('next date: ' + str(date))
def update_current_parliament_members_list(): logger.info('BEGIN') current_pms = Parliament.get_or_create_tweede_kamer().get_members_at_date(datetime.date.today()) update_members_list( list_name='tweedekamerleden', list_owner_id='802459284646850560', members=current_pms ) logger.info('END')
def create_all(start_date): parliament = Parliament.get_or_create_tweede_kamer() SeatsPerParty.objects.all().delete() end_date = datetime.date.today() date = start_date while date <= end_date: SeatsPerParty.create_for_date(parliament, date) date += datetime.timedelta(days=1) logger.info('next date: ' + str(date))
def test_create_kuzu(self): person_wikidata_id = 'Q616635' # Tunahan Kuzu parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) self.assertEqual(len(members), 3) party_expected_0 = PoliticalParty.find_party('PvdA') party_expected_1 = PoliticalParty.find_party('GrKÖ') party_expected_2 = PoliticalParty.find_party('DENK') self.assertEqual(members[0].party, party_expected_0) self.assertEqual(members[1].party, party_expected_1) self.assertEqual(members[2].party, party_expected_2)
def get_context_data(self, at_date, **kwargs): context = super().get_context_data(**kwargs) tweedekamer = Parliament.get_or_create_tweede_kamer() members = tweedekamer.get_members_at_date(at_date) member_filter = ParliamentMemberFilter(self.request.GET, queryset=members) members_filtered = member_filter.qs context['members'] = member_filter.qs context['n_results'] = members_filtered.count() context['filter'] = member_filter context['date'] = at_date return context
def test_create_parliament_member_from_wikidata_kuzu(self): person_wikidata_id = 'Q616635' # Tunahan Kuzu parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) self.assertEqual(len(members), 3) party_expected_0 = PoliticalParty.find_party('PvdA') party_expected_1 = PoliticalParty.find_party('GrKÖ') party_expected_2 = PoliticalParty.find_party('DENK') self.assertEqual(members[0].party, party_expected_0) self.assertEqual(members[1].party, party_expected_1) self.assertEqual(members[2].party, party_expected_2)
def test_submitter(self): date = datetime.date(day=30, month=1, year=2010) p1 = Person.objects.create(forename='Jeroen', surname='Dijsselbloem', initials='J.R.V.A.') parliament = Parliament.get_or_create_tweede_kamer() ParliamentMember.objects.create(person=p1, parliament=parliament, joined=datetime.date(2010, 1, 1), left=datetime.date(2010, 2, 1)) document = Document.objects.create( date_published=datetime.date.today()) submitter = openkamer.kamerstuk.create_submitter( document, 'L. van Tongeren', date) self.assertEqual(submitter.person.initials, 'L.') submitter = openkamer.kamerstuk.create_submitter( document, 'Tongeren C.S.', date) self.assertEqual(submitter.person.initials, '') submitter = openkamer.kamerstuk.create_submitter( document, 'DIJSSELBLOEM', date) self.assertEqual(submitter.person, p1) p5 = Person.objects.create(forename='', surname='Dijsselbloem', initials='') submitter = openkamer.kamerstuk.create_submitter( document, 'DIJSSELBLOEM', date) self.assertEqual(submitter.person, p1) p2 = Person.objects.create(forename='Pieter', surname='Dijsselbloem', initials='P.') ParliamentMember.objects.create(person=p2, parliament=parliament, joined=datetime.date(2010, 1, 1), left=datetime.date(2010, 2, 1)) submitter = openkamer.kamerstuk.create_submitter( document, 'DIJSSELBLOEM', date) self.assertNotEqual(submitter.person, p1) self.assertNotEqual(submitter.person, p2) p3 = Person.objects.create(forename='Jan Jacob', surname_prefix='van', surname='Dijk', initials='J.J.') p4 = Person.objects.create(forename='Jasper', surname_prefix='van', surname='Dijk', initials='J.J.') submitter = openkamer.kamerstuk.create_submitter( document, 'JAN JACOB VAN DIJK', date) self.assertEqual(submitter.person, p3) submitter = openkamer.kamerstuk.create_submitter( document, 'JASPER VAN DIJK', date) self.assertEqual(submitter.person, p4)
def test_create_paul(self): person_wikidata_id = 'Q18169519' # Paul Smeulders Person.objects.create(forename='Paul', surname='Smeulders', wikidata_id=person_wikidata_id) parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) self.assertEqual(len(members), 1) member = members[0] party_expected = PoliticalParty.find_party('GroenLinks') self.assertEqual(member.party, party_expected) self.assertEqual(member.person.initials, '') member.person.update_info() self.assertEqual(member.person.initials, 'P.H.M.')
def test_create_paul(self): person_wikidata_id = 'Q18169519' # Paul Smeulders Person.objects.create( forename='Paul', surname='Smeulders', wikidata_id=person_wikidata_id ) parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) self.assertEqual(len(members), 1) member = members[0] party_expected = PoliticalParty.find_party('GroenLinks') self.assertEqual(member.party, party_expected) self.assertEqual(member.person.initials, '') member.person.update_info() self.assertEqual(member.person.initials, 'P.H.M.')
def get_members_per_month(start_date): current_date = start_date parliament = Parliament.get_or_create_tweede_kamer() members_per_month = [] while current_date < datetime.date.today(): members = parliament.get_members_at_date(current_date) members_per_month.append({ 'date': current_date, 'members': members, }) current_date += datetime.timedelta(days=31) current_date = datetime.date.today() members = parliament.get_members_at_date(current_date) members_per_month.append({ 'date': current_date, 'members': members, }) return members_per_month
def get_members_per_month(start_date): current_date = start_date parliament = Parliament.get_or_create_tweede_kamer() members_per_month = [] while current_date < datetime.date.today(): members = parliament.get_members_at_date(current_date) members_per_month.append({ 'date': current_date, 'members': members, }) current_date += datetime.timedelta(days=31) current_date = datetime.date.today() members = parliament.get_members_at_date(current_date) members_per_month.append({ 'date': current_date, 'members': members, }) return members_per_month
def test_get_members_at_date(self): tweede_kamer = Parliament.get_or_create_tweede_kamer() active_members = tweede_kamer.get_members_at_date( datetime.date(year=2016, month=6, day=1)) self.assertEqual(len(active_members), 150)
def test_get_members_at_date(self): tweede_kamer = Parliament.get_or_create_tweede_kamer() active_members = tweede_kamer.get_members_at_date(datetime.date(year=2016, month=6, day=1)) self.assertEqual(len(active_members), 150)