本文整理匯總了Python中registration.forms.RegistrationForm.save方法的典型用法代碼示例。如果您正苦於以下問題:Python RegistrationForm.save方法的具體用法?Python RegistrationForm.save怎麽用?Python RegistrationForm.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類registration.forms.RegistrationForm
的用法示例。
在下文中一共展示了RegistrationForm.save方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: createUser
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def createUser(request):
if request.method == 'POST': # If the form has been submitted...
form = RegistrationForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
try:
form.save()
except ValidationError, err:
error = unicode(err)
return render(request, 'createuser.html', {'form': form, 'error': error})
return HttpResponseRedirect('/thanks/') # Redirect after POST
示例2: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def register(request):
member_form=MemberForm(request.POST or None)
registration_form=RegistrationForm(request.POST or None)
if request.method == 'POST':
member_form = MemberForm(request.POST, request.FILES)
registration_form = RegistrationForm(request.POST)
if member_form.is_valid() and registration_form.is_valid():
member_form.save()
registration_form.save()
registration_form.new_person_form = member_form
registration_form.save()
else:
member_form = member_form
registration_form = registration_form
return render(request, 'registration/registration_form.html', {
'member_form': member_form,
'registration_form': registration_form,
})
示例3: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = form.save()
return redirect('registration_completed')
else:
form = RegistrationForm()
return TemplateResponse(request, 'registration/register.html', {'form': form})
示例4: index
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def index(request):
success = False
if request.method == 'POST':
f = RegistrationForm(request.POST)
if f.is_valid():
success = True
f.instance.is_active = False
#print f.cleaned_data
f.save()
# присоединяем пользователя к группе зарегистрированных пользователей
g = Group.objects.get(pk=1)
f.instance.groups.add(g)
# отправляем письмо с данными учетной записи пользователю
mail_template = MailTemplate.objects.get(code__exact='USERREGISTRATION')
body = mail_template.body.replace('###hostname###', request.get_host())
body = body.replace('###username###', request.POST.get('username'))
body = body.replace('###password###', request.POST.get('password'))
body = body.replace('###activation_link###', 'http://' + request.get_host() + '/registration/activate/{0}/'.format(request.POST.get('username')))
email = EmailMessage(
mail_template.subject,
body,
mail_template.from_email,
[request.POST.get('email').strip(), ],
mail_template.copy_emails.split(';'),
headers={'Reply-To': mail_template.from_email, 'From': mail_template.from_name}
)
email.content_subtype = "html"
email.send()
return redirect('registration_success')
else:
f = RegistrationForm()
context = {'form': f, 'success': success}
return render(request, 'registration/index.html', context)
示例5: _register_all
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def _register_all(trial_run, email_func):
if trial_run:
def trial_email(subject, body, from_, addresses, fail_silently):
print "-" * 60
print "Would send this mail:"
print "To: %s" % ", ".join(addresses)
print "From: %s" % from_
print "Subject: %s" % subject
print
print body
print '-' * 60
email_func = trial_email
anon_racks = Rack.objects.filter(user=u'')
addrs = set([rack.email.strip() for rack in anon_racks])
names_seen = set()
current_site = Site.objects.get(id=settings.SITE_ID)
for email in addrs:
name = email.split('@', 1)[0]
import re
name = re.sub(r'[^!A-Za-z0-9_-]', '_', name)
if name in names_seen:
raise ValueError("Oh crap, already saw name %r" % name)
names_seen.add(name)
password = randpass() # Just so we always have a non-empty password.
data = {'username': name, 'email': email,
'password1': password, 'password2': password,}
template_args = {'name': name, 'email': email, 'domain': current_site.domain,
'password': password,
'activation_days': settings.ACCOUNT_ACTIVATION_DAYS,
}
form = RegistrationForm(data=data)
if form.is_valid():
# Register an inactive account and get the key.
template = register_email_txt
user = form.save()
reg_profile = RegistrationProfile.objects.filter(user=user)[0]
template_args['key'] = reg_profile.activation_key
# We also need to provide a way to set your password.
template_args['password_reset_token'] = default_token_generator.make_token(user)
template_args['uidb36'] = int_to_base36(user.id)
if trial_run:
user.delete(); reg_profile.delete()
else:
if form.errors.get('username', [''])[0].count(u'already taken'):
# Send an email without the link to the predetermined username.
template = register_email_name_taken_txt
else:
print "Problem with address %s:" % email
import pprint
pprint.pprint(form.errors)
continue
send_email(template, trial_run, email_func=email_func, **template_args)
示例6: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def register(request):
if request.user.is_authenticated():
return redirect('edit_profile')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = form.save()
#user = auth.authenticate(username=username, password=password)
#assert user and user.is_authenticated()
#auth.login(request, user)
return redirect('registration_completed')
else:
form = RegistrationForm()
return TemplateResponse(request, 'registration/register.html', {'form': form})
示例7: _register_all
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def _register_all():
anon_racks = Rack.objects.filter(user=u"")
addrs = set([rack.email.strip() for rack in anon_racks])
names_seen = set()
current_site = Site.objects.get(id=settings.SITE_ID)
for email in addrs:
name = email.split("@", 1)[0]
name = name.replace("+", "_") # XXX do more cleanup
if name in names_seen:
raise ValueError("Oh crap, already saw name %r" % name)
names_seen.add(name)
password = randpass() # Just so we always have a non-empty password.
data = {"username": name, "email": email, "password1": password, "password2": password}
template_args = {
"name": name,
"email": email,
"domain": current_site.domain,
"password": password,
"activation_days": settings.ACCOUNT_ACTIVATION_DAYS,
}
form = RegistrationForm(data=data)
if form.is_valid():
# Register an inactive account and get the key.
template = register_email_txt
user = form.save()
reg_profile = RegistrationProfile.objects.filter(user=user)[0]
template_args["key"] = reg_profile.activation_key
# We also need to provide a way to set your password.
template_args["password_reset_token"] = default_token_generator.make_token(user)
template_args["uidb36"] = int_to_base36(user.id)
# user.delete(); reg_profile.delete() #XXX remove this when everything works
else:
if form.errors.get("username", [""])[0].count(u"already taken"):
# Send an email without the link to the predetermined username.
template = register_email_name_taken_txt
else:
print "Problem with address %s:" % email
import pprint
pprint.pprint(form.errors)
continue
send_email(template, **template_args)
示例8: save
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def save(self, commit=True):
user = RegistrationForm.save(self, commit=commit)
profile = user.get_profile()
artist_profile = ArtistProfileUpdateForm.save(self, profile, commit=commit)
return user
示例9: save
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import save [as 別名]
def save(self, commit=True):
self.instance.business_email = self.cleaned_data['email']
return BaseRegistrationForm.save(self, commit=commit)