def edit_component(request, component):
    component = get_object_or_404(Component, pk=component,\
                                  system__center__user=request.user)

    if request.method == 'POST':
        form = ComponentForm(request.POST, instance=component)
        if form.is_valid():
            component = form.save()
            return redirect('show_component', component=component.pk)
    else:
        form = ComponentForm(instance=component)
    return render_to_response('supercomputer/edit_component.html', locals(),\
                              context_instance=RequestContext(request))
def add_component(request, system):
    system = get_object_or_404(System, pk=system, center__user=request.user)

    if request.method == 'POST':
        form = ComponentForm(request.POST)
        if form.is_valid():
            component = form.save(commit=False)
            component.system = system
            component.save()
            return redirect('show_component', component=component.pk)
    else:
        form = ComponentForm()
    return render_to_response('supercomputer/add_component.html', locals(),\
                              context_instance=RequestContext(request))