def update_ns(request, nameserver_pk):
    nameserver = get_object_or_404(Nameserver, pk=nameserver_pk)
    if request.method == "POST":
        form = NameserverForm(request.POST, instance=nameserver)
        try:
            if form.is_valid():
                server = form.cleaned_data['server']
                domain = form.cleaned_data['domain']
                if 'glue' in form.cleaned_data:
                    glue_type, glue_pk = form.cleaned_data['glue'].split('_')
                    try:
                        if glue_type == 'addr':
                            glue = AddressRecord.objects.get(pk=glue_pk)
                        elif glue_type == 'sreg':
                            glue = StaticReg.objects.get(pk=glue_pk)
                    except ObjectDoesNotExist, e:
                        raise ValidationError("Couldn't find glue: " + str(e))
                    nameserver.glue = glue
                nameserver.server = server
                nameserver.domain = domain
                nameserver.clean()
                nameserver.save()
        except ValidationError, e:
            form = Nameserver(instance=nameserver)
            if form._errors is None:
                form._errors = ErrorDict()
            form._errors['__all__'] = ErrorList(e.messages)

        return redirect(nameserver)
    else:
        form = NameserverForm(instance=nameserver)
    return render(request, "mozdns/mozdns_form.html", {
        'form': form
    })
dataset/ETHPy150Open mozilla/inventory/mozdns/nameserver/views.py/update_ns/original