Skip to content

Commit

Permalink
Merge pull request #432 from peteeckel/housekeeping/code-cleanup
Browse files Browse the repository at this point in the history
Housekeeping/code cleanup
  • Loading branch information
peteeckel authored Oct 13, 2024
2 parents 720a3fc + af9d23b commit a5aade1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
24 changes: 3 additions & 21 deletions netbox_dns/fields/address.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
from django import forms
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

from netaddr import AddrFormatError, IPAddress

from ipam.formfields import IPAddressFormField

__all__ = (
"AddressFormField",
"AddressField",
)


class AddressFormField(forms.Field):
def to_python(self, value):
if not value:
return None

if isinstance(value, IPAddress):
return value

try:
ip_address = IPAddress(value)
except AddrFormatError as exc:
raise ValidationError(exc)

return ip_address
__all__ = ("AddressField",)


class AddressField(models.Field):
Expand Down Expand Up @@ -58,7 +40,7 @@ def get_prep_value(self, value):
return str(self.to_python(value))

def form_class(self):
return AddressFormField
return IPAddressFormField

def formfield(self, **kwargs):
defaults = {"form_class": self.form_class()}
Expand Down
9 changes: 3 additions & 6 deletions netbox_dns/forms/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ class RecordForm(TenancyForm, NetBoxModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

initial_zone_id = self.initial.get("zone")
if initial_zone_id is not None:
self.initial["view"] = Zone.objects.get(pk=initial_zone_id).view
else:
self.initial["view"] = View.get_default_view()

initial_name = self.initial.get("name")
if initial_name:
self.initial["name"] = name_to_unicode(initial_name)

view = DynamicModelChoiceField(
queryset=View.objects.all(),
required=False,
initial_params={
"zone": "$zone",
},
label=_p("DNS", "View"),
)
zone = DynamicModelChoiceField(
Expand Down

0 comments on commit a5aade1

Please sign in to comment.