本文整理汇总了Python中accounts.models.UserSettings.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserSettings.save方法的具体用法?Python UserSettings.save怎么用?Python UserSettings.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.UserSettings
的用法示例。
在下文中一共展示了UserSettings.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from accounts.models import UserSettings [as 别名]
# 或者: from accounts.models.UserSettings import save [as 别名]
def register(request, trial):
page_type = 'register'
if trial == 'trial':
trial_account = True
else:
trial_account = False
if request.method == 'POST':
user_form = UserRegisterForm(request.POST, label_suffix='')
group_form = GroupRegisterForm(request.POST, label_suffix='')
if user_form.is_valid() and group_form.is_valid():
# save each form
password = user_form.cleaned_data['password1']
new_user = user_form.save()
group = group_form.save()
# associate the user with the group
u = new_user
group.users.add(u)
# set the group as the user's current_group
settings = UserSettings(user=u, current_group=group)
settings.save()
# generate a slug from the group name
slug = slugify(group.name)[:20]
group.slug = slug
group.save()
# set the account status to trial if required
if trial_account == True:
group.account_type = 'Trial'
group.save()
# save initial snapshots of new user and group details
snapshot_user_details(u, password='set')
snapshot_group_details(group)
# log the new user in
user = authenticate(username=new_user.username,
password=password)
login(request, user)
# set the new user up as a participant
participant = Participant(group=group, email=user.email,
first_name=user.first_name,
last_name=user.last_name)
participant.save()
# send the new user a welcome email
send_welcome_email(group=group, user=user)
return HttpResponseRedirect(reverse('welcome'))
else:
user_form = UserRegisterForm(label_suffix='')
group_form = GroupRegisterForm(label_suffix='')
return render(request, 'register.html', {
'group_form': group_form,
'page_type': page_type,
'trial_account': trial_account,
'user_form': user_form,
})