本文整理汇总了Python中mozdns.domain.models.Domain.clean_fields方法的典型用法代码示例。如果您正苦于以下问题:Python Domain.clean_fields方法的具体用法?Python Domain.clean_fields怎么用?Python Domain.clean_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozdns.domain.models.Domain
的用法示例。
在下文中一共展示了Domain.clean_fields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ensure_domain
# 需要导入模块: from mozdns.domain.models import Domain [as 别名]
# 或者: from mozdns.domain.models.Domain import clean_fields [as 别名]
#.........这里部分代码省略.........
This function will attempt to prevent you from:
* creating a new TLD
* creating a domain that would be a child of a delegated domain
* creating a domain that wouldn't exist in an existing zone (it
wouldn't have an SOA)
You can override these constrains by setting the ``force`` named argument
to ``True``.
By default if a domain's parent has an SOA, the new domain will not inherit
that SOA. You can cause the domain to inherit the SOA by passing the named
argument ``inherit_soa`` as ``True``. For example, the function
:func:`ensure_label_domain` passes ``inherit_soa=True``.
If a domain already exists with a name equal to ``name`` it is immediately
returned. It is up to the caller to ensure that ``purgeable`` is set if it
is needed.
"""
try:
domain = Domain.objects.get(name=name)
return domain
except ObjectDoesNotExist:
pass
# Looks like we are creating some domains. Make sure the first domain we
# create is under a domain that has a non-None SOA reference.
parts = list(reversed(name.split('.')))
if not force:
domain_name = ''
leaf_domain = None
# Find the leaf domain.
for i in range(len(parts)):
domain_name = parts[i] + '.' + domain_name
domain_name = domain_name.strip('.')
try:
tmp_domain = Domain.objects.get(name=domain_name)
# It got here so we know we found a domain.
leaf_domain = tmp_domain
except ObjectDoesNotExist:
continue
if not leaf_domain:
raise ValidationError(
"Creating this record would cause the "
"creation of a new TLD. Please contact "
"http://www.icann.org/ for more information.")
if leaf_domain.delegated:
raise ValidationError(
"Creating this record would cause the "
"creation of a domain that would be a child of a "
"delegated domain.")
if not leaf_domain.soa:
raise ValidationError(
"Creating this record would cause the "
"creation of a domain that would not be in an existing "
"DNS zone.")
domain_name = ''
# We know the end domain doesn't exist, so we build it up incrementally
# starting at the very right most parent domain. If we find that a parent
# domain already exists we continue until we find the domain that doesn't
# exist.
for i in range(len(parts)):
domain_name = parts[i] + '.' + domain_name
domain_name = domain_name.strip('.')
if Domain.objects.filter(name=domain_name).exists():
continue
# We are about to create a domain that previously didn't exist!
clobber_querysets = get_clobbered(domain_name)
# Don't use get_or_create here because we need to pass certain kwargs
# to clean()
domain = Domain(name=domain_name)
# we know the clobber_querysets may conflict, but we will handle
# resolving the conflict later in this function
if purgeable:
domain.purgeable = True
domain.clean(ignore_conflicts=True) # master domain is set here
if (inherit_soa and domain.master_domain and
domain.master_domain.soa is not None):
domain.soa = domain.master_domain.soa
# get the domain in the db so we can save the clobbered objects
domain.save(do_full_clean=False)
# update the objects that initially conflicted with this domain
for qs in clobber_querysets:
qs.update(domain=domain, label='')
# full_clean() wasn't called on this domain but clean() was. Calling
# clean_feilds() will ensure we have done the equivalent of a
# full_clean() on the domain.
domain.clean_fields()
return domain