Пример #1
0
def get_idc_name():
    _sql = 'select idc_id,idc_name from idc_name'
    rt = []
    _cnt, _rt_list = excute_fetch_sql(_sql)
    for i in _rt_list:
        rt.append(i)
    return rt
Пример #2
0
def get_user():
    colloens = ('username', 'password', 'age', 'telphone', 'email')
    _sql = 'select username,password,age,telphone,email from user'
    rt = []
    sql_count, rt_list = excute_fetch_sql(_sql)
    for i in rt_list:
        rt.append(dict(zip(colloens, i)))
    return rt
Пример #3
0
def get_user():
    colloens = ('username','password','age','telphone','email')
    _sql = 'select username,password,age,telphone,email from user'
    rt = []
    sql_count,rt_list = excute_fetch_sql(_sql)
    for i in rt_list:
        rt.append(dict(zip(colloens,i)))
    return rt
Пример #4
0
def get_list():
    _column = 'id,sn,ip,hostname,os,cpu,ram,disk,idc_name,admin,business,purchase_date,warranty,vendor,model,status'
    _columns = _column.split(',')
    _sql = 'select {column} from assets,idc_name where assets.status=0 and assets.idc_id = idc_name.idc_id;'.format(
        column=_column)
    # _sql = 'select {column} from assets where status=0'.format(column=_column)
    _cnt, _rt_list = excute_fetch_sql(_sql)
    rt_list = [dict(zip(_columns, i)) for i in _rt_list]
    return [dict(zip(_columns, i)) for i in _rt_list]
Пример #5
0
def validate_create(params):
    collent = params.keys()
    result = {}
    for i in collent:
        if params[i] == '':
            result[i] = '%s 不能为空' % i
    #检查SN的唯一
    sn = params.get('sn').strip()
    if len(sn) >= 6:
        _sql = 'select * from assets where sn = %s and status = 0'
        _args = (sn, )
        _cnt, rt_list = excute_fetch_sql(_sql, _args)
        if _cnt != 0:
            result['sn'] = 'SN编码已存在'
    else:
        result['sn'] = 'SN编码太短'

    #检查IP的唯一
    ip = params.get('ip').strip()
    if ip_check(ip):
        _sql = 'select * from assets where ip = %s and status = 0'
        _args = (ip, )
        _cnt, rt_list = excute_fetch_sql(_sql, _args)
        if _cnt != 0:
            result['ip'] = 'IP地址已存在'
    else:
        result['ip'] = 'IP地址不合法'

    #检查主机名的唯一
    hostname = params.get('hostname').strip()
    _sql = 'select * from assets where hostname = %s and status = 0'
    _args = (hostname, )
    _cnt, rt_list = excute_fetch_sql(_sql, _args)
    if _cnt != 0:
        result['hostname'] = '主机名已存在'

    if not result:
        return create(params)
    return False, result.values()
Пример #6
0
def get_by_id(aid):
    _column = 'id,sn,ip,hostname,os,cpu,ram,disk,idc_id,admin,business,purchase_date,warranty,vendor,model,status'
    # _sql = 'select {coll} from assets,idc_name where assets.status=0 and assets.idc_id = idc_name.idc_id and id = %s'.format(coll=_column)
    _sql = 'select {coll} from assets where id = %s'.format(coll=_column)
    _args = (aid, )
    _cnt, _rt_list = excute_fetch_sql(_sql, _args)
    rt = []
    if _cnt != 0:
        for x in range(len(_column.split(','))):
            # print _column.split(',')[x],_rt_list[0][x]
            rt.append((_column.split(',')[x], _rt_list[0][x]))
        return dict(rt)
    return ''
Пример #7
0
def user_add(params):
    username = params.get('username')
    password = params.get('password')
    age = params.get('age')
    telphone = params.get('telphone')
    email = params.get('email')
    _sql_select = 'select * from user where username = %s'
    _sql_insert = 'insert into user(username,password,age,telphone,email) values(%s,md5(%s),%s,%s,%s)'
    agrs1 = (username, )
    _sql_count, rt_list = excute_fetch_sql(_sql_select, agrs1)
    if _sql_count != 0:
        return False
    args2 = (username, password, age, telphone, email)
    exectue_commit_sql(_sql_insert, args2)
    return True
Пример #8
0
def user_add(params):
    username = params.get('username')
    password = params.get('password')
    age = params.get('age')
    telphone = params.get('telphone')
    email = params.get('email')
    _sql_select = 'select * from user where username = %s'
    _sql_insert = 'insert into user(username,password,age,telphone,email) values(%s,md5(%s),%s,%s,%s)'
    agrs1 = (username,)
    _sql_count,rt_list = excute_fetch_sql(_sql_select,agrs1)
    if _sql_count != 0:
        return False
    args2 = (username,password,age,telphone,email)
    exectue_commit_sql(_sql_insert,args2)
    return True
Пример #9
0
def validate_login(username, password):
    _sql = 'select * from user where username = %s and password = md5(%s)'
    args = (username, password)
    sql_count, rt_list = excute_fetch_sql(_sql, args)
    return sql_count != 0
Пример #10
0
def validate_login(username,password):
    _sql = 'select * from user where username = %s and password = md5(%s)'
    args = (username,password)
    sql_count, rt_list = excute_fetch_sql(_sql,args)
    return sql_count != 0