# Path: journeyman/workers/models.py
# class BuildNode(models.Model):
#     name = models.CharField(max_length=255)
#     active = models.BooleanField(default=True)
# 
#     host = models.CharField(max_length=255)
#     username = models.CharField(max_length=255)
#     ssh_key = models.TextField()
# 
#     def __unicode__(self):
#         return '%s (%s)' % (self.name, self.host)
# 
# Path: journeyman/workers/forms.py
# class WorkerForm(forms.ModelForm):
#     class Meta:
#         model = BuildNode


from django.shortcuts import redirect, render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from journeyman.workers.models import BuildNode
from journeyman.workers.forms import WorkerForm
        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))

def list(request):
    return redirect('projects_list')

# Protect the detail page because of plain visible ssh private keys.
@login_required
def detail(request, worker_id=None):
    # Get the node.
    node = get_object_or_404(BuildNode, pk=worker_id)

    # Return info page.
    return render_to_response('workers/detail.html', {
        'object': node,
    }, context_instance=RequestContext(request))

def delete(request, worker_id):
    # Load the node and remove.

# Path: journeyman/workers/models.py
# class BuildNode(models.Model):
#     name = models.CharField(max_length=255)
#     active = models.BooleanField(default=True)
# 
#     host = models.CharField(max_length=255)
#     username = models.CharField(max_length=255)
#     ssh_key = models.TextField()
# 
#     def __unicode__(self):
#         return '%s (%s)' % (self.name, self.host)
# 
# Path: journeyman/workers/forms.py
# class WorkerForm(forms.ModelForm):
#     class Meta:
#         model = BuildNode


# Path: journeyman/workers/views.py
from django.shortcuts import redirect, render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from journeyman.workers.models import BuildNode
from journeyman.workers.forms import WorkerForm

        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))

def list(request):
    return redirect('projects_list')

# Protect the detail page because of plain visible ssh private keys.
@login_required
def detail(request, worker_id=None):
    # Get the node.
    node = get_object_or_404(BuildNode, pk=worker_id)

    # Return info page.
    return render_to_response('workers/detail.html', {
        'object': node,
    }, context_instance=RequestContext(request))

def delete(request, worker_id):
    # Load the node and remove.

    node = get_object_or_404(BuildNode, pk=worker_id)