本文整理汇总了Python中forms.MyRegistrationForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python MyRegistrationForm.save方法的具体用法?Python MyRegistrationForm.save怎么用?Python MyRegistrationForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.MyRegistrationForm
的用法示例。
在下文中一共展示了MyRegistrationForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
# if not (form.cleaned_data['user_type'] == 'Patient'):
# # if its a patient, we dont need to check his username
# response = java_insertUser(form)
# else:
if not (userExists(form.cleaned_data['username'])):
# if the user does not exist
return HttpResponseRedirect('/accounts/register_failed')
# else save him
response = java_insertStaff(form)
if (response):
form.save()
return HttpResponseRedirect('/accounts/register_success')
else:
return HttpResponseRedirect('/accounts/register_failed')
else:
form = MyRegistrationForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render(request, 'register.html', args)
示例2: reg
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def reg(request):
if request.method =='POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
username= request.POST.get('username','')
email= request.POST.get('email','')
subject = 'Hi {0} Welcome to Shabingo'.format(username)
msg="Hi {0},".format(username)
msg=msg+settings.WELCOME_EMAIL
message = msg
recipients = ['[email protected]']
if email:
recipients.append(email)
send_mail(subject, message, '[email protected]', recipients)
return HttpResponseRedirect('thank-you')
else:
form = MyRegistrationForm()
return render(request, 'reg.html', {'form': form})
示例3: manage_account
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def manage_account(request,user_id):
a = User.objects.get(pk=user_id)
print a
print request.user.username
if request.method == "POST":
print "test1"
form = MyRegistrationForm(request.POST, instance = a)
print "test2"
#print form.is_valid()
try:
if form.is_valid():
form.save()
print "test2"
a.is_active = True
a.save()
messages.warning(request,'Updated successfully')
return HttpResponseRedirect(reverse('polls:index'))
except:
return render(request, 'polls/manage_account.html', {
'form':form,
'user_id':a.id,
})
else:
form = MyRegistrationForm()
c = {}
c.update(csrf(request))
c.update({'user_id':a.id})
c.update({'form':form})
c.update({'username':a.username})
c.update({'email':a.email})
c.update({'first_name':a.first_name})
c.update({'last_name':a.last_name})
return render_to_response('polls/manage_account.html',c)
示例4: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
# If the form has been submitted...
if request.method == "POST":
# form = UserCreationForm(request.POST)
# we are going to pass the values of request.POST a dictionary to
# UserCreationForm and create a form object
# A form bound to the POST data
form = MyRegistrationForm(request.POST)
# if form is validated then the form object should be saved
# with the resgitration information of the new user
if form.is_valid():
form.save()
# now HttpResponseRedirect takes us to url(r'^accounts/register_success/$','django_test.views.register_success')
# now accounts/register_success/ causes the excution of django_test.views.register_success views
return HttpResponseRedirect('/accounts/register_success')
# for security purpose we have to embedd csrf tokens into agrs which will help us to know this post
# method is coming from a reliable source
args={}
args.update(csrf(request))
# now we are embedding a blank user creation form into the args, it has no information put in it
args['form'] = MyRegistrationForm()
print args
return render_to_response('register.html',args)
示例5: home
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def home(request):
mylogfunction()
logger.debug("this is a debug message from home!")
if request.method =='POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
username= request.POST.get('username','')
email= request.POST.get('email','')
subject = 'Hi {0} Welcome to Shabingo'.format(username)
msg="Hi {0},".format(username)
#Email text stored in the settings.py file
msg=msg+settings.WELCOME_EMAIL
message = msg
recipients = ['[email protected]']
if email:
recipients.append(email)
send_mail(subject, message, '[email protected]', recipients)
#send_mail(subject, message, sender, recipients)
messages.success(request, 'Thank you for joining!')
return HttpResponseRedirect('thank-you')
else:
form = MyRegistrationForm()
return render(request, 'signup.html', {'form': form})
return render(request, 'signup.html', {'form': form})
示例6: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
if request.method == 'POST':
registration_form = MyRegistrationForm(request.POST)
#non-successful profile update
#registration success
if registration_form.is_valid():
registration_form.save()
send_mail('NEW USER SIGNUP', registration_form.cleaned_data['username'], '[email protected]', ['[email protected]'], fail_silently=False)
if request.is_ajax():
return HttpResponse('OK')
else:
return HttpResponseRedirect('/accounts/register_success')
else:
if request.is_ajax():
errors_dict = {}
for error in registration_form.errors:
e = registration_form.errors[error]
errors_dict[error] = unicode(e)
return HttpResponseBadRequest(json.dumps(errors_dict))
else:
registration_form = MyRegistrationForm()
args = {}
args.update(csrf(request))
args['form'] = registration_form;
return render_to_response('register.html', args, context_instance=RequestContext(request))
示例7: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
currentPath = request.POST.get('currentPath', '')
currentPath = currentPath.replace("invalid/", "").replace("registered/", "")
username=request.POST.get('email')
password=request.POST.get('password1')
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
if "log" in currentPath:
return HttpResponseRedirect(currentPath)
else:
return HttpResponseRedirect('/register_success')
elif "log" in currentPath:
return HttpResponseRedirect(currentPath + "registered")
else:
form = MyRegistrationForm()
form.fields['password1'].label = "密码"
form.fields['password2'].label = "再次输入密码"
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('register.html', args)
示例8: reg_view
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def reg_view(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid() and len(request.POST.get('zipcode')) == 5:
form.save()
return HttpResponseRedirect('/loggedin')
else:
return HttpResponseRedirect('/invalid')
示例9: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request,context):
context.update(csrf(request))
if request.method =="POST":
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return render_to_response('frontEnd/djangoBlog/register_success.html',context) #no need to create a new url like register_success just render that html is enough (url is /accounts/register)
context['form'] = MyRegistrationForm()
return render_to_response('frontEnd/djangoBlog/register.html',context)
示例10: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
c = {}
c.update(csrf(request))
c['form'] = MyRegistrationForm()
return render_to_response('register.html', c)
示例11: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid:
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
#args.update(csrf(request))
args['form'] = MyRegistrationForm()
return render(request,'register.html', args)
示例12: register
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return render(request, 'index.html', {})
args = {}
args.update(csrf(request))
args['form'] = MyRegistrationForm()
return render_to_response('login.html', args)
示例13: register
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
else:
args = {}
args['register_active'] = True
if request.GET.get('inv'):
args['invite'] = request.GET.get('inv')
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
args['form'] = form
if form.is_valid():
# Pick data
invite = request.POST.get('invite')
initial_balance = int(request.POST.get('balance'))
# Save user with Default properties
form.save()
# Pick the user
user = User.objects.get(username=form.get_username())
# Custom USER data
uinfo = UserProfile()
uinfo.user = user
# BALANCE
if initial_balance > 50:
initial_balance = initial_balance + (initial_balance * 0.10)
# Check invite
if invite:
try:
host_user = UserProfile.objects.get(invite_id=invite)
except UserProfile.DoesNotExist:
host_user = None
if host_user:
initial_balance = initial_balance + 10
# SAVE USER CUSTOM DATA
uinfo.initial_balance = initial_balance
uinfo.invite_id = get_random_string(length=30)
uinfo.save()
return HttpResponseRedirect('/accounts/register_success')
args['register_active'] = True
return render(request, 'register.html', args)
else:
args['form'] = MyRegistrationForm()
args.update(csrf(request))
return render_to_response('register.html', args)
示例14: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST) #just changed UserCreationForm to muregistrationform
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args={}
args.update(csrf(request))
args['form'] = MyRegistrationForm() #just changed UserCreationForm to muregistrationform
return render_to_response('register.html',args)
示例15: register_user
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import save [as 别名]
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
args = {}
args.update(csrf(request))
args['form'] = MyRegistrationForm()
return render_to_response('register.html', args)