本文整理汇总了Python中cyder.cydns.address_record.models.AddressRecord.set_is_glue方法的典型用法代码示例。如果您正苦于以下问题:Python AddressRecord.set_is_glue方法的具体用法?Python AddressRecord.set_is_glue怎么用?Python AddressRecord.set_is_glue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyder.cydns.address_record.models.AddressRecord
的用法示例。
在下文中一共展示了AddressRecord.set_is_glue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NameserverForm
# 需要导入模块: from cyder.cydns.address_record.models import AddressRecord [as 别名]
# 或者: from cyder.cydns.address_record.models.AddressRecord import set_is_glue [as 别名]
class NameserverForm(DNSForm, UsabilityFormMixin):
glue_ip_str = forms.CharField(label="Glue's IP Address", required=False)
glue_ctnr = forms.ModelChoiceField(
queryset=Ctnr.objects.all(),
required=False,
label="Glue's Container")
class Meta:
model = Nameserver
fields = ('domain', 'server', 'views', 'ttl', 'glue_ip_str',
'glue_ctnr', 'description')
exclude = ('addr_glue', 'intr_glue')
widgets = {'views': forms.CheckboxSelectMultiple}
def __init__(self, *args, **kwargs):
super(NameserverForm, self).__init__(*args, **kwargs)
if not self.instance:
return
if not self.instance.glue:
# If it doesn't have glue, it doesn't need it.
return
addr_glue = AddressRecord.objects.filter(
label=self.instance.glue.label,
domain=self.instance.glue.domain)
intr_glue = StaticInterface.objects.filter(
label=self.instance.glue.label,
domain=self.instance.glue.domain)
glue_choices = []
for glue in addr_glue:
glue_choices.append(("addr_{0}".format(glue.pk), str(glue)))
for glue in intr_glue:
glue_choices.append(("intr_{0}".format(glue.pk), str(glue)))
if isinstance(self.instance.glue, AddressRecord):
initial = "addr_{0}".format(self.instance.glue.pk)
elif isinstance(self.instance.glue, StaticInterface):
initial = "intr_{0}".format(self.instance.glue.pk)
self.fields['glue'] = forms.ChoiceField(choices=glue_choices,
initial=initial)
def clean(self, *args, **kwargs):
self.glue = None
if self.instance.pk is None:
domain = self.cleaned_data['domain']
glue_ip_str, glue_ctnr = (self.cleaned_data['glue_ip_str'],
self.cleaned_data['glue_ctnr'])
server = self.cleaned_data['server'].strip('.')
if '.' in server:
if server.lower() != domain.name.lower():
glue_label, glue_domain = tuple(server.split('.', 1))
glue_domain = glue_domain.strip('.').lower()
else:
glue_label, glue_domain = "", server.lower()
else:
raise ValidationError(
"Please provide a fully qualified server name.")
if domain.delegated:
if glue_domain and glue_domain != domain.name.lower():
if glue_ip_str or glue_ctnr:
raise ValidationError(
"This record does not need glue, so "
"please leave the glue fields blank.")
else:
if not (glue_ip_str and glue_ctnr):
raise ValidationError(
"This zone is delegated, so "
"please provide information for glue.")
gluekwargs = {'domain': domain, 'label': glue_label,
'ip_str': glue_ip_str, 'ctnr': glue_ctnr}
try:
self.glue = AddressRecord.objects.get(**gluekwargs)
except AddressRecord.DoesNotExist:
self.glue = AddressRecord(**gluekwargs)
self.glue.set_is_glue()
self.glue.save()
for v in View.objects.all():
self.glue.views.add(v)
elif not domain.delegated and (glue_ip_str or glue_ctnr):
raise ValidationError("This zone is not delegated, so please "
"leave the glue fields blank.")
cleaned_data = super(NameserverForm, self).clean(*args, **kwargs)
return cleaned_data
def save(self, *args, **kwargs):
try:
super(NameserverForm, self).save(*args, **kwargs)
except Exception, e:
if self.glue and self.glue.pk is not None:
self.glue.delete(validate_glue=False)
raise ValidationError(e)