예제 #1
0
파일: views.py 프로젝트: jdarknet/gconsumos
def alarmasEdita(request,pk):
    try:
        alarmas = Alarmas.objects.get( pk=pk)
    except Alarmas.DoesNotExist:
        raise Http404

    if 'envia_actualiza' in request.POST:
        form_cab            = AlarmasForms(request.POST,prefix="cabalarma",instance=alarmas)
        if form_cab.is_valid():
            cabecera            = form_cab.save(commit=False)
            form_detail         = MensajesFormsSet(request.POST,instance=cabecera,prefix="mensajes")
            if form_detail.is_valid():
                cabecera.save()
                form_detail.save()
                messages.error(request,"Se actualizo la alarma")
            else:
                messages.error(request, "%s " % form_detail.errors)
                print "%s " % form_detail.errors

        else:
            messages.error(request, "%s " % form_cab.errors.as_text)
            print "%s " % form_cab.errors.as_text

    elif 'envia_elimina' in request.POST:
        return redirect(reverse('alarmasDelete',kwargs = {'pk':pk}))
    elif 'envia_nuevo' in request.POST:
        return redirect(reverse('alarmasNuevo'))

    form_cab            = AlarmasForms(instance=alarmas,prefix="cabalarma")
    form_detail         = MensajesFormsSet(instance=alarmas,prefix="mensajes")
    formset_alarma      = Alarmas.objects.all()

    return render_to_response("web/secciones/panelcontrol/alarmas.html", {'listalarm' : formset_alarma,'form_cab' :form_cab , 'form_detail': form_detail},context_instance=RequestContext(request) )
예제 #2
0
파일: views.py 프로젝트: jdarknet/gconsumos
def alarmasNuevo(request):
    form_detail =""
    if 'envia_actualiza' in request.POST:
        form_cab            = AlarmasForms(request.POST,prefix="cabalarma")
        if form_cab.is_valid():
            cabecera            = form_cab.save(commit=False)
            form_detail         = MensajesFormsSet(request.POST,instance=cabecera,prefix="mensajes")
            if form_detail.is_valid():
                cabecera.save()
                form_detail.save()
                id = cabecera.id
                return redirect(reverse('alarmasEdita',kwargs = {'pk':id}))
            else:
                request.user.message_set.create(message = form_detail.errors)
        else:
            print form_cab.errors.as_text()
            form_detail         = MensajesFormsSet(prefix="mensajes")
    else:
        form_cab            = AlarmasForms(prefix="cabalarma")
        form_detail         = MensajesFormsSet(prefix="mensajes")

    formset_alarma =  Alarmas.objects.all()
    return render_to_response("web/secciones/panelcontrol/alarmas.html", {'listalarm' : formset_alarma,'form_cab' :form_cab , 'form_detail': form_detail },context_instance=RequestContext(request) )