Esempio n. 1
0
def create(request):
    # Post request?
    if request.method == 'POST':
        # Load the form
        form = WorkerForm(request.POST)
        # Check if the form is valid.
        if form.is_valid():
            # Save the node and return to detail page.
            node = form.save()
            return redirect('workers_detail', worker_id=node.pk)
    else:
        form = WorkerForm()

    # Render template.
    return render_to_response('workers/create.html', {
        'form' : form,
    }, context_instance=RequestContext(request))
Esempio n. 2
0
def edit(request, worker_id):
    # Load the node.
    node = get_object_or_404(BuildNode, pk=worker_id)
    # Post request?
    if request.method == 'POST':
        # Load and validate form.
        form = WorkerForm(request.POST, instance=node)
        if form.is_valid():
            # Its valid, save and redirect.
            form.save()
            return redirect('workers_detail', worker_id=node.pk)
    else:
        # create a new form.
        form = WorkerForm(instance=node)

    # Render template.
    return render_to_response('workers/edit.html', {
        'object': node,
        'form': form,
    }, context_instance=RequestContext(request))