Пример #1
0
def node_edit(request, id):
    node = get_object_or_404(Node, pk=id)
    if node.is_root_node():
        return HttpResponseBadRequest()
    NodeForm = form_factory(node.content_object.__class__)
    if request.POST:
        form = NodeForm(request.POST, initial={ 'name': node.name }, instance=node.content_object)
        if form.is_valid():
            obj = form.save()
            node.name = form.cleaned_data['name']
            node.save()
            messages.success(request, _(u'%s changed successfully' % obj))
            return redirect('meotec:settings')
    else:
        form = NodeForm(initial={ 'name': node.name }, instance=node.content_object)
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Node Edit'),
        'form': form,
    })
Пример #2
0
def node_add(request, id, class_path):
    Entity = get_class_by_path(class_path)
    parent = get_object_or_404(Node, pk=id)
    NodeForm = form_factory(Entity)
    if request.POST:
        form = NodeForm(request.POST)
        if form.is_valid():
            obj = form.save()
            Node(
                name=form.cleaned_data['name'],
                parent=parent,
                content_object=obj,
            ).save()
            messages.success(request, _(u'%s is added' % obj))
            return redirect('meotec:settings')
    else:
        form = NodeForm()
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Node Add'),
        'form': form,
    })
Пример #3
0
def node_add(request, id, class_path):
    Entity = get_class_by_path(class_path)
    parent = get_object_or_404(Node, pk=id)
    NodeForm = form_factory(Entity)
    if request.POST:
        form = NodeForm(request.POST)
        if form.is_valid():
            obj = form.save()
            Node(
                name=form.cleaned_data['name'],
                parent=parent,
                content_object=obj,
            ).save()
            messages.success(request, _(u'%s is added' % obj))
            return redirect('meotec:settings')
    else:
        form = NodeForm()
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Node Add'),
        'form': form,
    })
Пример #4
0
def node_edit(request, id):
    node = get_object_or_404(Node, pk=id)
    if node.is_root_node():
        return HttpResponseBadRequest()
    NodeForm = form_factory(node.content_object.__class__)
    if request.POST:
        form = NodeForm(request.POST,
                        initial={'name': node.name},
                        instance=node.content_object)
        if form.is_valid():
            obj = form.save()
            node.name = form.cleaned_data['name']
            node.save()
            messages.success(request, _(u'%s changed successfully' % obj))
            return redirect('meotec:settings')
    else:
        form = NodeForm(initial={'name': node.name},
                        instance=node.content_object)
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Node Edit'),
        'form': form,
    })