本文整理汇总了Python中model.User.user_group方法的典型用法代码示例。如果您正苦于以下问题:Python User.user_group方法的具体用法?Python User.user_group怎么用?Python User.user_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.user_group方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newuser
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_group [as 别名]
def newuser(*args, **kwargs):
'''
Usage : newuser()
The only method to create a new user
call this method first, modify the return value which is a database row instance,then call self.register()
'''
user_new = User('newuser', 'asdf1234')
user_new.user_group = 'primary'
user_new.avatar = 'default.png'
return user_new
示例2: get_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_group [as 别名]
def get_users(self, board_id):
users_array = self.session.query(User.id, User.name, User.email, BoardUser.user_group).\
join(BoardUser).\
filter(BoardUser.board_id == board_id).\
all()
users = []
for u in users_array:
user = User(id=u.id, name=u.name, email=u.email)
user.user_group = u.user_group
users.append(user)
return users
示例3: newuser
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_group [as 别名]
def newuser(*args, **kwargs):
'''
Usage : newuser()
The only method to create a new user
call this method first, modify the return value which is a database row instance,then call self.register()
'''
user_new = User('newuser', 'asdf1234')
quotafile = open(fspath+"/global/sys/quotainfo",'r')
quotas = json.loads(quotafile.read())
quotafile.close()
user_new.user_group = quotas['default']
user_new.avatar = 'default.png'
return user_new
示例4: __init__
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_group [as 别名]
def __init__(self, username = 'root', password = None):
'''
Try to create the database when there is none
initialize 'root' user and 'root' & 'primary' group
'''
try:
User.query.all()
except:
db.create_all()
if password == None:
#set a random password
password = os.urandom(16)
password = b64encode(password).decode('utf-8')
fsdir = env.getenv('FS_PREFIX')
f = open(fsdir + '/local/generated_password.txt', 'w')
f.write("User=%s\nPass=%s\n"%(username, password))
f.close()
sys_admin = User(username, hashlib.sha512(password.encode('utf-8')).hexdigest())
sys_admin.status = 'normal'
sys_admin.nickname = 'root'
sys_admin.description = 'Root_User'
sys_admin.user_group = 'root'
sys_admin.auth_method = 'local'
db.session.add(sys_admin)
path = env.getenv('DOCKLET_LIB')
subprocess.call([path+"/userinit.sh", username])
db.session.commit()
if not os.path.exists(fspath+"/global/sys/quota"):
groupfile = open(fspath+"/global/sys/quota",'w')
groups = []
groups.append({'name':'root', 'quotas':{ 'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8' }})
groups.append({'name':'admin', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groups.append({'name':'primary', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groups.append({'name':'foundation', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groupfile.write(json.dumps(groups))
groupfile.close()
if not os.path.exists(fspath+"/global/sys/quotainfo"):
quotafile = open(fspath+"/global/sys/quotainfo",'w')
quotas = {}
quotas['default'] = 'foundation'
quotas['quotainfo'] = []
quotas['quotainfo'].append({'name':'cpu', 'hint':'the cpu quota, number of cores, e.g. 4'})
quotas['quotainfo'].append({'name':'memory', 'hint':'the memory quota, number of MB , e.g. 4000'})
quotas['quotainfo'].append({'name':'disk', 'hint':'the disk quota, number of MB, e.g. 4000'})
quotas['quotainfo'].append({'name':'data', 'hint':'the quota of data space, number of GB, e.g. 100'})
quotas['quotainfo'].append({'name':'image', 'hint':'how many images the user can save, e.g. 10'})
quotas['quotainfo'].append({'name':'idletime', 'hint':'will stop cluster after idletime, number of hours, e.g. 24'})
quotas['quotainfo'].append({'name':'vnode', 'hint':'how many containers the user can have, e.g. 8'})
quotafile.write(json.dumps(quotas))
quotafile.close()
示例5: __init__
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_group [as 别名]
def __init__(self, username = 'root', password = None):
'''
Try to create the database when there is none
initialize 'root' user and 'root' & 'primary' group
'''
try:
User.query.all()
UserGroup.query.all()
except:
db.create_all()
root = UserGroup('root')
db.session.add(root)
db.session.commit()
if password == None:
#set a random password
password = os.urandom(16)
password = b64encode(password).decode('utf-8')
fsdir = env.getenv('FS_PREFIX')
f = open(fsdir + '/local/generated_password.txt', 'w')
f.write("User=%s\nPass=%s\n"%(username, password))
f.close()
sys_admin = User(username, hashlib.sha512(password.encode('utf-8')).hexdigest())
sys_admin.status = 'normal'
sys_admin.nickname = 'root'
sys_admin.description = 'Root_User'
sys_admin.user_group = 'root'
sys_admin.auth_method = 'local'
db.session.add(sys_admin)
path = env.getenv('DOCKLET_LIB')
subprocess.call([path+"/userinit.sh", username])
db.session.commit()
admin = UserGroup('admin')
primary = UserGroup('primary')
db.session.add(admin)
db.session.add(primary)
db.session.commit()