本文整理汇总了Python中users.forms.RegistrationForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationForm.is_valid方法的具体用法?Python RegistrationForm.is_valid怎么用?Python RegistrationForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.forms.RegistrationForm
的用法示例。
在下文中一共展示了RegistrationForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def start(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
# user = User.objects.create_user(
# username=form.cleaned_data['username'],
# password=form.cleaned_data['password1'],
# email=form.cleaned_data['email']
# )
user = User(username=form.cleaned_data['username'], password=form.cleaned_data['password1'], email=form.cleaned_data['email'])
user.save()
return HttpResponseRedirect('/users/success/')
else:
form = RegistrationForm()
# 로그인 세션 확인
# 아이디와 비밀번호 비교해서 로그인 성공 시 'login_info' 세션 생성해서 아이디 저장
# request.session['login_info'] = "~~~id" 하고 is_login = TRUE 로 변경
if request.session.get('login_info', False):
is_login = True
else:
is_login = False
print(is_login)
variables = RequestContext(request, {
'form': form,
'is_login': is_login,
})
return render_to_response(
'torch/start.html',
variables,
)
示例2: register_page
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register_page(request):
"""
User can register here to get an account
:param request: HTTP request
:return: HTTP response
"""
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data.get('username'),
password=form.cleaned_data.get('password'),
email=form.cleaned_data.get('email')
)
user.save()
subscription = Subscription(name=user,
registration_date=datetime.now(),
last_login_date=datetime.now(),
abo_date=datetime.now() + timedelta(days=30))
subscription.save()
return render(request, "users/register_success.html", {'username': form.cleaned_data['username']})
else:
form = RegistrationForm()
return render(request, "users/register.html", {"form": form})
示例3: login
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def login(request):
login_form = LoginForm()
register_form = RegistrationForm()
next = request.REQUEST.get('next')
if 'kind' in request.POST:
if request.POST['kind'] == 'login':
login_form = LoginForm(request.POST)
if login_form.is_valid():
username = login_form.get_username()
request.session['username'] = username
if next:
return HttpResponseRedirect(next)
return HttpResponseRedirect('/')
elif request.POST['kind'] == 'register':
register_form = RegistrationForm(request.POST)
if register_form.is_valid():
username = register_form.save()
request.session['username'] = username
if next:
return HttpResponseRedirect(next)
return HttpResponseRedirect('/')
context = {
'login_form': login_form,
'register_form': register_form,
'next': next,
}
return render_to_response(
'users/login.html', context, context_instance=RequestContext(request))
示例4: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register(request):
if request.is_ajax():
if request.POST['fratname'] and request.POST['university'] and request.POST['email'] and request.POST['type']:
try:
uni = University.objects.get(name=str(request.POST['university']))
except University.DoesNotExist:
uni = University(name=str(request.POST['university']), date = datetime.now())
uni.save()
form = RegistrationForm(request.POST)
clean = form.is_valid()
# Make some dicts to get passed back to the browser
rdict = {'bad':'false'}
errors = ""
if not clean:
rdict.update({'bad':'true'})
for e in form.errors.iteritems():
errors += str(e[1])
else:
date = datetime.now()
org = Organization(university = uni, name=request.POST['fratname'], date = date, type=request.POST['type'])
org.save()
user = User.objects.create_user(request.POST['email'], request.POST['email'], date.isoformat())
user.save()
user.get_profile().chapter = org
user.get_profile().university = uni
user.get_profile().ip = request.META['REMOTE_ADDR']
user.get_profile().save
json = simplejson.dumps(rdict)
return HttpResponse(errors)
return HttpResponse("fail")
示例5: test_email_is_saved
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def test_email_is_saved(self):
form = RegistrationForm(data=self.data)
self.assertTrue(form.is_valid())
user = form.save()
self.assertEqual(user.email, '[email protected]')
示例6: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register(request):
"""
Es invocada cuando hacemos un nuevo registro y se encarga de recoger los datos y almacenarlos.
"""
state = " Se dispone a realizar un nuevo registro.Recuerde que todos los campos son obligatorios"
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
name_user = form.cleaned_data['username']
email_user = form.cleaned_data['email']
pass_user = form.cleaned_data['password1']
create_user = User.objects.create_user(username= name_user, email= email_user, password=pass_user)
create_user.save()
pseudo = "@"+name_user
extend = ExtendUser(user=create_user, pseudo=pseudo)
extend.save()
return redirect('/login')
else:
state = " Error en el registro"
return render_to_response('nuevo.html', {'title':'Registro', 'formulario': form, 'state':state}, context_instance=RequestContext(request))
else:
form = RegistrationForm()
return render_to_response('nuevo.html', {'title':'Registro', 'formulario': form, 'state':state}, context_instance=RequestContext(request))
示例7: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register(request):
if is_registration_disabled():
raise Http404
if not is_free_rooms():
return HttpResponseRedirect('/waiting/')
title = "Registration"
definition = get_object_or_404(ZosiaDefinition, active_definition=True)
date_1, date_2, date_3, date_4 = definition.zosia_start, (definition.zosia_start + timedelta(days=1)),\
(definition.zosia_start + timedelta(days=2)),\
(definition.zosia_start + timedelta(days=3))
user_form = RegistrationForm(request.POST or None)
pref_form = preferences_form_fabric(definition)(request.POST or None)
org_form = OrganizationForm(request.POST or None)
f1 = user_form.is_valid()
f2 = pref_form.is_valid()
f3 = org_form.is_valid()
if f1 and f2 and f3:
user = user_form.save()
org = org_form.save()
send_confirmation_mail(request, user, definition)
preference = pref_form.save(commit=False)
preference.user = user
preference.org = org
preference.state = definition
preference.save()
return HttpResponseRedirect('/register/thanks/')
return render_to_response('register_form.html', locals())
示例8: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register(request):
if request.POST:
form = RegistrationForm(request.POST, request.FILES)
if form.is_valid():
user = form.save()
email = user.email
first_name = "Claper"
activation_key = create_activation_key(email)
key_expires = datetime.datetime.now() + datetime.timedelta(2)
Activation.objects.create(user=user, activation_key=activation_key, key_expires=key_expires)
send_activation_key(email, activation_key, first_name)
#return redirect('/success/')
resp = {"code": "0"}
resp = json.dumps(resp)
return HttpResponse(resp, content_type="application/json")
else:
#resp = {"response": "fail", 'error': form['email'].errors}
resp = {"code": "1"}
resp = json.dumps(resp)
return HttpResponse(resp, content_type="application/json")
form = RegistrationForm()
return render(request, 'signup.html', {'form': form})
示例9: waiting_list
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def waiting_list(request):
title = "Registration"
definition = get_object_or_404(ZosiaDefinition, active_definition=True)
date_1, date_2, date_3, date_4 = definition.zosia_start, (definition.zosia_start + timedelta(days=1)),\
(definition.zosia_start + timedelta(days=2)),\
(definition.zosia_start + timedelta(days=3))
if request.POST:
form = WaitingForm(request.POST)
user_form = RegistrationForm(request.POST)
f1 = form.is_valid()
f2 = user_form.is_valid()
if f1 and f2:
user = user_form.save()
send_confirmation_mail(request, user, definition)
waiting = form.save(commit=False)
waiting.state = definition
waiting.user = user
waiting.save()
return HttpResponseRedirect('/register/thanks/')
form = WaitingForm(request.POST)
user_form = RegistrationForm(request.POST)
return render_to_response('waiting.html', {'pref_form': form, 'user_form': user_form,
'date_1': date_1, 'date_2': date_2, 'date_3': date_3, 'date_4': date_4,
'definition': definition})
示例10: hello
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def hello(request, template="users/login.html"):
cc = {}
login_form = LoginForm()
registration_form = RegistrationForm()
if request.method == "POST" and "login_submit" in request.POST:
login_form = LoginForm(request.POST)
if login_form.is_valid():
user = authenticate(
username=login_form.cleaned_data["username"], password=login_form.cleaned_data["password"]
)
login(request, user)
messages.add_message(request, messages.SUCCESS, "Zostałeś zalogowany.")
if "next" in request.GET:
return HttpResponseRedirect(request.GET["next"])
else:
return HttpResponseRedirect(reverse("index"))
elif request.method == "POST" and "registration_submit" in request.POST:
registration_form = RegistrationForm(request.POST)
if registration_form.is_valid():
user_profile = registration_form.save()
user = authenticate(
username=registration_form.cleaned_data["username"],
password=registration_form.cleaned_data["password1"],
)
# send_registration_mail(request.LANGUAGE_CODE, registration_form.cleaned_data['email'], user_profile.activation_key)
return registered(request)
cc["login_form"] = login_form
cc["registration_form"] = registration_form
return render(request, template, Context(cc))
示例11: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.register(request)
return redirect('users.views.home')
else:
form = RegistrationForm()
return render(request, 'register.hisp', {'form': form})
示例12: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def register(request):
form = RegistrationForm(request.POST or None)
if request.POST and form.is_valid():
form.save()
user = authenticate(username=request.POST['username'],
password=request.POST['password'])
auth_login(request, user)
return render(request, 'registration/register_complete.html')
return render(request, 'registration/register.html', {'form': form})
示例13: test_user_submits_empty_form
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def test_user_submits_empty_form(self):
form_data = {'name': '',
'email': '',
'password': ''}
from users.forms import RegistrationForm
form = RegistrationForm(form_data)
self.assertFalse(form.is_valid())
self.assertTrue(form.errors)
self.assertTrue(form.errors.get('name'))
self.assertTrue(form.errors.get('email'))
self.assertTrue(form.errors.get('password'))
示例14: test_user_submits_valid_duplicate_data
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def test_user_submits_valid_duplicate_data(self):
form_data = {'name': 'Nanda Kishore',
'email': '[email protected]',
'password': '1234'}
from users.forms import RegistrationForm
form = RegistrationForm(form_data)
self.assertFalse(form.is_valid())
self.assertTrue(form.errors)
self.assertFalse(form.errors.get('name'))
self.assertTrue(form.errors.get('email'))
self.assertFalse(form.errors.get('password'))
示例15: post
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import is_valid [as 别名]
def post(self, request, *args, **kwargs):
form = RegistrationForm(request.POST)
password = request.POST.get('password')
if form.is_valid():
user = form.save(commit=False)
user.set_password(password)
user.save()
messages.success(request, 'User Succefully registered.')
return HttpResponseRedirect('/')
ctx = {"form": form}
return render(request, "registration/register.html", ctx)