-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #487 by implementing option 5 in the issue.
Supports: python3.7+, django 3.2+. Tests included for this range. Breaking changes: None This implementation uses django-filter as intended. It sets a default filter backend and uses standard filter_class models where possible. Exceptions take place in the following views: HostList. Relies on manipulating the queryset, and said manipulation is also used in the filter-less HostDetail. *Zone*List. The abstraction model for these views is based around propagating a filterset into the parent class. Concerns: This patch creates explicit mapping filters for JSONField and CIDRField. It is unclear how well-tested these are.
- Loading branch information
Showing
13 changed files
with
382 additions
and
263 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
from django_filters import rest_framework as filters | ||
|
||
from mreg.models import ( | ||
BACnetID, | ||
Cname, | ||
ForwardZone, | ||
ForwardZoneDelegation, | ||
Hinfo, | ||
History, | ||
Host, | ||
HostGroup, | ||
Ipaddress, | ||
Label, | ||
Loc, | ||
Mx, | ||
NameServer, | ||
Naptr, | ||
NetGroupRegexPermission, | ||
Network, | ||
NetworkExcludedRange, | ||
PtrOverride, | ||
ReverseZone, | ||
ReverseZoneDelegation, | ||
Srv, | ||
Sshfp, | ||
Txt, | ||
) | ||
|
||
|
||
class JSONFieldExactFilter(filters.BaseCSVFilter, filters.CharFilter): | ||
pass | ||
|
||
|
||
class CIDRFieldExactFilter(filters.BaseCSVFilter, filters.CharFilter): | ||
pass | ||
|
||
|
||
class BACnetIDFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = BACnetID | ||
fields = "__all__" | ||
|
||
|
||
class CnameFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Cname | ||
fields = "__all__" | ||
|
||
|
||
class ForwardZoneFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = ForwardZone | ||
fields = "__all__" | ||
|
||
|
||
class ForwardZoneDelegationFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = ForwardZoneDelegation | ||
fields = "__all__" | ||
|
||
|
||
class HinfoFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Hinfo | ||
fields = "__all__" | ||
|
||
|
||
class HistoryFilterSet(filters.FilterSet): | ||
data = JSONFieldExactFilter(field_name="data") | ||
|
||
class Meta: | ||
model = History | ||
fields = "__all__" | ||
|
||
|
||
class HostFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Host | ||
fields = "__all__" | ||
|
||
|
||
class HostGroupFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = HostGroup | ||
fields = "__all__" | ||
|
||
|
||
class IpaddressFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Ipaddress | ||
fields = "__all__" | ||
|
||
|
||
class LabelFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Label | ||
fields = "__all__" | ||
|
||
|
||
class LocFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Loc | ||
fields = "__all__" | ||
|
||
|
||
class MxFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Mx | ||
fields = "__all__" | ||
|
||
|
||
class NameServerFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = NameServer | ||
fields = "__all__" | ||
|
||
|
||
class NaptrFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Naptr | ||
fields = "__all__" | ||
|
||
|
||
class NetGroupRegexPermissionFilterSet(filters.FilterSet): | ||
range = CIDRFieldExactFilter(field_name="range") | ||
|
||
class Meta: | ||
model = NetGroupRegexPermission | ||
fields = "__all__" | ||
|
||
|
||
class NetworkFilterSet(filters.FilterSet): | ||
network = CIDRFieldExactFilter(field_name="network") | ||
|
||
class Meta: | ||
model = Network | ||
fields = "__all__" | ||
|
||
|
||
class NetworkExcludedRangeFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = NetworkExcludedRange | ||
fields = "__all__" | ||
|
||
|
||
class PtrOverrideFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = PtrOverride | ||
fields = "__all__" | ||
|
||
|
||
class ReverseZoneFilterSet(filters.FilterSet): | ||
network = CIDRFieldExactFilter(field_name="network") | ||
|
||
class Meta: | ||
model = ReverseZone | ||
fields = "__all__" | ||
|
||
|
||
class ReverseZoneDelegationFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = ReverseZoneDelegation | ||
fields = "__all__" | ||
|
||
|
||
class SrvFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Srv | ||
fields = "__all__" | ||
|
||
|
||
class SshfpFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Sshfp | ||
fields = "__all__" | ||
|
||
|
||
class TxtFilterSet(filters.FilterSet): | ||
class Meta: | ||
model = Txt | ||
fields = "__all__" |
Oops, something went wrong.