Skip to content

Commit

Permalink
Migrate to django-filter 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Nov 26, 2021
1 parent 86a5f3e commit 605afa2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion python/nav/auditlog/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ class LogEntryViewSet(NAVDefaultsMixin, viewsets.ReadOnlyModelViewSet):
)
queryset = LogEntry.objects.all()
serializer_class = LogEntrySerializer
filter_fields = ('subsystem', 'object_pk', 'verb')
filterset_fields = ('subsystem', 'object_pk', 'verb')
search_fields = ('summary',)
ordering = ('timestamp',)
26 changes: 13 additions & 13 deletions python/nav/web/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class AccountViewSet(NAVAPIMixin, viewsets.ModelViewSet):

queryset = profiles.Account.objects.all()
serializer_class = serializers.AccountSerializer
filter_fields = ('login', 'ext_sync')
filterset_fields = ('login', 'ext_sync')
search_fields = ('name',)


Expand Down Expand Up @@ -319,7 +319,7 @@ class RoomViewSet(LoggerMixin, NAVAPIMixin, viewsets.ModelViewSet):

queryset = manage.Room.objects.all()
serializer_class = serializers.RoomSerializer
filter_fields = ('location', 'description')
filterset_fields = ('location', 'description')


class LocationViewSet(LoggerMixin, NAVAPIMixin, viewsets.ModelViewSet):
Expand All @@ -337,7 +337,7 @@ class LocationViewSet(LoggerMixin, NAVAPIMixin, viewsets.ModelViewSet):

queryset = manage.Location.objects.all()
serializer_class = serializers.LocationSerializer
filter_fields = ('id', 'parent')
filterset_fields = ('id', 'parent')
search_fields = ('description',)


Expand All @@ -356,7 +356,7 @@ class UnrecognizedNeighborViewSet(NAVAPIMixin, viewsets.ReadOnlyModelViewSet):

queryset = manage.UnrecognizedNeighbor.objects.all()
serializer_class = serializers.UnrecognizedNeighborSerializer
filter_fields = ('netbox', 'source')
filterset_fields = ('netbox', 'source')
search_fields = ('remote_name',)


Expand Down Expand Up @@ -390,7 +390,7 @@ class NetboxViewSet(LoggerMixin, NAVAPIMixin, viewsets.ModelViewSet):

queryset = manage.Netbox.objects.all()
serializer_class = serializers.NetboxSerializer
filter_fields = (
filterset_fields = (
'ip',
'sysname',
'room',
Expand Down Expand Up @@ -493,7 +493,7 @@ class InterfaceViewSet(NAVAPIMixin, viewsets.ReadOnlyModelViewSet):

# NaturalIfnameFilter returns a list, so IfClassFilter needs to come first
filter_backends = NAVAPIMixin.filter_backends + (IfClassFilter, NaturalIfnameFilter)
filter_class = InterfaceFilterClass
filterset_class = InterfaceFilterClass

def get_serializer_class(self):
request = self.request
Expand Down Expand Up @@ -556,7 +556,7 @@ class PatchViewSet(NAVAPIMixin, viewsets.ReadOnlyModelViewSet):
'cabling__room', 'interface__netbox'
).all()
serializer_class = serializers.PatchSerializer
filter_fields = ('cabling', 'cabling__room', 'interface', 'interface__netbox')
filterset_fields = ('cabling', 'cabling__room', 'interface', 'interface__netbox')
search_fields = ('cabling__jack',)


Expand All @@ -579,7 +579,7 @@ class CablingViewSet(NAVAPIMixin, viewsets.ReadOnlyModelViewSet):
"""

serializer_class = serializers.CablingSerializer
filter_fields = ('room', 'jack', 'building', 'target_room', 'category')
filterset_fields = ('room', 'jack', 'building', 'target_room', 'category')
search_fields = ('jack', 'target_room', 'building')

def get_queryset(self):
Expand Down Expand Up @@ -663,7 +663,7 @@ class CamViewSet(MachineTrackerViewSet):

model_class = manage.Cam
serializer_class = serializers.CamSerializer
filter_fields = ('netbox', 'ifindex', 'port')
filterset_fields = ('netbox', 'ifindex', 'port')

def list(self, request):
"""Override list so that we can control what is returned"""
Expand Down Expand Up @@ -705,7 +705,7 @@ class ArpViewSet(MachineTrackerViewSet):

model_class = manage.Arp
serializer_class = serializers.ArpSerializer
filter_fields = ('netbox', 'prefix')
filterset_fields = ('netbox', 'prefix')

def list(self, request):
"""Override list so that we can control what is returned"""
Expand Down Expand Up @@ -751,7 +751,7 @@ class VlanViewSet(NAVAPIMixin, viewsets.ModelViewSet):

queryset = manage.Vlan.objects.all()
serializer_class = serializers.VlanSerializer
filter_fields = [
filterset_fields = [
'vlan',
'net_type',
'net_ident',
Expand All @@ -775,7 +775,7 @@ class PrefixViewSet(NAVAPIMixin, viewsets.ModelViewSet):

queryset = manage.Prefix.objects.all()
serializer_class = serializers.PrefixSerializer
filter_fields = ('vlan', 'net_address', 'vlan__vlan')
filterset_fields = ('vlan', 'net_address', 'vlan__vlan')

@action(detail=False)
def search(self, request):
Expand Down Expand Up @@ -1049,7 +1049,7 @@ class RackViewSet(NAVAPIMixin, viewsets.ReadOnlyModelViewSet):

queryset = rack.Rack.objects.all()
serializer_class = serializers.RackSerializer
filter_fields = ['room', 'rackname']
filterset_fields = ['room', 'rackname']
search_fields = ['rackname']


Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Markdown==3.3.6
feedparser==6.0.8
dnspython==1.15.0

django-filter>=2
djangorestframework>=3.12,<3.13

# REST framework
Expand Down
1 change: 0 additions & 1 deletion requirements/django22.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Django>=2.2,<2.3
django-filter>=2
django-crispy-forms>=1.7,<1.8
crispy-forms-foundation>=0.7,<0.8
1 change: 0 additions & 1 deletion requirements/django32.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Django>=3.2,<3.3
django-filter>=2

0 comments on commit 605afa2

Please sign in to comment.