Last modified, last created

This commit is contained in:
Sebastian Lohff 2017-03-31 03:20:23 +02:00
parent e9aeca1f32
commit 697f203974
3 changed files with 14 additions and 30 deletions

View File

@ -1,8 +1,8 @@
from django import forms
from django.db.models import Q
from whoisdb.models import InetNum, Contact
from whoisdb.forms import MntFormMixin
from whoisdb.models import InetNum
from whoisdb.forms import MntFormMixin, WhoisObjectFormMixin
from whoisdb.validators import IP46CIDRValidator
from .models import Domain, Nameserver, ReverseZone
@ -11,14 +11,12 @@ import re
import ipaddress
class DomainForm(MntFormMixin, forms.ModelForm):
class DomainForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
class Meta:
model = Domain
fields = ['name', 'nameservers', 'mnt_by', 'admin_c']
def __init__(self, user, *args, **kwargs):
self._user = user
def __init__(self, *args, **kwargs):
super(DomainForm, self).__init__(*args, **kwargs)
mnts = self._user.maintainer_set.all()
@ -33,9 +31,6 @@ class DomainForm(MntFormMixin, forms.ModelForm):
self.fields['nameservers'].queryset.distinct()
if 'admin_c' in self.fields:
self.fields['admin_c'].queryset = Contact.getMntQueryset(mnts, self.instance, "admin_c")
def clean_name(self):
name = self.cleaned_data['name'].lower()
if self._create:
@ -60,7 +55,7 @@ class DomainForm(MntFormMixin, forms.ModelForm):
return name
class NameserverForm(MntFormMixin, forms.ModelForm):
class NameserverForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
class Meta:
model = Nameserver
fields = ['name', 'glueIPv4', 'glueIPv6', 'mnt_by', 'admin_c']
@ -69,18 +64,12 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
"glueIPv4": "Note: You can only set a glue record if the base domain of this nameserver belongs to you!"
}
def __init__(self, user, *args, **kwargs):
self._user = user
def __init__(self, *args, **kwargs):
super(NameserverForm, self).__init__(*args, **kwargs)
instance = getattr(self, "instance", None)
self._create = not (instance and instance.pk)
mnts = self._user.maintainer_set.all()
if 'admin_c' in self.fields:
self.fields['admin_c'].queryset = Contact.getMntQueryset(mnts, self.instance, "admin_c")
def clean_name(self):
name = self.cleaned_data['name'].lower().strip()
if not name.endswith("."):
@ -99,18 +88,6 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
except Nameserver.MultipleObjectsReturned:
pass
#zone = ".".join(name.split(".")[-3:])
#mnts = self._user.maintainer_set.all()
#domains = Domain.objects.filter(mnt_by__in=mnts)
#found = False
#for domain in domains:
# if domain.name == zone:
# found = True
# break
#if not found:
# raise forms.ValidationError("This nameserver is not under a domain you control.")
return name
def clean(self):

View File

@ -1,5 +1,6 @@
from django import forms
from django.db.models import Q
from django.utils import timezone
from .models import Maintainer, Contact, InetNum, ASBlock, ASNumber
from .validators import HandleValidatorWithSuffix, IP46CIDRValidator
@ -21,7 +22,8 @@ class WhoisObjectFormMixin(object):
else:
self._create = True
self.fields['handle'].help_text = "Handle for this object in uppercase with a suffix of -%s" % instance.handleSuffix
if 'handle' in self.fields:
self.fields['handle'].help_text = "Handle for this object in uppercase with a suffix of -%s" % instance.handleSuffix
# only show users contacts and already present contacts
mnts = self._user.maintainer_set.all()
@ -41,6 +43,9 @@ class WhoisObjectFormMixin(object):
cleaned_data['handle'] = self._meta.model.genGenericHandle(name)
# XXX: Find a better position to update last_changed
self.instance.last_modified = timezone.now()
return cleaned_data

View File

@ -43,6 +43,8 @@ def getWhoisObjectFields(obj, owner):
fields.append(("Address CIDR", obj.prefix()))
_addFields(fields, obj, ["parentNet", "nameservers"])
_addFields(fields, obj, ["created", "last_modified"])
return fields