示例#1
0
def show_devices():
    entries = [
        dict(did=device.deviceid,
             dname=device.devicename,
             ddescr=device.description,
             dver=device.version) for device in Devices.select()
    ]
    return render_template('show_devices.html', entries=entries)
示例#2
0
def list_devicerules():
    # select device
    devices = [
        dict(did=device.deviceid, dname=device.devicename)
        for device in Devices.select()
    ]
    # select token
    tokens = [
        dict(tid=each.tokenid, tname=each.token) for each in Tokens.select()
    ]
    return render_template('list_devicerules.html', entries=[devices, tokens])
示例#3
0
def edit_devices():
    error = None

    if request.method == 'POST':
        # check if this is remove vs update POST request
        action = request.form.getlist('action')
        if action[0] == 'remove':
            # read in the content of a present click
            list_value = request.form.getlist('id')
            # if list is not empty - content has gone through
            if len(list_value) > 0:
                value = int(list_value[0])
                # find device and rules associated with it
                device = Devices.get(Devices.deviceid == value)
                # recursively - delete all dependencies incl. nullable
                device.delete_instance(recursive=True, delete_nullable=True)

        elif action[0] == 'update':
            # read in the content of a present click
            list_id_value = request.form.getlist('id')
            print list_id_value
            # if list is not empty - content has gone through
            if len(list_id_value) > 0:
                id_value = int(list_id_value[0])
                print "value is", id_value
                # find device and rules associated with it
                device = Devices.get(Devices.deviceid == id_value)
                list_name_value = request.form.getlist('name')
                list_descr_value = request.form.getlist('descr')
                list_ver_value = request.form.getlist('ver')
                if list_name_value[0] != '':
                    if list_name_value[0] != device.devicename:
                        device.devicename = list_name_value[0]
                    elif list_descr_value[0] != device.description:
                        device.description = list_descr_value[0]
                    elif list_ver_value[0] != device.version:
                        device.version = list_ver_value[0]
                    device.save()
                else:
                    error = 'Name cannot be empty'

    else:
        # list devices
        entries = [
            dict(did=device.deviceid,
                 dname=device.devicename,
                 ddescr=device.description,
                 dver=device.version) for device in Devices.select()
        ]
        return render_template('edit_devices.html',
                               error=error,
                               entries=entries)
def show_devices():
    entries = [dict(did=device.deviceid, dname=device.devicename, ddescr=device.description, dver=device.version) for device in Devices.select()]
    return render_template('show_devices.html', entries=entries)
def list_devicerules():
    # select device
    devices = [dict(did=device.deviceid, dname=device.devicename) for device in Devices.select()]
    # select token
    tokens = [dict(tid=each.tokenid, tname=each.token) for each in Tokens.select()]
    return render_template('list_devicerules.html', entries=[devices, tokens])
def edit_devices():
    error = None
    
    if request.method == 'POST':
        # check if this is remove vs update POST request
        action = request.form.getlist('action')
        if action[0] == 'remove':
            # read in the content of a present click
            list_value = request.form.getlist('id')
            # if list is not empty - content has gone through
            if len(list_value) > 0:
                value = int(list_value[0])
                # find device and rules associated with it
                device = Devices.get(Devices.deviceid == value)
                # recursively - delete all dependencies incl. nullable
                device.delete_instance(recursive=True,delete_nullable=True)

        elif action[0] == 'update':
            # read in the content of a present click
            list_id_value = request.form.getlist('id')
            print list_id_value
            # if list is not empty - content has gone through
            if len(list_id_value) > 0:
                id_value = int(list_id_value[0])
                print "value is", id_value
                # find device and rules associated with it
                device = Devices.get(Devices.deviceid == id_value)
                list_name_value = request.form.getlist('name')
                list_descr_value = request.form.getlist('descr')
                list_ver_value = request.form.getlist('ver')
                if list_name_value[0] != '':
                    if list_name_value[0] != device.devicename:
                        device.devicename = list_name_value[0]
                    elif list_descr_value[0] != device.description:
                        device.description = list_descr_value[0]
                    elif list_ver_value[0] != device.version:
                        device.version = list_ver_value[0]
                    device.save()
                else:
                    error = 'Name cannot be empty'
    
    else:
        # list devices
        entries = [dict(did=device.deviceid, dname=device.devicename, ddescr=device.description, dver=device.version) for device in Devices.select()]
        return render_template('edit_devices.html', error=error, entries=entries)