コード例 #1
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def room_list():
    if isloggedin() == True:
        uf = userfactory.Userfactory()
        db = get_db()
        user = uf.getuser(db, session['currentuserid'])
        rf = roomfactory.RoomFactory()
        rooms = rf.get_rooms(db)
        return render_template('roomlist.html', user=user, rooms=rooms)
    else:
        error = 'Not authorised'
        return render_template('home.html', error=error)
コード例 #2
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def unlink(item, id1, id2):
    if isloggedin() == True:
        db = get_db()
        item = item.lower()
        rf = roomfactory.RoomFactory()

        if item == 'roomdevice':
            room = rf.get_room(db, id1)
            df = devicefactory.DeviceFactory()
            device = df.get_device(db, id2)
            room.remove_device(db, device)
            return edit('room', id1)

        else:
            error = 'Not authorised'
            return render_template('home.html', error=error)
コード例 #3
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def edit(item, id):
    if isloggedin() == True:
        db = get_db()
        uf = userfactory.Userfactory()
        user = uf.getuser(db, session['currentuserid'])
        item = item.lower()
        if item == 'room':
            rgf = roomgroupfactory.Roomgroupfactory()
            roomgroups = rgf.getroomgroups(db)
            rf = roomfactory.RoomFactory()
            room = rf.get_room(db, id)
            df = devicefactory.DeviceFactory()
            available_devices = df.get_available_devices(db, room)
            return render_template('addeditroom.html',
                                   user=user,
                                   roomgroups=roomgroups,
                                   room=room,
                                   available_devices=available_devices)
        elif item == 'roomgroup':
            pass
        elif item == 'device':
            dgf = devicegroupfactory.DeviceGroupFactory()
            devicegroups = dgf.get_devicegroups(db)
            df = devicefactory.DeviceFactory()
            device = df.get_device(db, id)
            return render_template('addeditdevice.html',
                                   user=user,
                                   devicegroups=devicegroups,
                                   device=device)
        elif item == 'user':
            edituser = uf.getuser(db, id)
            ugf = usergroupfactory.UserGroupFactory()
            usergroups = ugf.get_user_groups(db)
            return render_template('addedituser.html',
                                   user=user,
                                   edituser=edituser,
                                   usergroups=usergroups)
        elif item == 'devicegroup':
            dgf = devicegroupfactory.DeviceGroupFactory()
            devicegroup = dgf.get_devicegroup(db, id)
            return render_template('addeditdevicegroup.html',
                                   user=user,
                                   devicegroup=devicegroup)
    else:
        error = 'Not authorised'
        return render_template('home.html', error=error)
コード例 #4
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def save_room(db):
    if 'save' in request.form:
        roomname = request.form['name']
        roomgroups = []
        roomid = request.form['roomid']
        for f in request.form:
            if f.startswith('checkbox_'):
                roomgroupid = f.replace('checkbox_', '')
                roomgroups.append(int(roomgroupid))

        # need to check we have at least 1 room group here
        rf = roomfactory.RoomFactory()
        if roomid == '':
            rf.create_room(db, roomname, roomgroups)
        else:
            rf.update_room(db, roomid, roomname, roomgroups)

    return room_list()
コード例 #5
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def getroom():
    db = get_db()
    rf = roomfactory.RoomFactory()
    roomid = int(request.args.get('roomid'))
    roomdetails = rf.get_room(db, roomid)
    lin = None
    if 'currentuserid' in session:
        lin = session['currentuserid']
    else:
        lin = False

    if lin == True:
        uf = userfactory.Userfactory()
        db = get_db()
        user = uf.getuser(db, session['currentuserid'])
        return render_template('roomdetails.html', user=user, room=roomdetails)
    else:
        error = 'Not authorised'
    return render_template('home.html', error=error)
コード例 #6
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def show_home():
    # init_db()
    #init_defaultdata()
    #init_testdata()
    db = get_db()
    rf = roomfactory.RoomFactory()
    rooms = rf.get_rooms(db)
    lin = None
    if 'currentuserid' in session:
        lin = session['currentuserid']
    else:
        lin = False
    if lin == True:
        uf = userfactory.Userfactory()
        dgf = devicegroupfactory.DeviceGroupFactory()
        user = uf.getuser(db, session['currentuserid'])
        devicegroups = dgf.get_devicegroups(db)
        return render_template('home.html',
                               rooms=rooms,
                               user=user,
                               devicegroups=devicegroups)
    else:
        return render_template('welcome.html', user=None)
コード例 #7
0
ファイル: homecontrol.py プロジェクト: onzc/homecontrol
def delete(item, id):
    if isloggedin() == True:
        db = get_db()
        item = item.lower()
        if item == 'room':
            rf = roomfactory.RoomFactory()
            rf.delete_room(db, id)
            return room_list()
        elif item == 'roomgroup':
            pass
        elif item == 'device':
            df = devicefactory.DeviceFactory()
            df.delete(db, id)
            return device_list()
        elif item == 'user':
            return user_list()
        elif item == 'devicegroup':
            dgf = devicegroupfactory.DeviceGroupFactory()
            dgf.delete(db, id)
            return device_group_list()

    else:
        error = 'Not authorised'
        return render_template('home.html', error=error)