Esempio n. 1
0
def update_vlan(request, vlan_pk):
    vlan = get_object_or_404(Vlan, pk=vlan_pk)
    attrs = vlan.vlankeyvalue_set.all()
    aux_attrs = VlanKeyValue.aux_attrs
    if request.method == "POST":
        form = VlanForm(request.POST, instance=vlan)
        if form.is_valid():
            try:
                # Handle KV store.
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, VlanKeyValue, vlan, "vlan")

                vlan = form.save()
                vlan.save()
                return redirect(vlan)
            except ValidationError, e:
                if form._errors is None:
                    form._errors = ErrorDict()
                form._errors["__all__"] = ErrorList(e.messages)
                return render(
                    request, "vlan/vlan_edit.html", {
                        "vlan": vlan,
                        "form": form,
                        "attrs": attrs,
                        "aux_attrs": aux_attrs
                    })
Esempio n. 2
0
def update_network(request, network_pk):
    network = get_object_or_404(Network, pk=network_pk)
    attrs = network.networkkeyvalue_set.all()
    docs = get_dhcp_docstrings(NetworkKeyValue())
    aa = get_dhcp_aa(NetworkKeyValue())
    if request.method == "POST":
        form = NetworkForm(request.POST, instance=network)
        try:
            if not form.is_valid():
                return render(
                    request,
                    "network/network_edit.html",
                    {"network": network, "form": form, "attrs": attrs, "docs": docs, "aa": json.dumps(aa)},
                )
            else:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, NetworkKeyValue, network, "network")
                network = form.save()
                return redirect(network.get_update_url())
        except ValidationError, e:
            if form._errors is None:
                form._errors = ErrorDict()
            form._errors["__all__"] = ErrorList(e.messages)
            if kv:
                attrs = dict_to_kv(kv, NetworkKeyValue)
            return render(
                request,
                "network/network_edit.html",
                {"network": network, "form": form, "attrs": attrs, "docs": docs, "aa": json.dumps(aa)},
            )
Esempio n. 3
0
def update_vlan(request, vlan_pk):
    vlan = get_object_or_404(Vlan, pk=vlan_pk)
    attrs = vlan.vlankeyvalue_set.all()
    aux_attrs = VlanKeyValue.aux_attrs
    if request.method == "POST":
        form = VlanForm(request.POST, instance=vlan)
        if form.is_valid():
            try:
                # Handle KV store.
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, VlanKeyValue, vlan, "vlan")

                vlan = form.save()
                vlan.save()
                return redirect(vlan)
            except ValidationError, e:
                if form._errors is None:
                    form._errors = ErrorDict()
                form._errors["__all__"] = ErrorList(e.messages)
                return render(request, "vlan/vlan_edit.html", {
                    "vlan": vlan,
                    "form": form,
                    "attrs": attrs,
                    "aux_attrs": aux_attrs
                })
Esempio n. 4
0
def edit_static_interface(request, intr_pk):
    # TODO, make sure the user has access to this system
    intr = get_object_or_404(StaticInterface, pk=intr_pk)
    system = intr.system
    attrs = intr.staticintrkeyvalue_set.all()
    aa = get_aa(StaticIntrKeyValue())
    docs = get_docstrings(StaticIntrKeyValue())
    if request.method == 'POST':
        interface_form = StaticInterfaceForm(request.POST, instance=intr)
        if interface_form.is_valid():
            try:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, StaticIntrKeyValue, intr, 'intr')
                intr = interface_form.save()

                # Everything checks out. Clean and Save all the objects.
                intr.clean()
                intr.save()
            except ValidationError, e:
                interface_form._errors['__all__'] = ErrorList(e.messages)
                if kv:
                    attrs = dict_to_kv(kv, StaticIntrKeyValue)
                return render(
                    request, 'static_intr/static_intr_edit.html', {
                        'form':
                        interface_form,
                        'intr':
                        intr,
                        'attrs':
                        attrs,
                        'aa':
                        json.dumps(aa),
                        'docs':
                        docs,
                        'form_title':
                        'Edit Interface for System {0}'.format(system),
                        'domain':
                        intr.domain
                    })
        else:
            return render(
                request, 'static_intr/static_intr_edit.html', {
                    'form': interface_form,
                    'intr': intr,
                    'attrs': attrs,
                    'aa': json.dumps(aa),
                    'docs': docs,
                    'form_title':
                    'Edit Interface for System {0}'.format(system),
                    'domain': intr.domain
                })

        messages.success(request, "Success! Interface Updated.")
        return redirect(intr.get_update_url())
Esempio n. 5
0
def edit_static_interface(request, intr_pk):
    # TODO, make sure the user has access to this system
    intr = get_object_or_404(StaticInterface, pk=intr_pk)
    system = intr.system
    attrs = intr.staticintrkeyvalue_set.all()
    aa = get_aa(StaticIntrKeyValue())
    docs = get_docstrings(StaticIntrKeyValue())
    if request.method == 'POST':
        interface_form = StaticInterfaceForm(request.POST, instance=intr)
        if interface_form.is_valid():
            try:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, StaticIntrKeyValue, intr, 'intr')
                intr = interface_form.save()

                # Everything checks out. Clean and Save all the objects.
                intr.clean()
                intr.save()
            except ValidationError, e:
                interface_form._errors['__all__'] = ErrorList(e.messages)
                if kv:
                    attrs = dict_to_kv(kv, StaticIntrKeyValue)
                return render(request, 'static_intr/static_intr_edit.html', {
                    'form': interface_form,
                    'intr': intr,
                    'attrs': attrs,
                    'aa': json.dumps(aa),
                    'docs': docs,
                    'form_title': 'Edit Interface for System {0}'.format(
                        system),
                    'domain': intr.domain
                })
        else:
            return render(request, 'static_intr/static_intr_edit.html', {
                'form': interface_form,
                'intr': intr,
                'attrs': attrs,
                'aa': json.dumps(aa),
                'docs': docs,
                'form_title': 'Edit Interface for System {0}'.format(
                    system),
                'domain': intr.domain
            })

        messages.success(request, "Success! Interface Updated.")
        return redirect(intr.get_update_url())
Esempio n. 6
0
def update_range(request, range_pk):
    mrange = get_object_or_404(Range, pk=range_pk)
    attrs = mrange.rangekeyvalue_set.all()
    docs = get_docstrings(RangeKeyValue())
    aa = get_aa(RangeKeyValue())
    if request.method == 'POST':
        form = RangeForm(request.POST, instance=mrange)
        try:
            if not form.is_valid():
                if form._errors is None:
                    form._errors = ErrorDict()
                form._errors['__all__'] = ErrorList(e.messages)
                return render(request, 'range/range_edit.html', {
                    'range': mrange,
                    'form': form,
                    'attrs': attrs,
                    'docs': docs,
                    'aa': json.dumps(aa)
                })
            else:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, RangeKeyValue, mrange, 'range')
                mrange = form.save()
                return redirect(mrange.get_update_url())
        except ValidationError, e:
            if form._errors is None:
                form._errors = ErrorDict()
            if kv:
                attrs = dict_to_kv(kv, RangeKeyValue)
            form._errors['__all__'] = ErrorList(e.messages)
            return render(request, 'range/range_edit.html', {
                'range': mrange,
                'form': form,
                'attrs': attrs,
                'docs': docs,
                'aa': json.dumps(aa)
            })
Esempio n. 7
0
def update_network(request, network_pk):
    network = get_object_or_404(Network, pk=network_pk)
    attrs = network.networkkeyvalue_set.all()
    docs = get_dhcp_docstrings(NetworkKeyValue())
    aa = get_dhcp_aa(NetworkKeyValue())
    if request.method == 'POST':
        form = NetworkForm(request.POST, instance=network)
        try:
            if not form.is_valid():
                return render(
                    request, 'network/network_edit.html', {
                        'network': network,
                        'form': form,
                        'attrs': attrs,
                        'docs': docs,
                        'aa': json.dumps(aa)
                    })
            else:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, NetworkKeyValue, network, 'network')
                network = form.save()
                return redirect(network.get_update_url())
        except ValidationError, e:
            if form._errors is None:
                form._errors = ErrorDict()
            form._errors['__all__'] = ErrorList(e.messages)
            if kv:
                attrs = dict_to_kv(kv, NetworkKeyValue)
            return render(
                request, 'network/network_edit.html', {
                    'network': network,
                    'form': form,
                    'attrs': attrs,
                    'docs': docs,
                    'aa': json.dumps(aa)
                })
Esempio n. 8
0
def update_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    attrs = soa.soakeyvalue_set.all()
    docs = get_docstrings(SOAKeyValue())
    aa = get_aa(SOAKeyValue())
    if request.method == 'POST':
        form = SOAForm(request.POST, instance=soa)
        try:
            if not form.is_valid():
                return render(
                    request, 'soa/soa_edit.html', {
                        'soa': soa,
                        'form': form,
                        'attrs': attrs,
                        'docs': docs,
                        'aa': json.dumps(aa)
                    })
            else:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, SOAKeyValue, soa, 'soa')
                soa = form.save()
                return redirect(soa.get_update_url())
        except ValidationError, e:
            if form._errors is None:
                form._errors = ErrorDict()
            form._errors['__all__'] = ErrorList(e.messages)
            if kv:
                attrs = dict_to_kv(kv, SOAKeyValue)
            return render(
                request, 'soa/soa_edit.html', {
                    'soa': soa,
                    'form': form,
                    'attrs': attrs,
                    'docs': docs,
                    'aa': json.dumps(aa)
                })
Esempio n. 9
0
def update_site(request, site_pk):
    site = get_object_or_404(Site, pk=site_pk)
    attrs = site.sitekeyvalue_set.all()
    aux_attrs = SiteKeyValue.aux_attrs
    if request.method == "POST":
        form = SiteForm(request.POST, instance=site)
        try:
            if form.is_valid():
                # Handle KV store.
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, SiteKeyValue, site, "site")
                site = form.save()

            return redirect(site)
        except ValidationError, e:
            if form._errors is None:
                form._errors = ErrorDict()
            form._errors["__all__"] = ErrorList(e.messages)
            return render(request, "site/site_edit.html", {
                "site": site,
                "form": form,
                "attrs": attrs,
                "aux_attrs": aux_attrs
            })
Esempio n. 10
0
def update_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    attrs = soa.soakeyvalue_set.all()
    docs = get_docstrings(SOAKeyValue())
    aa = get_aa(SOAKeyValue())
    if request.method == 'POST':
        form = SOAForm(request.POST, instance=soa)
        try:
            if not form.is_valid():
                return render(request, 'soa/soa_edit.html', {
                    'soa': soa,
                    'form': form,
                    'attrs': attrs,
                    'docs': docs,
                    'aa': json.dumps(aa)
                })
            else:
                # Handle key value stuff.
                kv = None
                kv = get_attrs(request.POST)
                update_attrs(kv, attrs, SOAKeyValue, soa, 'soa')
                soa = form.save()
                return redirect(soa.get_update_url())
        except ValidationError, e:
            if form._errors is None:
                form._errors = ErrorDict()
            form._errors['__all__'] = ErrorList(e.messages)
            if kv:
                attrs = dict_to_kv(kv, SOAKeyValue)
            return render(request, 'soa/soa_edit.html', {
                'soa': soa,
                'form': form,
                'attrs': attrs,
                'docs': docs,
                'aa': json.dumps(aa)
            })