Lang fixes, filter admins, fix nameserver adding

This commit is contained in:
Sebastian Lohff 2017-03-28 13:00:27 +02:00
parent 9e241adb8e
commit 54e34a49b0
2 changed files with 11 additions and 4 deletions

View File

@ -1,7 +1,7 @@
from django import forms from django import forms
from django.db.models import Q from django.db.models import Q
from whoisdb.models import InetNum from whoisdb.models import InetNum, Contact
from whoisdb.forms import MntFormMixin from whoisdb.forms import MntFormMixin
from whoisdb.validators import IP46CIDRValidator from whoisdb.validators import IP46CIDRValidator
@ -33,6 +33,9 @@ class DomainForm(MntFormMixin, forms.ModelForm):
self.fields['nameservers'].queryset.distinct() 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): def clean_name(self):
name = self.cleaned_data['name'].lower() name = self.cleaned_data['name'].lower()
if self._create: if self._create:
@ -74,6 +77,10 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
instance = getattr(self, "instance", None) instance = getattr(self, "instance", None)
self._create = not (instance and instance.pk) 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): def clean_name(self):
name = self.cleaned_data['name'].lower().strip() name = self.cleaned_data['name'].lower().strip()
if not name.endswith("."): if not name.endswith("."):
@ -115,7 +122,7 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
ipv4 = cleaned_data.get("glueIPv4") ipv4 = cleaned_data.get("glueIPv4")
ipv6 = cleaned_data.get("glueIPv6") ipv6 = cleaned_data.get("glueIPv6")
if (ipv4 or ipv6) and self._create or not (self.instance.glueIPv4 == ipv4 and self.instance.glueIPv6 == ipv6): if self._create and (ipv4 or ipv6) or not self._create and not (self.instance.glueIPv4 == ipv4 and self.instance.glueIPv6 == ipv6):
mnts = self._user.maintainer_set.all() mnts = self._user.maintainer_set.all()
domains = Domain.objects.filter(mnt_by__in=mnts) domains = Domain.objects.filter(mnt_by__in=mnts)
found = False found = False
@ -125,7 +132,7 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
break break
if not found: if not found:
raise forms.ValidationError("This nameserver is not under a domain you control.") raise forms.ValidationError("You have glue IPs set, but this domain is not under a domain you control.")
return cleaned_data return cleaned_data

View File

@ -14,7 +14,7 @@ class RequestForm(forms.Form):
subject = forms.CharField(label="Subject") subject = forms.CharField(label="Subject")
resources = forms.CheckboxSelectMultiple(choices=RESOURCES) resources = forms.CheckboxSelectMultiple(choices=RESOURCES)
message = forms.CharField(widget=forms.Textarea, help_text="Describe shortly what resources you need and what for you need them") message = forms.CharField(widget=forms.Textarea, help_text="Describe shortly what resources you need and what you need them for")
def __init__(self, user, *args, **kwargs): def __init__(self, user, *args, **kwargs):
super(RequestForm, self).__init__(*args, **kwargs) super(RequestForm, self).__init__(*args, **kwargs)