<s> import simplejson as json <EOL> from django . contrib import messages <EOL> from django . forms import ValidationError <EOL> from django . shortcuts import render <EOL> from django . http import HttpResponse <EOL> from django . shortcuts import redirect <EOL> from django . views . generic import UpdateView <EOL> from django . views . generic import DetailView <EOL> from django . views . generic import CreateView <EOL> from mozdns . utils import tablefy <EOL> from mozdns . views import MozdnsDeleteView , MozdnsListView <EOL> from mozdns . domain . models import Domain <EOL> from mozdns . domain . forms import DomainForm , DomainUpdateForm <EOL> def domain_sort ( domains ) : <EOL> """<STR_LIT>""" <EOL> roots = domains . filter ( master_domain = None ) <EOL> ordered = [ ] <EOL> for root in roots : <EOL> ordered += build_tree ( root , domains ) <EOL> return ordered <EOL> def build_tree ( root , domains ) : <EOL> if len ( domains ) == <NUM_LIT:0> : <EOL> return root <EOL> ordered = [ root ] <EOL> children = domains . filter ( master_domain = root ) <EOL> for child in children : <EOL> ordered += build_tree ( child , domains ) <EOL> return ordered <EOL> def get_all_domains ( request ) : <EOL> domains = [ domain . name for domain in Domain . objects . all ( ) ] <EOL> return HttpResponse ( json . dumps ( domains ) ) <EOL> class DomainView ( object ) : <EOL> model = Domain <EOL> queryset = Domain . objects . all ( ) . order_by ( '<STR_LIT:name>' ) <EOL> form_class = DomainForm <EOL> class DomainDeleteView ( DomainView , MozdnsDeleteView ) : <EOL> """<STR_LIT:U+0020>""" <EOL> class DomainListView ( DomainView , MozdnsListView ) : <EOL> queryset = Domain . objects . filter ( is_reverse = False ) <EOL> template_name = "<STR_LIT>" <EOL> paginate_by = <NUM_LIT:200> <EOL> class ReverseDomainListView ( DomainView , MozdnsListView ) : <EOL> queryset = Domain . objects . filter ( is_reverse = True ) . order_by ( '<STR_LIT:name>' ) <EOL> paginate_by = <NUM_LIT:200> <EOL> class DomainDetailView ( DomainView , DetailView ) : <EOL> template_name = "<STR_LIT>" <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( DetailView , self ) . get_context_data ( ** kwargs ) <EOL> domain = kwargs . get ( '<STR_LIT:object>' , False ) <EOL> if not domain : <EOL> return context <EOL> mx_objects = domain . mx_set . all ( ) . order_by ( '<STR_LIT:label>' ) <EOL> mx_headers , mx_matrix , mx_urls = tablefy ( mx_objects ) <EOL> srv_objects = domain . srv_set . all ( ) . order_by ( '<STR_LIT:label>' ) <EOL> srv_headers , srv_matrix , srv_urls = tablefy ( srv_objects ) <EOL> txt_objects = domain . txt_set . all ( ) . order_by ( '<STR_LIT:label>' ) <EOL> txt_headers , txt_matrix , txt_urls = tablefy ( txt_objects ) <EOL> sshfp_objects = domain . sshfp_set . all ( ) . order_by ( '<STR_LIT:label>' ) <EOL> sshfp_headers , sshfp_matrix , sshfp_urls = tablefy ( sshfp_objects ) <EOL> cname_objects = domain . cname_set . order_by ( '<STR_LIT:label>' ) <EOL> if cname_objects . count ( ) > <NUM_LIT:50> : <EOL> cname_views = False <EOL> else : <EOL> cname_views = True <EOL> cname_headers , cname_matrix , cname_urls = tablefy ( cname_objects , <EOL> cname_views ) <EOL> ptr_objects = domain . ptr_set . all ( ) . order_by ( '<STR_LIT>' ) <EOL> ptr_headers , ptr_matrix , ptr_urls = tablefy ( ptr_objects ) <EOL> sreg_objects = domain . staticreg_set . all ( ) . order_by ( <EOL> '<STR_LIT:name>' ) . order_by ( '<STR_LIT>' ) <EOL> sreg_headers , sreg_matrix , sreg_urls = tablefy ( sreg_objects ) <EOL> address_objects = domain . addressrecord_set . all ( ) . order_by ( '<STR_LIT:label>' ) <EOL> if address_objects . count ( ) > <NUM_LIT:50> : <EOL> adr_views = False <EOL> else : <EOL> adr_views = True <EOL> adr_headers , adr_matrix , adr_urls = tablefy ( address_objects , adr_views ) <EOL> ns_objects = domain . nameserver_set . all ( ) . order_by ( '<STR_LIT>' ) <EOL> ns_headers , ns_matrix , ns_urls = tablefy ( ns_objects ) <EOL> domain_objects = domain . domain_set . all ( ) . order_by ( '<STR_LIT:name>' ) <EOL> domain_headers , domain_matrix , domain_urls = tablefy ( domain_objects ) <EOL> context = dict ( { <EOL> "<STR_LIT>" : ns_headers , <EOL> "<STR_LIT>" : ns_matrix , <EOL> "<STR_LIT>" : ns_urls , <EOL> "<STR_LIT>" : domain_headers , <EOL> "<STR_LIT>" : domain_matrix , <EOL> "<STR_LIT>" : domain_urls , <EOL> "<STR_LIT>" : adr_headers , <EOL> "<STR_LIT>" : adr_matrix , <EOL> "<STR_LIT>" : adr_urls , <EOL> "<STR_LIT>" : adr_views , <EOL> "<STR_LIT>" : mx_headers , <EOL> "<STR_LIT>" : mx_matrix , <EOL> "<STR_LIT>" : mx_urls , <EOL> "<STR_LIT>" : srv_headers , <EOL> "<STR_LIT>" : srv_matrix , <EOL> "<STR_LIT>" : srv_urls , <EOL> "<STR_LIT>" : txt_headers , <EOL> "<STR_LIT>" : txt_matrix , <EOL> "<STR_LIT>" : txt_urls , <EOL> "<STR_LIT>" : sshfp_headers , <EOL> "<STR_LIT>" : sshfp_matrix , <EOL> "<STR_LIT>" : sshfp_urls , <EOL> "<STR_LIT>" : cname_headers , <EOL> "<STR_LIT>" : cname_matrix , <EOL> "<STR_LIT>" : cname_urls , <EOL> "<STR_LIT>" : cname_views , <EOL> "<STR_LIT>" : ptr_headers , <EOL> "<STR_LIT>" : ptr_matrix , <EOL> "<STR_LIT>" : ptr_urls , <EOL> "<STR_LIT>" : sreg_headers , <EOL> "<STR_LIT>" : sreg_matrix , <EOL> "<STR_LIT>" : sreg_urls <EOL> } . items ( ) + context . items ( ) ) <EOL> return context <EOL> class DomainCreateView ( DomainView , CreateView ) : <EOL> model_form = DomainForm <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> domain_form = DomainForm ( request . POST ) <EOL> try : <EOL> domain = domain_form . save ( ) <EOL> except ValueError : <EOL> return render ( request , "<STR_LIT>" , { <EOL> '<STR_LIT>' : domain_form , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> try : <EOL> if domain . master_domain and domain . master_domain . soa : <EOL> domain . soa = domain . master_domain . soa <EOL> domain . save ( ) <EOL> except ValidationError : <EOL> return render ( request , "<STR_LIT>" , { '<STR_LIT>' : <EOL> domain_form , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> messages . success ( request , "<STR_LIT>" . <EOL> format ( domain . name ) ) <EOL> return redirect ( domain ) <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> domain_form = DomainForm ( ) <EOL> return render ( request , "<STR_LIT>" , <EOL> { '<STR_LIT>' : domain_form , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class DomainUpdateView ( DomainView , UpdateView ) : <EOL> form_class = DomainUpdateForm <EOL> template_name = "<STR_LIT>" </s>
