Skip to content

Commit

Permalink
Merge branch 'main' into wdn/scramble
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges authored Apr 21, 2024
2 parents 6cdacb7 + 2d179bc commit e6e9598
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/meshapi/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,21 @@ class InstallAdmin(admin.ModelAdmin):
),
]

def get_search_results(self, request, queryset, search_term):
queryset, may_have_duplicates = super().get_search_results(
request,
queryset,
search_term,
)
try:
upper_search = search_term.upper()
if len(upper_search) > 2 and upper_search[:2] == "NN":
search_term_as_int = int(upper_search[2:])
queryset |= self.model.objects.filter(node_id=search_term_as_int)
except ValueError:
pass
return queryset, may_have_duplicates


class LinkAdminForm(forms.ModelForm):
class Meta:
Expand Down
9 changes: 9 additions & 0 deletions src/meshapi/tests/test_admin_search_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ def test_search_device(self):

def test_search_node(self):
self._call("/admin/meshapi/node/?q=1", 200)

def test_search_install_by_nn(self):
self._call("/admin/meshapi/install/?q=nN1", 200)

def test_search_install_just_nn(self):
self._call("/admin/meshapi/install/?q=nN", 200)

def test_search_install_empty(self):
self._call("/admin/meshapi/install/?q=", 200)
29 changes: 29 additions & 0 deletions src/meshapi/views/query_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db.models import Q
from django_filters import rest_framework as filters
from drf_spectacular.utils import extend_schema, extend_schema_view

from meshapi.docs import query_form_password_param
from meshapi.models import Install
from meshapi.permissions import LegacyMeshQueryPassword
from meshapi.serializers.query_api import QueryFormSerializer
Expand Down Expand Up @@ -32,6 +34,15 @@ class Meta:
fields = []


@extend_schema_view(
get=extend_schema(
tags=["Legacy Query Form"],
parameters=[query_form_password_param],
summary="Query & filter based on Member attributes. "
"Results are returned as flattened spreadsheet row style output",
auth=[],
),
)
class QueryMember(FilterRequiredListAPIView):
queryset = (
Install.objects.all()
Expand All @@ -53,6 +64,15 @@ class Meta:
fields = ["install_number", "member", "building", "status"]


@extend_schema_view(
get=extend_schema(
tags=["Legacy Query Form"],
parameters=[query_form_password_param],
summary="Query & filter based on Install attributes. "
"Results are returned as flattened spreadsheet row style output",
auth=[],
),
)
class QueryInstall(FilterRequiredListAPIView):
queryset = (
Install.objects.all()
Expand All @@ -78,6 +98,15 @@ class Meta:
fields = ["bin", "zip_code"]


@extend_schema_view(
get=extend_schema(
tags=["Legacy Query Form"],
parameters=[query_form_password_param],
summary="Query & filter based on Building attributes. "
"Results are returned as flattened spreadsheet row style output",
auth=[],
),
)
class QueryBuilding(FilterRequiredListAPIView):
queryset = (
Install.objects.all()
Expand Down

0 comments on commit e6e9598

Please sign in to comment.