From df86629c9fb1d0f120711f5fa732ebebfc2ece57 Mon Sep 17 00:00:00 2001 From: Aly Ibrahim Date: Fri, 12 Nov 2021 17:26:55 -0500 Subject: [PATCH 1/3] add the ability to filter oganization membership by the division the people represent --- openstates/data/models/people_orgs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openstates/data/models/people_orgs.py b/openstates/data/models/people_orgs.py index b5825d51f..e8bfcc811 100644 --- a/openstates/data/models/people_orgs.py +++ b/openstates/data/models/people_orgs.py @@ -117,7 +117,7 @@ def __str__(self): class PersonQuerySet(QuerySet): - def member_of(self, organization_name, current_only=True, post=None): + def member_of(self, organization_name, current_only=True, post=None, division_id=None): if organization_name.startswith("ocd-organization/"): org_filter = Q(memberships__organization_id=organization_name) else: @@ -132,6 +132,8 @@ def member_of(self, organization_name, current_only=True, post=None): ) & Q(memberships__end_date="") | Q(memberships__end_date__gte=today) if post: org_filter &= Q(memberships__post__label=post) + if division_id: + org_filter &= Q(memberships__post__division_id=division_id) return qs.filter(org_filter).distinct() def active(self): From 03caa3e9e500999a421a03874e3b3af36dbe5dc0 Mon Sep 17 00:00:00 2001 From: Aly Ibrahim Date: Fri, 12 Nov 2021 18:56:38 -0500 Subject: [PATCH 2/3] add test --- openstates/data/tests/test_models.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/openstates/data/tests/test_models.py b/openstates/data/tests/test_models.py index 77d79d114..28381b672 100644 --- a/openstates/data/tests/test_models.py +++ b/openstates/data/tests/test_models.py @@ -192,6 +192,34 @@ def test_organization_membership(): assert len(Person.objects.member_of(o.id)) == 1 +@pytest.mark.django_db +def test_organization_membership_multiple_divisions(): + o = Organization.objects.create(name="state") + p1 = Person.objects.create(name="rep1") + p2 = Person.objects.create(name="rep2") + d1 = Division.objects.create(id="ocd-division/country:aa/place:locality1", name="locality1") + d2 = Division.objects.create(id="ocd-division/country:aa/place:locality2", name="locality2") + + post1 = Post.objects.create(label="district rep", role="vip", organization=o, division=d1) + post2 = Post.objects.create(label="district rep", role="vip", organization=o, division=d2) + + o.memberships.create(person=p1, post=post1) + o.memberships.create(person=p2, post=post2) + + people = Person.objects.member_of(o.id, post="district rep").all() + assert len(people) == 2 + assert p1 in people + assert p2 in people + + people = Person.objects.member_of(o.id, post="district rep", division_id=d1.id).all() + assert len(people) == 1 + assert p1 in people + + people = Person.objects.member_of(o.id, post="district rep", division_id=d2.id).all() + assert len(people) == 1 + assert p2 in people + + @pytest.mark.django_db def test_member_of_with_post(): o = Organization.objects.create(name="The Org") From d9ef0efcfb85f91ba02d682acc144af457f4ef95 Mon Sep 17 00:00:00 2001 From: Aly Ibrahim Date: Wed, 24 Nov 2021 17:21:15 -0500 Subject: [PATCH 3/3] add subcommittee --- local.env | 2 ++ openstates/data/common.py | 1 + .../0045_alter_organization_classification.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 local.env create mode 100644 openstates/data/migrations/0045_alter_organization_classification.py diff --git a/local.env b/local.env new file mode 100644 index 000000000..0044acafb --- /dev/null +++ b/local.env @@ -0,0 +1,2 @@ +OS_PEOPLE_DIRECTORY=/Users/alyibrahim/projects/civiqa/backend/openstates/people +DATABASE_URL=postgres://alyibrahim:42571allahis1@localhost:5432/civiqa-db diff --git a/openstates/data/common.py b/openstates/data/common.py index 8e81d745c..a0513ed7a 100644 --- a/openstates/data/common.py +++ b/openstates/data/common.py @@ -44,6 +44,7 @@ ("party", "Party"), ("committee", "Committee"), ("government", "Government"), + ("subcommittee", "Subcommittee"), ) ORGANIZATION_CLASSIFICATIONS = _keys(ORGANIZATION_CLASSIFICATION_CHOICES) diff --git a/openstates/data/migrations/0045_alter_organization_classification.py b/openstates/data/migrations/0045_alter_organization_classification.py new file mode 100644 index 000000000..3db733544 --- /dev/null +++ b/openstates/data/migrations/0045_alter_organization_classification.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.8 on 2021-11-19 11:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0044_bill_citations'), + ] + + operations = [ + migrations.AlterField( + model_name='organization', + name='classification', + field=models.CharField(blank=True, choices=[('legislature', 'Legislature'), ('executive', 'Executive'), ('upper', 'Upper Chamber'), ('lower', 'Lower Chamber'), ('party', 'Party'), ('committee', 'Committee'), ('government', 'Government'), ('subcommittee', 'Subcommittee')], help_text='The type of Organization being defined.', max_length=100), + ), + ]