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


Python forms.SignupForm方法代码示例

本文整理汇总了Python中allauth.account.forms.SignupForm方法的典型用法代码示例。如果您正苦于以下问题:Python forms.SignupForm方法的具体用法?Python forms.SignupForm怎么用?Python forms.SignupForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在allauth.account.forms的用法示例。


在下文中一共展示了forms.SignupForm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_org_group

# 需要导入模块: from allauth.account import forms [as 别名]
# 或者: from allauth.account.forms import SignupForm [as 别名]
def new_org_group(request):
    # Create new organization group

    class NewOrgForm(forms.ModelForm):
        class Meta:
            model = Organization
            fields = ['name', 'slug']
            labels = {
                "name": "Group name",
                "slug": "Group \"slug\" to appear in URLs",
            }
            help_texts = {
                "name": "An organizational group for you teams assessments.",
                "slug": "Only lowercase letters, digits, and dashes.",
            }
            widgets = {
                "name": forms.TextInput(attrs={"placeholder": "Privacy Office"}),
                "slug": forms.TextInput(attrs={"placeholder": "privacy"})
            }

        def clean_slug(self):
            # Not sure why the field validator isn't being run by the ModelForm.
            import re
            from .models import subdomain_regex
            from django.forms import ValidationError
            if not re.match(subdomain_regex, self.cleaned_data['slug']):
                raise ValidationError("The organization address must contain only lowercase letters, digits, and dashes and cannot start or end with a dash.")
            return self.cleaned_data['slug']

    neworg_form = NewOrgForm()

    if request.POST.get("action") == "neworg":
        # signup_form = SignupForm(request.POST)
        neworg_form = NewOrgForm(request.POST)
        if request.user.is_authenticated and neworg_form.is_valid():
            # Perform new org group creation, then redirect
            # to that org group.
            with transaction.atomic():
                if not request.user.is_authenticated:
                    # TODO Log message that usunloged in user tried to create a group
                    return HttpResponseRedirect("/")
                else:
                    user = request.user
                org = Organization.create(admin_user=user, **neworg_form.cleaned_data)
                return HttpResponseRedirect("/" + org.slug + "/projects")

    return render(request, "org_groups/new_org_group.html", {
        "neworg_form": neworg_form,
        # "member_of_orgs": Organization.get_all_readable_by(request.user) if request.user.is_authenticated else None,
    }) 
开发者ID:GovReady,项目名称:govready-q,代码行数:52,代码来源:views_landing.py


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