Ejemplo n.º 1
0
def create_or_update_outofbandworker(request, worker_pk=None):
    """Create an OutOfBandWorker"""
    if request.method == 'POST':
        if worker_pk is None:
            new_obj = OutOfBandWorkerNodeForm(request.POST, request.FILES)
        else:
            worker_node = OutOfBandWorkerNode.objects.get(pk=worker_pk)
            new_obj = OutOfBandWorkerNodeForm(request.POST, request.FILES, 
                                              instance=worker_node)
        if new_obj.is_valid():
            worker = new_obj.save()
            if worker_pk is not None:
                json = simplejson.dumps("Worker successfully updated.")
            else:
                worker.active = worker.is_celeryd_running()
                context = { 'worker': {'worker': worker,
                            'workerForm': new_obj }}
                tpl = "celerymanagementapp/configure_outofbandworker_instance.html"
                html = render_to_response(tpl, context,
                                    context_instance=RequestContext(request))
                success = { 'success': 'Worker successfully created.',
                            'html': urlquote(html.content),
                            'pk': worker.pk }
                json = simplejson.dumps(success)
        else:
            errors = []
            for field in new_obj:
                errors.append({ 'field' : field.html_name,
                                'error' : field.errors })
            failed = { 'failure' : errors,
                        'id': worker_pk }
            json = simplejson.dumps(failed)
        return HttpResponse("<textarea>" + json + "</textarea>")
Ejemplo n.º 2
0
def create_or_update_outofbandworker(request, worker_pk=None):
    if request.method == "POST":
        if worker_pk is None:
            out_of_band_worker_node_form = OutOfBandWorkerNodeForm(request.POST, request.FILES)
        else:
            worker = OutOfBandWorkerNode()
            out_of_band_worker_node_form = OutOfBandWorkerNodeForm(request.POST, request.FILES, instance=worker)

        if out_of_band_worker_node_form.is_valid():
            if worker_pk is not None:
                json = simplejson.dumps("Worker successfully updated.")
            else:
                worker = out_of_band_worker_node_form.save(commit=False)
                worker.pk = 120
                worker.active = True
                context = { 'worker': {'worker': worker,
                            'workerForm': out_of_band_worker_node_form }}
                html = render_to_response("celerymanagementapp/configure_outofbandworker_instance.html",
                        context,
                        context_instance=RequestContext(request))
                success = { 'success': 'Worker successfully created.',
                            'html': urlquote(html.content),
                            'pk': worker.pk }
                json = simplejson.dumps(success)
        else:
            errors = []
            for field in out_of_band_worker_node_form:
                errors.append({ 'field' : field.html_name,
                                'error' : field.errors })
            failed = { 'failure' : errors,
                        'id': worker_pk }
            json = simplejson.dumps(failed)
        
        return HttpResponse("<textarea>" + json + "</textarea>")