本文整理汇总了Python中users.forms.RegistrationForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationForm.save方法的具体用法?Python RegistrationForm.save怎么用?Python RegistrationForm.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.forms.RegistrationForm
的用法示例。
在下文中一共展示了RegistrationForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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})
示例2: login
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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))
示例3: waiting_list
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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})
示例4: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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())
示例5: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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})
示例6: hello
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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))
示例7: test_email_is_saved
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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]')
示例8: post
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def post(self, *args, **kwargs):
form = RegistrationForm(self.request.POST)
if form.is_valid():
user = form.save(commit=False)
user.user_name = form.cleaned_data['username']
user.email = form.cleaned_data['email']
user.set_password(form.cleaned_data['password'])
user.save()
return HttpResponseRedirect(reverse('bookmark_create'))
return render(self.request, 'registration/register.html', {'form': form})
示例9: post
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [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)
示例10: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def register(request):
""" Allows creation of a new user.
"""
form = RegistrationForm(request.DATA)
if form.is_valid():
key = form.save()
data = {
'token': key
}
return OK_RESPONSE(data)
else:
return BAD_RESPONSE(form.errors)
示例11: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def register(request):
if request.user.is_authenticated():
# They already have an account; don't let them register again
return render_to_response(
'users/register.html',
{'has_account': True},
context_instance=RequestContext(request)
)
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
# Find the user type
user = form.save(form)
user_type = form.cleaned_data['user_type']
# Build the activation key for their account
salt = hashlib.md5(str(random.random())).hexdigest()[:5]
activation_key = hashlib.md5(salt+user.username).hexdigest()
key_expires = datetime.today() + timedelta(2)
new_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires, user_type = user_type)
current_site = Site.objects.get_current()
EMAIL_SUBJECT = 'Phonelab Email Verification'
c = Context({'user': user, 'key': new_profile.activation_key, 'site_name': current_site})
EMAIL_BODY = (loader.get_template('users/mails/user_signup.txt')).render(c)
TO_EMAIL = [user.email]
send_mail(EMAIL_SUBJECT, EMAIL_BODY, FROM_EMAIL, TO_EMAIL)
# Create and save their profile
new_profile.save()
return render_to_response(
'users/register.html',
{ 'created': True,
'user_type': user_type,
'mail' : user.email },
context_instance=RequestContext(request)
)
else:
form = RegistrationForm()
return render_to_response(
'users/register.html',
{ 'form': form },
context_instance=RequestContext(request)
)
示例12: register
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def register(request):
if request.user.is_authenticated():
# They already have an account; don't let them register again
return render_to_response(
'users/register.html',
{'has_account': True},
context_instance=RequestContext(request)
)
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
# Save the user
user = form.save(form)
# user.groups.add(Group.objects.get(name='Regular'))
# Build the activation key for their account
salt = hashlib.md5(str(random.random())).hexdigest()[:5]
activation_key = hashlib.md5(salt+user.username).hexdigest()
key_expires = datetime.datetime.today() + datetime.timedelta(2)
# Create and save their profile
new_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires)
new_profile.save()
# Send an email with the confirmation link
EMAIL_SUBJECT = 'The signup information you requested'
#TODO: remove the following two lines
current_site = Site.objects.get_current()
c = Context({'user': user.username, 'key': new_profile.activation_key, 'site_name': current_site.domain})
# c = Context({'user': user.username, 'key': new_profile.activation_key})
EMAIL_BODY = (loader.get_template('users/mails/user_signup.txt')).render(c)
send_mail(EMAIL_SUBJECT, EMAIL_BODY, FROM_EMAIL, [user.email])
# messages.success(request, u'Welcome to the PhoneLab Web Site!')
return render_to_response(
'users/register.html',
{ 'created': True,
'mail' : user.email },
context_instance=RequestContext(request)
)
else:
form = RegistrationForm()
return render_to_response(
'users/register.html',
{ 'form': form },
context_instance=RequestContext(request)
)
示例13: signup
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def signup(request):
form = RegistrationForm()
if request.method == "POST":
form = RegistrationForm(data=request.POST)
if form.is_valid():
user = form.save()
activation_key = hashlib.sha224(user.username.encode("utf-8")).hexdigest()
key_expires = timezone.now() + datetime.timedelta(1)
profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires)
profile.save()
send_email(user, profile)
messages.info(request, "Check email for a confirmation link!")
return redirect("/")
return render(request, "signup.html", {"form": form})
示例14: post
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def post(self, request):
form = RegistrationForm(request.POST)
if form.is_valid():
new_user = form.save()
# TODO - crear el usuario y su blog en una sóla llamada
blog_for_newUser = Blog()
blog_for_newUser.owner = new_user
blog_for_newUser.name = new_user.first_name + ' ' +new_user.last_name + '\'s Personal Blog'
blog_for_newUser.save()
return redirect(reverse('users_login'))
else:
context = {
'signup_form': form
}
return render(request, 'users/sign-up.html', context)
示例15: signup
# 需要导入模块: from users.forms import RegistrationForm [as 别名]
# 或者: from users.forms.RegistrationForm import save [as 别名]
def signup(request):
if not request.user.is_authenticated():
form = RegistrationForm()
if request.method == 'POST':
form = RegistrationForm(data=request.POST)
if form.is_valid():
user = form.save()
activation_key = (hashlib.sha224(user.username.encode('utf-8'))
.hexdigest())
key_expires = timezone.now() + datetime.timedelta(1)
profile = UserProfile(user=user, activation_key=activation_key,
key_expires=key_expires)
profile.save()
send_email(user, profile)
messages.info(request, 'Check email for a confirmation link!')
return redirect('/')
return render(request, 'signup.html', {'form': form})
if request.user.is_teacher:
return redirect('/courses/')
return redirect('/courses/s')