Example #1
0
def deployment(req, slug=''):
    if req.method == 'GET':
        p = _createParams(req)
        deployment = get_object_or_404(Deployment, slug=slug)
        p['form'] = AssociateDeploymentForm(instance=deployment)
        p['slug'] = deployment.slug
        return render_to_response(TEMPLATE_PATH + 'associate.html', p, 
            context_instance=RequestContext(req))
    elif req.method == 'POST':
        deployment = get_object_or_404(Deployment, slug=slug)
        # check user permissions
        if deployment.owner == req.user:
            form = AssociateDeploymentForm(req.POST)
            if form.is_valid():
                _save_associate_deployment(form, deployment)
                messages.add_message(req, messages.INFO, 
                    'Deployment "%s" successfully updated.' % deployment.name)
                return HttpResponseRedirect(reverse('deployments'))
            else:
                return render_to_response(TEMPLATE_PATH + 'associate.html',
                    p, context_instance=RequestContext(req))
                
        else:
            messages.add_message(req, messages.INFO, 
                'You must be the owner of a deployment to edit it.')
            return HttpResponseRedirect(reverse('deployments'))
Example #2
0
def associate_deployment(req):
    p = _createParams(req)
    if req.method == 'GET':
        p['form'] = AssociateDeploymentForm()
        return render_to_response(TEMPLATE_PATH + 'associate.html', p, 
            context_instance=RequestContext(req))
    elif req.method == 'POST':
        form = AssociateDeploymentForm(req.POST)
        if form.is_valid():
            d = Deployment()
            d.owner = req.user
            _save_associate_deployment(form, d)
            messages.add_message(req, messages.INFO, 
                '%s successfully associated with %s.' % (d.project,
                d.provider))
            return HttpResponseRedirect(reverse('deployments'))
        else:
            p['form'] = form
            return render_to_response(TEMPLATE_PATH + 'associate.html', p, 
                context_instance=RequestContext(req))