Пример #1
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 = 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_edit_url())
def keyvalue(request, obj_class, obj_pk):
    obj, KVKlass = resolve_obj(obj_class, obj_pk)
    if request.method == 'POST':
        process_kv(request.POST.items(), obj, KVKlass)
    attrs = obj.keyvalue_set.all()
    aa_options = get_aa(obj.keyvalue_set.model)
    docs = get_docstrings(KVKlass)
    return render(request, 'keyvalue/keyvalue.html', {
        'kv_class': obj_class,
        'obj_pk': obj.pk,
        'attrs': attrs,
        'object': obj,
        'aa_options': aa_options,
        'existing_keyvalue': attrs,
        'docs': docs,
    })
Пример #3
0
def keyvalue(request, obj_class, obj_pk):
    obj, KVKlass = resolve_obj(obj_class, obj_pk)
    if request.method == 'POST':
        process_kv(request.POST.items(), obj, KVKlass)
    attrs = obj.keyvalue_set.all()
    aa_options = get_aa(obj.keyvalue_set.model)
    docs = get_docstrings(KVKlass)
    return render(request, 'keyvalue/keyvalue.html', {
        'kv_class': obj_class,
        'obj_pk': obj.pk,
        'attrs': attrs,
        'object': obj,
        'aa_options': aa_options,
        'existing_keyvalue': attrs,
        'docs': docs,
    })
Пример #4
0
def keyvalue(request, obj_class, obj_pk):
    obj, KVKlass = resolve_obj(obj_class, obj_pk)
    if request.method == "POST":
        process_kv(request.POST.items(), obj, KVKlass)
    attrs = obj.keyvalue_set.all()
    aa_options = get_aa(obj.keyvalue_set.model)
    docs = get_docstrings(KVKlass)
    return render(
        request,
        "keyvalue/keyvalue.html",
        {
            "kv_class": obj_class,
            "obj_pk": obj.pk,
            "attrs": attrs,
            "object": obj,
            "aa_options": aa_options,
            "existing_keyvalue": attrs,
            "docs": docs,
        },
    )
Пример #5
0
def update_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    attrs = soa.keyvalue_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 = form.save()
                return redirect(soa.get_edit_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)
            })