Skip to content

Commit

Permalink
Refactoring cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjekv committed Aug 7, 2024
1 parent 6757d93 commit 0c442c1
Showing 1 changed file with 41 additions and 87 deletions.
128 changes: 41 additions & 87 deletions mreg/api/v1/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@
INT_OPERATORS: OperatorList = ["exact", "in", "gt", "lt"]
EXACT_OPERATORS: OperatorList = ["exact"]


HOST_FIELDS = {
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
}

CREATED_UPDATED = {
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
}

class CIDRFieldExactFilter(filters.CharFilter):
pass
Expand All @@ -43,11 +54,7 @@ class Meta:
model = BACnetID
fields = {
"id": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
**HOST_FIELDS,
}


Expand All @@ -56,15 +63,10 @@ class Meta:
model = Cname
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"name": STRING_OPERATORS,
"ttl": INT_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED,
}


Expand All @@ -73,9 +75,8 @@ class Meta:
model = ForwardZone
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"name": STRING_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -84,11 +85,10 @@ class Meta:
model = ForwardZoneDelegation
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"name": STRING_OPERATORS,
"nameservers": INT_OPERATORS,
"comment": STRING_OPERATORS,
**CREATED_UPDATED,
}


Expand Down Expand Up @@ -141,8 +141,6 @@ class Meta:
model = Host
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"name": STRING_OPERATORS,
"contact": STRING_OPERATORS,
"ttl": INT_OPERATORS,
Expand Down Expand Up @@ -178,6 +176,7 @@ class Meta:
"srvs__weight": INT_OPERATORS,
"srvs__port": INT_OPERATORS,
"srvs__ttl": INT_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -186,13 +185,12 @@ class Meta:
model = HostGroup
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"description": STRING_OPERATORS,
"hosts": INT_OPERATORS,
"name": STRING_OPERATORS,
"owners": INT_OPERATORS,
"parent": INT_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -203,11 +201,7 @@ class Meta:
"id": INT_OPERATORS,
"ipaddress": STRING_OPERATORS,
"macaddress": STRING_OPERATORS,
"host": INT_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__comment": STRING_OPERATORS,
**HOST_FIELDS,
}


Expand All @@ -216,23 +210,18 @@ class Meta:
model = Label
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"description": STRING_OPERATORS,
"name": STRING_OPERATORS,
**CREATED_UPDATED,
}


class LocFilterSet(filters.FilterSet):
class Meta:
model = Loc
fields = {
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"loc": STRING_OPERATORS,
**HOST_FIELDS,
}


Expand All @@ -241,15 +230,10 @@ class Meta:
model = Mx
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"priority": INT_OPERATORS,
"mx": STRING_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED
}


Expand All @@ -258,10 +242,9 @@ class Meta:
model = NameServer
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"name": STRING_OPERATORS,
"ttl": INT_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -270,19 +253,14 @@ class Meta:
model = Naptr
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"preference": INT_OPERATORS,
"order": INT_OPERATORS,
"flag": STRING_OPERATORS,
"service": STRING_OPERATORS,
"regex": STRING_OPERATORS,
"replacement": STRING_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED,
}


Expand All @@ -293,11 +271,10 @@ class Meta:
model = NetGroupRegexPermission
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"group": STRING_OPERATORS,
"regex": STRING_OPERATORS,
"labels": INT_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -308,15 +285,14 @@ class Meta:
model = Network
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"description": STRING_OPERATORS,
"vlan": INT_OPERATORS,
"dns_delegated": EXACT_OPERATORS,
"category": STRING_OPERATORS,
"location": STRING_OPERATORS,
"frozen": EXACT_OPERATORS,
"reserved": INT_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -325,8 +301,6 @@ class Meta:
model = NetworkExcludedRange
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"network": INT_OPERATORS,
"network__description": STRING_OPERATORS,
"network__vlan": INT_OPERATORS,
Expand All @@ -337,6 +311,7 @@ class Meta:
"network__reserved": INT_OPERATORS,
"start_ip": STRING_OPERATORS,
"end_ip": STRING_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -345,27 +320,22 @@ class Meta:
model = PtrOverride
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"ipaddress": EXACT_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED,
}



class ReverseZoneFilterSet(filters.FilterSet):
network = CIDRFieldExactFilter(field_name="network")

class Meta:
model = ReverseZone
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"name": STRING_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -374,13 +344,12 @@ class Meta:
model = ReverseZoneDelegation
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"name": STRING_OPERATORS,
"nameservers": INT_OPERATORS,
"comment": STRING_OPERATORS,
"zone": INT_OPERATORS,
"zone__name": STRING_OPERATORS,
**CREATED_UPDATED,
}


Expand All @@ -389,18 +358,13 @@ class Meta:
model = Srv
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"name": STRING_OPERATORS,
"priority": INT_OPERATORS,
"weight": INT_OPERATORS,
"port": INT_OPERATORS,
"ttl": INT_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED,
}


Expand All @@ -409,16 +373,11 @@ class Meta:
model = Sshfp
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"algorithm": INT_OPERATORS,
"hash_type": INT_OPERATORS,
"fingerprint": STRING_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED,
}


Expand All @@ -427,12 +386,7 @@ class Meta:
model = Txt
fields = {
"id": INT_OPERATORS,
"created_at": INT_OPERATORS,
"updated_at": INT_OPERATORS,
"host": INT_OPERATORS,
"host__comment": STRING_OPERATORS,
"host__contact": STRING_OPERATORS,
"host__name": STRING_OPERATORS,
"host__ttl": INT_OPERATORS,
"txt": STRING_OPERATORS,
**HOST_FIELDS,
**CREATED_UPDATED,
}

0 comments on commit 0c442c1

Please sign in to comment.