本文整理汇总了Python中Directory.create_user方法的典型用法代码示例。如果您正苦于以下问题:Python Directory.create_user方法的具体用法?Python Directory.create_user怎么用?Python Directory.create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Directory
的用法示例。
在下文中一共展示了Directory.create_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_generate_users
# 需要导入模块: import Directory [as 别名]
# 或者: from Directory import create_user [as 别名]
def do_generate_users(self, request):
'''Automatically generates users'''
try:
name = request.getvalue('name', '')
assert name != ''
start = int(request.getvalue('start', 'error'))
end = int(request.getvalue('end', 'error'))
passlen = int(request.getvalue('passlength', 'error'))
except:
request.writeln('<p align="center"><font color="red">Error: Some fields were not entered correctly or were blank; autogeneration cancelled.</font></p>')
return
rand = random.Random()
index_len = len(str(end))
for i in range(start, end + 1):
user = Directory.create_user(request.session.user.id)
newname = name
for j in range(len(str(i)), index_len): # pad lower numbers with zeros
newname += '0'
newname += str(i)
user.name = newname
user.email = ''
user.username = newname
user.password = ''
if passlen > 0:
for i in range(passlen - 1): # all letters except last char is a number
user.password += rand.choice(ASCII_CHARS)
user.password += rand.choice(DIGIT_CHARS)
user.save()
示例2: save_user
# 需要导入模块: import Directory [as 别名]
# 或者: from Directory import create_user [as 别名]
def save_user(self, request):
'''Saves (or creates) a user'''
userid = request.getvalue('userid', 'New')
if (userid == 'New'):
user = Directory.create_user(request.session.user.id)
else:
user = Directory.get_user(userid)
for key in Directory.USER_FIELDS:
setattr(user, key, request.getvalue(key, ''))
user.save()