当前位置: 首页>>代码示例>>Python>>正文


Python UserSettings.save方法代码示例

本文整理汇总了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,
    })
开发者ID:MelissaNaomi,项目名称:econvenor,代码行数:58,代码来源:views.py


注:本文中的accounts.models.UserSettings.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。