예제 #1
0
파일: views.py 프로젝트: Coderhypo/TDMS
def upredev():

    device = Devices.query.filter_by(device_id=request.args.get('deviceid')).first()

    if request.method == 'POST':
        doer = current_user
        lendlog = LendLog()
        lendlog.setDoer(doer.user_id)
        lendlog.returnDevice(device.lend_log_id)

        device.lend_log_id = -1
        device.device_status = request.form['status']

        log = Log()
        log.setUser(doer.user_id)
        log.setType('RETURN')
        log.setDevice(device.device_id)
        log.setContent('RETURN DEVICE ' + str(device.device_id))
        log.info()

        db.session.add(device)
        db.session.commit()

        return redirect(url_for('reDevices'))

    deviceinfo = {'id': device.device_id, 'name': device.device_name}

    return render_template('/admin/devices/updatedevice.html', device=deviceinfo)
예제 #2
0
파일: views.py 프로젝트: Coderhypo/TDMS
def lend():
    """设备借出页面"""
    doer = current_user
    if request.method == 'GET':

        if request.args.get('login') and request.args.get('deviceid'):

            login = request.args.get('login')
            deviceid = request.args.get('deviceid')
            device = Devices.query.filter_by(device_id=deviceid).first()

            if device is None:
                pass
            elif len(login) > 0 and len(deviceid) > 0 and device.lend_log_id == -1:
                user = Users.query.filter_by(user_login=login).first()

                if user is not None:
                    lendlog = LendLog()
                    lendlog.setDevice(deviceid)
                    lendlog.setLender(user.user_id)
                    lendlog.setDoer(doer.user_id)
                    lendlog.setSchool(doer.school_id)
                    logid = lendlog.lendDevice()
                    device.lend_log_id = logid

                    log = Log()
                    log.setUser(doer.user_id)
                    log.setDevice(deviceid)
                    log.setType('LEND')
                    log.setContent('LEND DEVICE ' + deviceid)
                    log.info()

                    db.session.add(device)
                    db.session.commit()

    ulist = []
    users = Users.query.filter_by(school_id=doer.school_id).all()
    if doer.school_id == 1:
        users = Users.query.all()

    for user in users:
        tmp = {'id': user.user_id, 'login': user.user_login, 'name': user.user_name, 'phone': user.user_phone}
        ulist.append(tmp)

    dlist = []
    devices = Devices.query.filter_by(lend_log_id=-1, school_id=doer.school_id, device_status=0).all()
    if doer.school_id == 1:
        devices = Devices.query.filter_by(lend_log_id=-1, device_status=0).all()

    for device in devices:
        tmp = {'id': device.device_id, 'name': device.device_name}
        dlist.append(tmp)

    return render_template('/admin/devices/lenddevice.html', users=ulist, devices=dlist)
예제 #3
0
def upredev():

    device = Devices.query.filter_by(
        device_id=request.args.get('deviceid')).first()

    if request.method == 'POST':
        doer = current_user
        lendlog = LendLog()
        lendlog.setDoer(doer.user_id)
        lendlog.returnDevice(device.lend_log_id)

        device.lend_log_id = -1
        device.device_status = request.form['status']

        log = Log()
        log.setUser(doer.user_id)
        log.setType('RETURN')
        log.setDevice(device.device_id)
        log.setContent('RETURN DEVICE ' + str(device.device_id))
        log.info()

        db.session.add(device)
        db.session.commit()

        return redirect(url_for('reDevices'))

    deviceinfo = {'id': device.device_id, 'name': device.device_name}

    return render_template('/admin/devices/updatedevice.html',
                           device=deviceinfo)
예제 #4
0
def lend():
    """设备借出页面"""
    doer = current_user
    if request.method == 'GET':

        if request.args.get('login') and request.args.get('deviceid'):

            login = request.args.get('login')
            deviceid = request.args.get('deviceid')
            device = Devices.query.filter_by(device_id=deviceid).first()

            if device is None:
                pass
            elif len(login) > 0 and len(
                    deviceid) > 0 and device.lend_log_id == -1:
                user = Users.query.filter_by(user_login=login).first()

                if user is not None:
                    lendlog = LendLog()
                    lendlog.setDevice(deviceid)
                    lendlog.setLender(user.user_id)
                    lendlog.setDoer(doer.user_id)
                    lendlog.setSchool(doer.school_id)
                    logid = lendlog.lendDevice()
                    device.lend_log_id = logid

                    log = Log()
                    log.setUser(doer.user_id)
                    log.setDevice(deviceid)
                    log.setType('LEND')
                    log.setContent('LEND DEVICE ' + deviceid)
                    log.info()

                    db.session.add(device)
                    db.session.commit()

    ulist = []
    users = Users.query.filter_by(school_id=doer.school_id).all()
    if doer.school_id == 1:
        users = Users.query.all()

    for user in users:
        tmp = {
            'id': user.user_id,
            'login': user.user_login,
            'name': user.user_name,
            'phone': user.user_phone
        }
        ulist.append(tmp)

    dlist = []
    devices = Devices.query.filter_by(lend_log_id=-1,
                                      school_id=doer.school_id,
                                      device_status=0).all()
    if doer.school_id == 1:
        devices = Devices.query.filter_by(lend_log_id=-1,
                                          device_status=0).all()

    for device in devices:
        tmp = {'id': device.device_id, 'name': device.device_name}
        dlist.append(tmp)

    return render_template('/admin/devices/lenddevice.html',
                           users=ulist,
                           devices=dlist)