Ejemplo n.º 1
0
def sensor_new(request):
    af = SensorForm()    
    if request.method == "POST":
        af = SensorForm(request.POST)
        af.instance.Device = Device.objects.get(id=request.session['Device.id'])
        if af.is_valid():
            af.save()
            return render_to_response('device/setup.sensor_new.html', {'request':request,
                                                                                 'form':af,
                                                                                'saved':True})    
    try:
        af
    except:
        af = SensorForm()
        
    return render_to_response('device/setup.sensor_new.html', {'request':request,
                                                                         'form':af,
                                                                         'saved':False})
Ejemplo n.º 2
0
def sensor_edit(request, sensor_id):
    app = Sensor.objects.get(id=sensor_id)
    if app.Device.id != request.session['Device.id']:
        return redirect('/manage/pick/')
    af = SensorForm(instance=app)    
    if request.method == "POST":
        af = SensorForm(request.POST, instance=app)
        if af.is_valid():
            af.save()
            return render_to_response('device/setup.sensor_edit.html', {'request':request,
                                                                                 'form':af,
                                                                                'saved':True})    
    try:
        af
    except:
        af = SensorForm()
        
    return render_to_response('device/setup.sensor_edit.html', {'request':request,
                                                                         'form':af,
                                                                         'saved':False})
Ejemplo n.º 3
0
def sensor_new(request):
    af = SensorForm()
    if request.method == "POST":
        af = SensorForm(request.POST)
        af.instance.Device = Device.objects.get(
            id=request.session['Device.id'])
        if af.is_valid():
            af.save()
            return render_to_response('device/setup.sensor_new.html', {
                'request': request,
                'form': af,
                'saved': True
            })
    try:
        af
    except:
        af = SensorForm()

    return render_to_response('device/setup.sensor_new.html', {
        'request': request,
        'form': af,
        'saved': False
    })
Ejemplo n.º 4
0
def sensor_edit(request, sensor_id):
    app = Sensor.objects.get(id=sensor_id)
    if app.Device.id != request.session['Device.id']:
        return redirect('/manage/pick/')
    af = SensorForm(instance=app)
    if request.method == "POST":
        af = SensorForm(request.POST, instance=app)
        if af.is_valid():
            af.save()
            return render_to_response('device/setup.sensor_edit.html', {
                'request': request,
                'form': af,
                'saved': True
            })
    try:
        af
    except:
        af = SensorForm()

    return render_to_response('device/setup.sensor_edit.html', {
        'request': request,
        'form': af,
        'saved': False
    })