本文整理匯總了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,
})