django-orchestra-test/orchestra/apps/domains/helpers.py

34 lines
1.2 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
import copy
from .models import Domain, Record
def domain_for_validation(instance, records):
""" Create a fake zone in order to generate the whole zone file and check it """
domain = copy.copy(instance)
if not domain.pk:
domain.top = domain.get_top()
def get_records():
for data in records:
yield Record(type=data['type'], value=data['value'])
domain.get_records = get_records
2014-10-03 14:02:11 +00:00
def get_top_subdomains(exclude=None):
subdomains = []
for subdomain in Domain.objects.filter(name__endswith='.%s' % domain.origin.name):
if exclude != subdomain.pk:
subdomain.top = domain
yield subdomain
domain.get_top_subdomains = get_top_subdomains
2014-05-08 16:59:35 +00:00
if domain.top:
2014-10-03 14:02:11 +00:00
subdomains = domain.get_top_subdomains(exclude=instance.pk)
2014-05-08 16:59:35 +00:00
domain.top.get_subdomains = lambda: list(subdomains) + [domain]
elif not domain.pk:
subdomains = []
for subdomain in Domain.objects.filter(name__endswith=domain.name):
subdomain.top = domain
subdomains.append(subdomain)
2014-10-03 14:02:11 +00:00
domain.get_subdomains = get_top_subdomains
2014-05-08 16:59:35 +00:00
return domain