本文整理汇总了Python中treemap.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.User
的用法示例。
在下文中一共展示了User.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save [as 别名]
def create_user(request):
data = json.loads(request.body)
errors = {}
for field in REQ_FIELDS:
if field not in data:
errors[field] = [trans('This field is required')]
for inputfield in data:
if inputfield not in ALL_FIELDS:
errors[inputfield] = [trans('Unrecognized field')]
if errors:
raise ValidationError(errors)
dup_username = User.objects.filter(username=data['username'])
dup_email = User.objects.filter(email=data['email'])
if dup_username.exists():
return _conflict_response(trans('Username is already in use'))
if dup_email.exists():
# BE WARNED - The iOS application relies on this error message string.
# If you change this you WILL NEED TO ALTER CODE THERE AS WELL.
return _conflict_response(trans('Email is already in use'))
user = User(**data)
# Needed to properly hash the password
user.set_password(data['password'])
user.active = True
user.save()
RegistrationProfile.objects.create_profile(user)
return {'status': 'success', 'id': user.pk}
示例2: create_user
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save [as 别名]
def create_user(*args, **kwargs):
# Clearly this is just getting the api working
# it shouldn't stay here when real user stuff happens
user = User(username=kwargs["username"], email=kwargs["email"])
user.set_password(kwargs["password"])
user.save()
return user
示例3: _create_test_user
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save [as 别名]
def _create_test_user(self):
global userUUID
username = 'autotest%s' % userUUID
email = '%[email protected]' % username
userUUID += 1
User.objects.filter(email=email).delete()
u = User(username=username, email=email)
u.set_password(username)
u.save()
setattr(u, 'plain_password', username)
return u
示例4: create_user
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save [as 别名]
def create_user(request):
data = json.loads(request.body)
if 'allow_email_contact' not in data:
data['allow_email_contact'] = False
errors = {}
for field in REQ_FIELDS:
if field not in data:
errors[field] = [trans('This field is required')]
for inputfield in data:
if inputfield not in ALL_FIELDS:
errors[inputfield] = [trans('Unrecognized field')]
if errors:
raise ValidationError(errors)
dup_username = User.objects.filter(username=data['username'])
dup_email = User.objects.filter(email=data['email'])
if dup_username.exists():
return _conflict_response(trans('Username is already in use'))
if dup_email.exists():
return _conflict_response(trans('Email is already in use'))
user = User(**data)
# Needed to properly hash the password
user.set_password(data['password'])
user.active = True
user.save()
RegistrationProfile.objects.create_profile(user)
return {'status': 'success', 'id': user.pk}
示例5: make_plain_user
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save [as 别名]
def make_plain_user(username, password='password'):
user = User(username=username, email='%[email protected]e.com' % username)
user.set_password(password) # hashes password, allowing authentication
user.save()
return user