<s> from django . core . exceptions import ValidationError , ObjectDoesNotExist <EOL> from django . shortcuts import render_to_response <EOL> from django . shortcuts import get_object_or_404 , redirect , render <EOL> from django . forms . util import ErrorList , ErrorDict <EOL> from mozdns . nameserver . forms import NameserverForm <EOL> from mozdns . nameserver . forms import NSDelegated <EOL> from mozdns . nameserver . models import Nameserver <EOL> from mozdns . views import ( MozdnsDeleteView , MozdnsDetailView , MozdnsListView , <EOL> MozdnsCreateView , MozdnsUpdateView ) <EOL> from mozdns . address_record . models import AddressRecord <EOL> from mozdns . domain . models import Domain <EOL> from core . registration . static . models import StaticReg <EOL> class NSView ( object ) : <EOL> model = Nameserver <EOL> form_class = NameserverForm <EOL> queryset = Nameserver . objects . all ( ) <EOL> class NSDeleteView ( NSView , MozdnsDeleteView ) : <EOL> """<STR_LIT:U+0020>""" <EOL> class NSDetailView ( NSView , MozdnsDetailView ) : <EOL> template_name = "<STR_LIT>" <EOL> class NSListView ( NSView , MozdnsListView ) : <EOL> """<STR_LIT:U+0020>""" <EOL> template_name = "<STR_LIT>" <EOL> queryset = Nameserver . objects . all ( ) . select_related ( ) <EOL> class NSCreateView ( NSView , MozdnsCreateView ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def update_ns ( request , nameserver_pk ) : <EOL> nameserver = get_object_or_404 ( Nameserver , pk = nameserver_pk ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = NameserverForm ( request . POST , instance = nameserver ) <EOL> try : <EOL> if form . is_valid ( ) : <EOL> server = form . cleaned_data [ '<STR_LIT>' ] <EOL> domain = form . cleaned_data [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in form . cleaned_data : <EOL> glue_type , glue_pk = form . cleaned_data [ '<STR_LIT>' ] . split ( '<STR_LIT:_>' ) <EOL> try : <EOL> if glue_type == '<STR_LIT>' : <EOL> glue = AddressRecord . objects . get ( pk = glue_pk ) <EOL> elif glue_type == '<STR_LIT>' : <EOL> glue = StaticReg . objects . get ( pk = glue_pk ) <EOL> except ObjectDoesNotExist , e : <EOL> raise ValidationError ( "<STR_LIT>" + str ( e ) ) <EOL> nameserver . glue = glue <EOL> nameserver . server = server <EOL> nameserver . domain = domain <EOL> nameserver . clean ( ) <EOL> nameserver . save ( ) <EOL> except ValidationError , e : <EOL> form = Nameserver ( instance = nameserver ) <EOL> if form . _errors is None : <EOL> form . _errors = ErrorDict ( ) <EOL> form . _errors [ '<STR_LIT>' ] = ErrorList ( e . messages ) <EOL> return redirect ( nameserver ) <EOL> else : <EOL> form = NameserverForm ( instance = nameserver ) <EOL> return render ( request , "<STR_LIT>" , { <EOL> '<STR_LIT>' : form <EOL> } ) <EOL> class NSUpdateView ( NSView , MozdnsUpdateView ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def create_ns_delegated ( request , domain ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = NSDelegated ( request . POST ) <EOL> domain = Domain . objects . get ( pk = domain ) <EOL> if not domain : <EOL> pass <EOL> elif form . is_valid ( ) : <EOL> was_delegated = domain . delegated <EOL> if was_delegated : <EOL> domain . delegated = False <EOL> domain . save ( ) <EOL> if was_delegated : <EOL> domain . delegated = True <EOL> domain . save ( ) <EOL> else : <EOL> pass <EOL> form = NSDelegated ( ) <EOL> return render_to_response ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : form , '<STR_LIT>' : request } ) </s>
