From 03f75b12ca6d5f29de85aef45f666af08fe2e900 Mon Sep 17 00:00:00 2001 From: Willard Nilges <willardnilges@gmail.com> Date: Wed, 11 Dec 2024 23:32:48 -0500 Subject: [PATCH] Add NN Status to Query Form (#779) * Add nn status * Add option to query by member name to query form * lint * Add test --- src/meshapi/serializers/query_api.py | 2 ++ src/meshapi/tests/test_query_form.py | 3 +++ src/meshapi/views/query_api.py | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/meshapi/serializers/query_api.py b/src/meshapi/serializers/query_api.py index aa1f971a..e2bfc36f 100644 --- a/src/meshapi/serializers/query_api.py +++ b/src/meshapi/serializers/query_api.py @@ -27,6 +27,7 @@ class Meta: "additional_email_addresses", "notes", "network_number", + "network_number_status", "status", ) @@ -42,6 +43,7 @@ class Meta: ) network_number = serializers.IntegerField(source="node.network_number", allow_null=True) + network_number_status = serializers.CharField(source="node.status", allow_null=True) primary_email_address = serializers.CharField(source="member.primary_email_address") stripe_email_address = serializers.CharField(source="member.stripe_email_address") diff --git a/src/meshapi/tests/test_query_form.py b/src/meshapi/tests/test_query_form.py index a45f4b04..2e11bf77 100644 --- a/src/meshapi/tests/test_query_form.py +++ b/src/meshapi/tests/test_query_form.py @@ -49,5 +49,8 @@ def test_query_address(self): def test_query_email(self): self.query("members", "email_address", self.install.member.primary_email_address) + def test_query_name(self): + self.query("members", "name", self.install.member.name) + def test_query_nn(self): self.query("installs", "network_number", self.install.node.network_number) diff --git a/src/meshapi/views/query_api.py b/src/meshapi/views/query_api.py index cd8552ea..2bc96a30 100644 --- a/src/meshapi/views/query_api.py +++ b/src/meshapi/views/query_api.py @@ -20,10 +20,13 @@ class QueryMemberFilter(filters.FilterSet): - name = filters.CharFilter(field_name="member.name", lookup_expr="icontains") + name = filters.CharFilter(method="filter_on_member_name") email_address = filters.CharFilter(method="filter_on_all_emails") phone_number = filters.CharFilter(method="filter_on_all_phone_numbers") + def filter_on_member_name(self, queryset: QuerySet[Member], field_name: str, value: str) -> QuerySet[Member]: + return queryset.filter(Q(member__name__icontains=value)) + def filter_on_all_emails(self, queryset: QuerySet[Member], field_name: str, value: str) -> QuerySet[Member]: return queryset.filter( Q(member__primary_email_address__icontains=value)