def get_account(self,values,userid,name):
   balance=None
   if userid:
     account=Account.gql("where userid=:1 limit 1",userid).get()
     if not account:
       if name:
         account=Account()
         account.userid=userid
         account.name=name
         account.balance=0
         account.put()
       else:
         account=None
     else:
       balance=account.balance
       name=account.name
   else:
     account=None
   values["userid"]=userid
   if balance:
     values["balance"]=balance/100.0
   else:
     values["balance"]=0.0
   values["name"]=name
   return account
Пример #2
0
async def init_data():
    await db.init_db(user_dsn)
    await db.begin()
    print('-   初始化表:account')
    password = '******'
    passwd_md5 = hashlib.md5(password.encode('utf-8')).hexdigest()
    account = Account()
    account.uid = 'admin'
    account.name = '管理员'
    account.password = passwd_md5
    account.usergroup = 'admin'
    await account.save()
    print('-   初始化表:usergroup')
    usergroup = Usergroup()
    usergroup.gid = 'admin'
    usergroup.role = 'admin'
    usergroup.name = '管理员'
    await usergroup.save()
    usergroup.gid = 'core'
    usergroup.role = 'user'
    usergroup.name = '核心组'
    await usergroup.save()
    usergroup.gid = 'front'
    usergroup.role = 'user'
    usergroup.name = '前置组'
    await usergroup.save()
    usergroup.gid = 'manger'
    usergroup.role = 'user'
    usergroup.name = '管理组'
    await usergroup.save()
    usergroup.gid = 'chanle'
    usergroup.role = 'user'
    usergroup.name = '渠道组'
    await usergroup.save()
    usergroup.gid = 'public'
    usergroup.role = 'user'
    usergroup.name = '公共'
    await usergroup.save()
    await db.commit()
    rows = await Usergroup.read(where='gid=%s', args=['public'])
    print(rows)
    await db.close_db(user_dsn)