本文整理匯總了Python中registration.forms.RegistrationForm.is_valid方法的典型用法代碼示例。如果您正苦於以下問題:Python RegistrationForm.is_valid方法的具體用法?Python RegistrationForm.is_valid怎麽用?Python RegistrationForm.is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類registration.forms.RegistrationForm
的用法示例。
在下文中一共展示了RegistrationForm.is_valid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register(request, extra_context=None):
if not getattr(settings, 'REGISTRATION_OPEN', True):
return redirect('registration_disallowed')
if request.method == 'POST':
form = RegistrationForm(data=request.POST, files=request.FILES)
if form.is_valid():
username, email, password = form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1']
site = Site.objects.get_current() if Site._meta.installed else RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site)
signals.user_registered.send(sender=None, user=new_user, request=request)
profile = UserProfile.objects.get(user=new_user)
seller_type = form.cleaned_data['seller_type']
phone = form.cleaned_data['phone']
profile.seller_type = seller_type
profile.phone = phone
profile.save()
gravatar_task.delay(new_user, new_user.pk)
success_url = request.GET.get('next','')
if success_url:
return redirect(success_url)
else:
return redirect('registration_complete')
else:
form = RegistrationForm()
if extra_context is None:
extra_context = {}
context = RequestContext(request)
for key, value in extra_context.items():
context[key] = callable(value) and value() or value
return render_to_response('static_pages/index.html', {'register_form': form}, context_instance=context)
示例2: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register(request,
disallowed_url='registration_disallowed',
template_name='registration/registration.html'):
"""用戶注冊
"""
# 是否允許用戶進行注冊
allow_register = getattr(settings, 'REGISTRATION_OPEN', False)
if not allow_register:
return redirect(disallowed_url)
if request.method == 'POST':
form = RegistrationForm(request.POST)
# 數據驗證
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
# 創建一個未激活的用戶和默認的擴展屬性
act_key = TeamProfile.objects.create_inactive_user(username, email, password)
# 直接將激活碼作為鏈接發給用戶
to, args, kwargs = ('registration_activate',(), {'activation_key':act_key})
return redirect(to, *args, **kwargs)
else:
form = RegistrationForm()
context = RequestContext(request)
return render_to_response(template_name,
{'form': form},
context_instance=context)
示例3: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(username=form.cleaned_data['username'], email = form.cleaned_data['email'], password=form.cleaned_data['password'])
user.save()
registration = UserProfile(user=user, name = form.cleaned_data['name'], address = form.cleaned_data['address'],
contact = form.cleaned_data['contact'], stream = form.cleaned_data['stream'], age = form.cleaned_data['age'],
gender = form.cleaned_data['gender'], register_as = form.cleaned_data['register_as']
)
if form.cleaned_data['register_as']=='FY':
facstat = FacultyStatus(username = form.cleaned_data['username'], name = form.cleaned_data['name'])
facstat.save()
if 'picture' in request.FILES:
registration.picture = request.FILES['picture']
registration.save()
return HttpResponseRedirect('/profile')
else:
return render_to_response('registration/register.html',{'form':form, 're':"active"}, context_instance=RequestContext(request))
else:
form = RegistrationForm()
context = {'form': form, 're':"active"}
return render_to_response('registration/register.html', context, context_instance=RequestContext(request))
示例4: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register(request):
if request.user.is_authenticated():
return redirect('current_profile')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
#new_user = RegistrationProfile.objects.create_inactive_user(username, email, password)
#return redirect('registration_complete')
user = User.objects.create_user(username, form.cleaned_data['email'], password)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
user = auth.authenticate(username=username, password=password)
assert user and user.is_authenticated()
auth.login(request, user)
# TODO: redirect to a message with confirmation
return redirect(user.get_absolute_url())
else:
form = RegistrationForm()
return render_to_response('users/register.html',
context_instance=RequestContext(request, {'form': form}))
示例5: handle_post
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def handle_post(self, request):
"""
Registers a user if it was a request to register a user
and the registration form was correctly completed.
"""
# Confirm that the requst is a post, and that this form is
# the intended recipient of the posted data.
if not request.POST or self.submit_btn_name() not in request.POST:
return None
form = RegistrationForm(request.POST, auto_id=False)
if form.is_valid():
# Create a user, log them in, and redirect based on the
# success_url rules.
user, created = User.objects.create_user(request=request,
send_email=True,
**form.cleaned_data)
user_cache = authenticate(
username=form.cleaned_data['email'],
password=form.cleaned_data['password1'])
expire_login(request, user_cache)
response = HttpResponseRedirect(success_url(request))
response.set_cookie('myguid', user.user_guid, expires=365*24*60*60,
domain='.my.jobs')
return response
return None
示例6: user_profile_post
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def user_profile_post(request, **kwargs):
user=request.user
form=RegistrationForm(request.POST)
added_context={'registration_form': form}
if not form.is_valid(user=user):
form.reformat_errors()
# log.debug('user %r not valid, aborting' % user.contributor)
return render(request, 'registration/user_profile.html', added_context)
user.first_name=form.cleaned_data['first_name']
user.last_name=form.cleaned_data['last_name']
user.email=form.cleaned_data['email']
user.password=make_password(form.cleaned_data['password1'])
user.contributor.lab.name=form.cleaned_data['lab']
user.contributor.lab.url=form.cleaned_data['lab_url']
try:
# log.debug('about to save user: %r' % user.contributor)
user.save()
added_context['msgs']='Profile successfully updated'
except Exception as e:
msgs='Unable to save user information: %s' % e
added_context['msgs']=msgs
# log.debug(msgs)
return render(request, 'registration/user_profile.html', added_context)
示例7: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register(request):
if not request.user.is_anonymous():
return redirect('/home/')
if request.method == 'POST':
title = "Update Profile"
form = RegistrationForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
user = User.objects.create(username=email_to_username(email),
email=email)
user.set_password(password)
user.save()
account = Account.objects.create(
user=user,
first_name=form.cleaned_data['first_name'],
middle_name=form.cleaned_data['middle_name'],
last_name=form.cleaned_data['last_name'],
mobile_no=form.cleaned_data['phone_number'],
email=form.cleaned_data['email']
)
return redirect('/register/success/')
else:
title = "Create New Profile"
form = RegistrationForm()
return render(
request,
'registration/register.html',
{'form': form, 'title': title}
)
示例8: edit
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def edit(request):
curr_user = request.user
if request.method == 'POST':
form = RegistrationForm(request.POST, user=curr_user)
if form.is_valid():
try:
curr_user.account.first_name = form.cleaned_data['first_name']
curr_user.account.middle_name = form.cleaned_data['middle_name']
curr_user.account.last_name = form.cleaned_data['last_name']
curr_user.account.mobile_no = form.cleaned_data['phone_number']
#curr_user.account.email = form.cleaned_data['email']
curr_user.account.save()
except Account.DoesNotExist:
return HttpResponse('The Account object does not exist for this user')
return redirect('/register/success/')
else:
form = RegistrationForm(user=curr_user)
return render(
request,
'registration/register.html',
{'form': form, 'title': 'Update Profile'}
)
示例9: create_account
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def create_account(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
form.cleaned_data['email'],
form.cleaned_data['email'],
form.cleaned_data['password'],
)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
# Log in the new user. Note that Django requires that we call
# authenticate() despite its apparent redundancy in this case
user = authenticate(username=user.username, password=form.cleaned_data['password'])
login(request, user)
return redirect(reverse('registration.views.create_account_done'))
else:
form = RegistrationForm()
return render_to_response('registration/create_account.html', RequestContext(request, {
'form': form,
}))
示例10: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register(request, template_name='registration/register.html'):
profile_url = settings.USER_PROFILE_URL % 'username'
if request.method == 'GET':
form = RegistrationForm()
else: # POST
form = RegistrationForm(data=request.POST)
if form.is_valid():
hn_username = form.cleaned_data['hn_username']
# user_data is a dict containing the users HN account creation
# date, karma at query time, and HN profile
user_data = retrieve_hn_user_data(hn_username)
# form validation checks that hn_username matches what's provided
# and that the "key" (a url) is in the profile
temp_password = ''.join(random.sample(string.letters, 16))
new_user = User.objects.create_user(username=hn_username,
email='',
password=temp_password)
user = authenticate(username=new_user.username,
password=temp_password)
if user is not None:
login(request, user)
messages.success(request, 'That worked. Please provide a password.')
return HttpResponseRedirect(reverse('set_password'))
return render_to_response(template_name, locals(),
context_instance=RequestContext(request))
示例11: login
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def login(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('')
else:
return render(request, 'registration/login.html')
示例12: createUser
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [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
示例13: register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [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})
示例14: login_register
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def login_register(request):
form = None
next_url = None
if request.method == 'POST':
action = request.POST.get('action')
next_url = request.GET.get('next') or reverse('login')
if action == 'login':
username = request.POST.get('username', '')
password = request.POST.get('password1', '')
if username and password:
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect(next_url)
# Could not authenticate
form = {
'username': {
'errors': 'Your username and password did not match.',
}
}
else:
form = {
'password1': {
'errors': 'Please enter a username and password.',
},
}
elif action == 'register':
form = RegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
User.objects.create_user(username, email, password)
user = authenticate(username=username, password=password)
login(request, user)
return redirect(next_url)
else:
# The action is not set. Malicious submission?
pass
context = {
'next_url': next_url,
'form': form,
}
return render(request, 'login.djhtml', context)
示例15: register_new_user
# 需要導入模塊: from registration.forms import RegistrationForm [as 別名]
# 或者: from registration.forms.RegistrationForm import is_valid [as 別名]
def register_new_user(request):
form=RegistrationForm(request.POST)
# log.debug('hi, prospective new user')
if not form.is_valid(): # try again
# log.debug('form invalid, try again')
form.reformat_errors()
return render(request, 'registration/login.html', {'registration_form': form})
# check for previously existing user of that name:
try:
username=form.cleaned_data['username']
user=User.objects.get(username=username)
form.errors['username']='username "%s" already taken' % username
# log.debug('username %s already taken' % username)
form.reformat_errors()
return render(request, 'registration/login.html', {'registration_form': form})
except User.DoesNotExist:
# log.debug('no user %s, proceeding' % username)
pass
# create User:
log.info('attempting to create new user %s' % form.cleaned_data['username'])
username=form.cleaned_data['username']
first_name=form.cleaned_data['first_name']
last_name=form.cleaned_data['last_name']
password1=form.cleaned_data['password2']
password2=form.cleaned_data['password1']
email=form.cleaned_data['email']
lab_name=form.cleaned_data['lab']
lab_url=form.cleaned_data['lab_url']
user=User.objects.create_user(username, email, password1)
user=auth.authenticate(username=username, password=password1)
auth.login(request, user)
log.info('new user %s logged in' % user.username)
# create lab and contributor:
try:
lab=Lab.objects.get(name=lab_name)
except Lab.DoesNotExist:
lab=Lab(name=lab_name, url=lab_url)
lab.save()
# log.debug('new user: lab is %s' % lab)
try:
contributor=Contributor.objects.get(user=user)
except Contributor.DoesNotExist:
contributor=Contributor(user=user, first_name=first_name, last_name=last_name, lab=lab)
contributor.save()
# log.debug('contributor is %s' % contributor)
url=reverse('user_profile', args=(user.username,))
return redirect(url)