From 55828dc6ca56c5d9dba970935e7e5c6ada3087a6 Mon Sep 17 00:00:00 2001 From: Sym Roe Date: Mon, 11 Sep 2023 17:12:48 +0100 Subject: [PATCH] Add delisted flag to people --- ynr/apps/people/admin.py | 7 +++++-- ynr/apps/people/api/next/serializers.py | 1 + ynr/apps/people/models.py | 5 +++++ ynr/apps/people/tests/test_api_views.py | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ynr/apps/people/admin.py b/ynr/apps/people/admin.py index 5cf6bfdcb..73cfe4c58 100644 --- a/ynr/apps/people/admin.py +++ b/ynr/apps/people/admin.py @@ -90,8 +90,11 @@ class PersonAdmin(admin.ModelAdmin): }, ), ( - "Edit limitations", - {"classes": ("collapse",), "fields": ("edit_limitations",)}, + "Restrictions", + { + "classes": ("collapse",), + "fields": ("edit_limitations", "delisted"), + }, ), ) diff --git a/ynr/apps/people/api/next/serializers.py b/ynr/apps/people/api/next/serializers.py index c627fd259..92dc708d8 100644 --- a/ynr/apps/people/api/next/serializers.py +++ b/ynr/apps/people/api/next/serializers.py @@ -100,6 +100,7 @@ class Meta: "thumbnail", "statement_to_voters", "favourite_biscuit", + "delisted", ) versions_url = serializers.HyperlinkedIdentityField( diff --git a/ynr/apps/people/models.py b/ynr/apps/people/models.py index dd0ca2991..ddaaa64ea 100644 --- a/ynr/apps/people/models.py +++ b/ynr/apps/people/models.py @@ -307,6 +307,11 @@ class Person(TimeStampedModel, models.Model): ], ) + delisted = models.BooleanField( + default=False, + help_text="Mark this person as de-listed in search engines. Might take some days to come in to effect", + ) + name_search_vector = SearchVectorField(null=True) class Meta: diff --git a/ynr/apps/people/tests/test_api_views.py b/ynr/apps/people/tests/test_api_views.py index e496d9239..107c1ae52 100644 --- a/ynr/apps/people/tests/test_api_views.py +++ b/ynr/apps/people/tests/test_api_views.py @@ -104,3 +104,17 @@ def test_person_history_view(self): response.json(), {"count": 0, "next": None, "previous": None, "results": []}, ) + + def test_delisted_in_api(self): + person = self.people[0] + response = self.client.get(f"/api/next/people/{person.pk}/") + data = response.json() + self.assertTrue("delisted" in data) + self.assertFalse(data["delisted"]) + + person.delisted = True + person.save() + response = self.client.get(f"/api/next/people/{person.pk}/") + data = response.json() + self.assertTrue("delisted" in data) + self.assertTrue(data["delisted"])