本文整理汇总了Python中forms.UserCreateForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python UserCreateForm.is_valid方法的具体用法?Python UserCreateForm.is_valid怎么用?Python UserCreateForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UserCreateForm
的用法示例。
在下文中一共展示了UserCreateForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def register(request):
context = {}
context["news"] = get_news_by_request(request)
user = User()
if request.method == 'POST':
form = UserCreateForm(request.POST, instance = user)
if form.is_valid():
pw = user.password
user.set_password(user.password)
user.theme_id=4
user.input_type_id=1
if not open_registration:
user.is_active = False
form.save()
ro = ReminderOffsets.objects.get(value=0)
user.reminder_offset.add(ro)
ro = ReminderOffsets.objects.get(value=2)
user.reminder_offset.add(ro)
if open_registration:
group = Group.objects.filter(name="BuLiTipp")[0]
user.groups.add(group)
user = authenticate(username=user.username, password=pw)
djlogin(request, user)
messages.success(request, "Benutzer erfolgreich angelegt! Tritt als nächstes einer Tippgemeinschaft bei!")
return HttpResponseRedirect(reverse("user", args=["tgchange"]))
else:
mail.send("BuLiTipp: User registriert", "[email protected]", "Bitte administriere den neuen User " + user.username+ " !")
messages.success(request, "Benutzer erfolgreich angelegt! Du kannst dich einloggen sobald der Administrator dich freigeschaltet hat.")
return HttpResponseRedirect(reverse("home"))
else:
form = UserCreateForm(instance=user)
context["form"] = form
return render(request, 'registration/register.html', context)
示例2: create_user
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def create_user(request):
context = {}
context_instance = RequestContext(request)
form = UserCreateForm(request.POST or None)
context['form'] = form
if request.user.is_authenticated():
return redirect('/user/dashboard')
if request.method == 'POST' and form.is_valid():
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
username = form.cleaned_data['username']
password = form.cleaned_data['password']
email = form.cleaned_data['email']
phone = form.cleaned_data['phone']
try:
users_manager.create_user(first_name, last_name, username, password, email, phone)
# authenticate and login
user = authenticate(username=username, password=password)
login_auth(request, user)
return redirect('/user/dashboard')
except Exception as exc:
# 400
form.errors['__all__'] = form.error_class(["Error: %s" % exc.message])
# GET / POST with invalid input
return render_to_response('user/create.html', context, context_instance=context_instance)
示例3: signup
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def signup(request):
"""
User registration view.
"""
auth_form = AuthenticateForm()
if request.method == 'POST':
form = UserCreateForm(data=request.POST)
if form.is_valid():
form.save()
user = authenticate(email=request.POST['email'], password=request.POST['password2'])
if user is not None:
if user.is_active:
login(request, user)
return redirect('/')
else:
return render_to_response('home.html', {
'auth_form': auth_form, 'user_form': form,
}, context_instance=RequestContext(request))
elif request.method == 'GET':
form = UserCreateForm()
return render_to_response('home.html', {
'auth_form': auth_form, 'user_form': form,
}, context_instance=RequestContext(request))
示例4: Register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def Register(request):
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
c_form = UserCreateForm(data=request.POST)
if user_form.is_valid() and c_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
c = c_form.save(commit=False)
c.user = user
c.save()
c_form.save_m2m()
registered = True
else:
print user_form.errors, c_form.errors
else:
user_form = UserForm()
c_form = UserCreateForm()
return render(request, 'gadgetapp/register.html',
{'user_form': user_form, 'c_form': c_form, 'registered': registered}, RequestContext(request))
示例5: customregister
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def customregister(request):
returnJson = ifReturnJson(request)
data_dict = {}
data_dict['type'] = 'register'
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
new_user = form.save()
data_dict['success'] = 1
data_dict['uid'] = new_user.id
data_dict['username'] = new_user.username
data_dict['name'] = new_user.first_name + new_user.last_name
data_dict['email'] = new_user.email
#Redirect to the registration complete page
#return HttpResponseRedirect("/homepage/")
else:
data_dict['success'] = 0
#invalid form
data_dict['error_message'] = 'invalid registration form'
if returnJson == 1:
return HttpResponse(json.dumps(data_dict),content_type='application/json')
elif returnJson == 0:
return redirect('/accounts/register')
else:
form = UserCreateForm()
return render(request, "registration/registration_form.html", {
'form': form,
})
示例6: register_user
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def register_user(request):
template_name = 'kitchen/crispy.html'
if request.method == 'POST':
user_form = UserCreateForm(request.POST)
if user_form.is_valid():
username = user_form.clean_username()
password = user_form.clean_password2()
user_form.save()
user = authenticate(username=username,
password=password)
if user:
# save extra parameters - email
user.email = user_form.data['email']
user.save()
#ASK - may be we should init it only in one place - on login?
initUser(user)
login(request, user)
return redirect('account-list')
return render(request,
template_name,
{ 'form' : user_form })
args = {}
args.update(csrf(request))
args['form'] = UserCreateForm()
print args
return render(request, template_name, args)
示例7: create_user
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def create_user(self, version = 0):
"""
Creates a UserProfile. Version is an integer that determines which userprofile to generate (one of two)
"""
registration_values = self.create_valid_user_vals(version)
user_form = UserCreateForm(registration_values)
if user_form.is_valid():
return user_form.save()
示例8: register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def register(request):
if request.method == "POST":
form = UserCreateForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/videos/")
else:
form = UserCreateForm()
return render(request, "registration/register.html", {"form": form})
示例9: create_account
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def create_account(request):
if request.method == "POST":
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/success/')
else:
form = UserCreateForm()
return render(request,'create.html',{'form':form})
示例10: register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def register(request):
register_success = reverse('user_register_success')
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(register_success)
else:
form = UserCreateForm()
return render_to_response('newaccounts/registration.html', {'form':form}, context_instance=RequestContext(request))
示例11: signup
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def signup(request, template_name="authentication/signup.html"):
form = UserCreateForm(request.POST or None)
if request.POST:
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse("home"))
return render(request, template_name, {"form": form})
示例12: create_user
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def create_user(request):
"""Creates a new user"""
if request.method == "POST":
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
form = UserCreateForm()
return render(request, 'quiz/create_user.html', context={'form': form})
示例13: register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def register(request):
if request.user.is_authenticated():
return redirect('/')
if request.method == 'POST':
user_information = {
'username': request.POST['username'],
'password1': request.POST['password1'],
'password2': request.POST['password2'],
'last_name': request.POST['last_name'],
'city': request.POST['city'],
'first_name': request.POST['first_name'],
'state': request.POST['state'],
'middle_initial': request.POST['middle_initial'],
'birth_date': request.POST['birth_date'],
'email': request.POST['email'],
'street_address': request.POST['street_address'],
'zip_code': request.POST['zip_code']
}
form = UserCreateForm(user_information)
if form.is_valid():
form.save()
return redirect('/')
else:
form_errors = form.errors
return render_to_response('register.html', {'errors': form_errors, 'form': form}, context_instance=RequestContext(request))
else: #AJAX form validation
request_copy = request.GET.copy()
if 'username' in request_copy: #Username in use?
name = request_copy['username']
response_data = {}
if UserProfile.objects.filter(username__iexact=name):
response_data['result'] = 'false'
else:
response_data['result'] = 'true'
return HttpResponse(response_data['result'], content_type='text/plain')
# return HttpResponse(json.dumps(response_data), content_type = "application/json")
if 'email' in request_copy: #Email in use?
entered_email = request_copy['email']
response_data = {}
if UserProfile.objects.filter(email__iexact=entered_email):
response_data['result'] = 'false'
else:
response_data['result'] = 'true'
return HttpResponse(response_data['result'], content_type = 'text/plain')
else:
form = UserCreateForm()
return render_to_response("register.html", {'form': form, 'errors':form.errors}, context_instance=RequestContext(request))
示例14: register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def register(request):
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/importinfo/")
else:
form = UserCreateForm()
return render_to_response("registration/register.html", {
'form': form,
}, context_instance=RequestContext(request))
示例15: settings
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import is_valid [as 别名]
def settings(request):
tweet_form = TweetForm()
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return redirect('/')
else:
return render(request, 'settings.html', {'form': form,})
form = UserCreateForm(instance=request.user)
return render(request, 'settings.html', {'form': form, 'tweet_form': tweet_form})