本文整理汇总了Python中forms.ProfileForm类的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm类的具体用法?Python ProfileForm怎么用?Python ProfileForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProfileForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate
def activate(request, activation_key,
template_name='userena/activate_fail.html',
extra_context=None):
"""
Activate a user with an activation key.
"""
user = UserenaSignup.objects.activate_user(activation_key)
if user:
# Sign the user in.
auth_user = authenticate(identification=user.username,
check_password=False)
UserDetail.set_activation_datetime(auth_user)
login(request, auth_user)
if userena_settings.USERENA_USE_MESSAGES:
messages.success(request, _('Congratulations -- your Art of Gratitude account is confirmed!'),
fail_silently=True)
if request.method == 'POST':
form = ProfileForm(request.POST, user=user)
if form.is_valid():
form.save()
redirect_to = settings.LOGIN_REDIRECT_URL % {'username': user.username }
return redirect(redirect_to)
else:
if not extra_context: extra_context = {}
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
示例2: profile
def profile(request):
if not request.user.is_authenticated():
raise PermissionDenied
record = request.user.courses_taken.all()
if request.method == 'POST':
form = ProfileForm(request.POST)
if form.is_valid():
# Validate
if form.cleaned_data['password0']:
if form.cleaned_data['password0'] == form.cleaned_data['password1']:
request.user.set_password(form.cleaned_data['password0'])
messages.success(request, "<strong>Success!</strong> Password changed.")
else:
messages.error(request, "The two passwords do not match.")
if request.user.option != form.cleaned_data['option']:
request.user.option = form.cleaned_data['option']
messages.success(request, "<strong>Success!</strong> Option selected.")
request.user.save()
return HttpResponseRedirect(reverse('profile'))
else:
form = ProfileForm(initial={'option': request.user.option})
return render_to_response(
'student/edit-profile.html',
{'form': form, 'record': record},
context_instance=RequestContext(request))
示例3: edit
def edit(request):
""" Update UserProfile """
if request.method == 'POST':
form = ProfileForm(request.POST,
instance=UserProfile.objects.get(user=request.user))
if form.is_valid(): # All validation rules pass
try:
User.objects.filter(email=form.cleaned_data['email']).\
exclude(pk=request.user.pk).get()
request.session['flash'] = ['This e-mail is already in use',
'error']
return HttpResponseRedirect(
request.META.get('HTTP_REFERER', '/'))
except User.DoesNotExist:#Check if the e-mail is not already in use
pass
request.user.email = form.cleaned_data['email']
request.user.save()
form.save()
request.session['flash'] = ['Your profile has been updated',
'success']
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
form = ProfileForm(instance=UserProfile.objects.get(user=request.user),
initial = {'email': request.user.email})
return render_to_response('accounts/edit.html', {'form': form},
context_instance=build_context(request))
示例4: profile
def profile():
if current_user.is_authenticated():
user = current_user
else:
user = None
form = ProfileForm(obj=user)
if not form.password or form.password == '':
del form.password
if form.validate_on_submit():
if user:
flash('Successfully updated your profile.')
else:
user = User()
user.role = 1
flash('Congratulations, you just created an account!')
form.populate_obj(user)
db.session.add(user)
db.session.commit()
if not current_user.is_authenticated():
login_user(user)
return redirect('/')
return render_template('demographic.html', form=form)
示例5: profile_edit
def profile_edit(request, username=None):
if username is None:
p = request.user.get_profile()
user = request.user
else:
user = User.objects.get(username=username)
p = user.get_profile()
if request.method == 'POST':
user_form = UserForm(request.POST, instance=user)
profile_form = ProfileForm(request.POST, instance=p, editor=request.user)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
p = profile_form.save()
if 'is_active' in request.POST and request.user.has_perm('auth.change_user'):
user.is_active = True
user.save()
send_mail(
"Your myschoolcommute.com account has been approved",
"You may login at http://%s/%s" % (request.META['HTTP_HOST'], reverse('login'),),
settings.SERVER_EMAIL,
[user.email]
)
return HttpResponseRedirect(reverse('user_detail', args=[user.username]))
else:
user_form = UserForm(instance=user)
profile_form = ProfileForm(instance=p, editor=request.user)
profile_form.helper.add_input(Submit('submit', 'Save account'))
return render_to_response("accounts/edit.html", {
'user_form' : user_form, 'profile_form': profile_form, 'user': user
}, context_instance=RequestContext(request) )
示例6: edit
def edit(request, profile_id):
profile = UserProfile.objects.get(id=profile_id)
if request.method == 'POST':
form = ProfileForm(request.POST, request.FILES)
if form.is_valid():
cd = form.cleaned_data
user_profile = UserProfile.objects.get(id=profile_id)
user_profile.pic = cd['pic']
user_profile.url = cd['url']
user_profile.mobile = cd['mobile']
user_profile.save()
return HttpResponseRedirect('/')
else:
form = ProfileForm(initial={
'id': profile.id,
'pic': profile.pic,
'url': profile.url,
'mobile': profile.mobile})
args = {}
args.update(csrf(request))
args['form'] = form
return render(request, "edit.html", args)
示例7: profile
def profile(req):
g = get_object_or_404(Gentleman, pk=req.user.gentleman.id)
if req.method == 'POST':
pf = ProfileForm(req.POST, req.FILES, instance=g)
if pf.is_valid():
ng = pf.save()
if 'before_pic' in req.FILES:
g.before_pic.file = req.FILES['before_pic']
if 'after_pic' in req.FILES:
g.after_pic.file = req.FILES['after_pic']
ng.user_id = g.user_id
ng.id = g.id
ng.save()
pf = ProfileForm(instance=ng)
messages.info(req, 'Gentleman updated successfully.')
else:
pf = ProfileForm(instance=g)
return render(req, 'voting/profile.html', {'pf': pf })
示例8: edit_profile
def edit_profile(request):
'''
'''
user = request.user
form = ProfileForm()
if request.method == "POST":
form = ProfileForm(request.POST, request.FILES)
if form.is_valid():
data = form.cleaned_data
'''
if len(data['name']) > NAME_MAX_LEN * 3:
messages.warning(request, u'名号输入过长,被自动截断')
if len(data['signature']) > SIGNATURE_MAX_LEN * 3:
messages.warning(request, u'签名输入过长,被自动截断')
'''
form.save(user.userprofile, data)
messages.success(request, u'个人资料修改成功')
else:
messages.error(request, u'你的输入有误')
profile = request.user.userprofile
return render_to_response('settings/edit_profile.html',
{'time_limit': PROFILE_NAME_CHANGE_DAYS,
'form': form,
'name': profile.name,
'website': profile.website,
'signature': profile.signature,
'detail': profile.detail,
},
context_instance=RequestContext(request))
示例9: profile
def profile(request):
if request.method == 'POST':
form = ProfileForm(request.POST)
buyer = request.user.buyer
if form.is_valid():
if form.cleaned_data['name'] != "":
buyer.name = form.cleaned_data['name']
if form.cleaned_data['address'] != "":
buyer.address = form.cleaned_data['address']
if form.cleaned_data['phone_number'] != "":
buyer.phone_number = form.cleaned_data['phone_number']
if form.cleaned_data['credit_card_number'] != "":
buyer.credit_card_number = form.cleaned_data['credit_card_number']
if form.cleaned_data['credit_card_exp'] != "":
buyer.credit_card_exp = form.cleaned_data['credit_card_exp']
if form.cleaned_data['credit_card_sec'] != "":
buyer.credit_card_sec = form.cleaned_data['credit_card_sec']
buyer.save()
#Process
buyer = request.user.buyer
ccn = "**** **** **** " + buyer.credit_card_number[12:17] if buyer.credit_card_number else "-"
cce = buyer.credit_card_exp if buyer.credit_card_exp else "-"
ccs = "***" if buyer.credit_card_sec else ""
defaults = {"name":buyer.name,"address":buyer.address,"phone_number":buyer.phone_number,"credit_card_number":ccn, "credit_card_expiration" : cce, "credit_card_security":ccs}
return render(request, "profile.html", {"form":form, "success":True,"defaults":defaults})
else:
return render(request, "profile.html", {"form":form, "error":True})
else:
form = ProfileForm()
buyer = request.user.buyer
ccn = "**** **** **** " + buyer.credit_card_number[12:17] if buyer.credit_card_number else "-"
cce = buyer.credit_card_exp if buyer.credit_card_exp else "-"
ccs = "***" if buyer.credit_card_sec else ""
defaults = {"name":buyer.name,"address":buyer.address,"phone_number":buyer.phone_number,"credit_card_number":ccn, "credit_card_expiration" : cce, "credit_card_security":ccs}
return render(request, "profile.html", {"form":form, "defaults":defaults})
示例10: contact_edit
def contact_edit(request, first_name, last_name):
'''
get contact page
@param request:
@param first_name: Profile.first_name
@param last_name: Profile.last_name
'''
profile = get_object_or_404(Mybio,
pk=1)
if request.method == "POST":
profile_form = ProfileForm(request.POST, instance=profile)
if profile_form.is_valid():
profile = profile_form.save()
if request.method == "GET":
profile_form = ProfileForm(instance=profile)
return {
"profile": profile,
"profile_form": profile_form,
"utility_links": ((reverse('profile-view',
kwargs={"first_name": profile.first_name,
"last_name": profile.last_name, }),
_("View profile"),
{}),)}
示例11: profile
def profile(nickname):
user = g.user
print user.nickname
form = ProfileForm()
if request.method == 'POST':
if form.validate_on_submit():
firstname = form.firstname.data
lastname = form.lastname.data
city = form.city.data
state = form.state.data
country = form.country.data
zipcode = form.zipcode.data
major = form.major.data
degree = form.degree.data
account = Account(user.id, firstname, lastname, city, state, country, zipcode, major, degree)
db.session.add(account)
db.session.commit()
return render_template('profile.html',
title=nickname,
form=form,
user=user)
return render_template('profile.html',
title=nickname,
form=form,
user=user)
示例12: register
def register(request):
if request.method == "POST":
data = json.loads(request.raw_post_data)
uForm = UserForm(data = data)
pForm = ProfileForm(data = data)
aForm = None
if data['artist']:
aForm = ArtistForm(data = data)
if uForm.is_valid() and pForm.is_valid() and (aForm == None or aForm.is_valid()):
user = uForm.save()
user.save()
profile = pForm.save(commit = False)
profile.user = user
if not profile.invites:
profile.invites = 0
profile.save()
if aForm:
artist = aForm.save(commit = False)
artist.profile = profile
artist.save()
user = authenticate(username = data['username'],
password = data['password1'])
login(request, user)
resp = HttpResponse(json.dumps({'success': 'true'}), mimetype="application/json")
resp.status_code = 201
return resp
else:
error = dict(uForm.errors.items()
+ pForm.errors.items())
else:
error = "The request must be a POST"
resp = HttpResponse(json.dumps({'error': error}), mimetype="applcation/json")
resp.status_code = 400
return resp
示例13: post
def post(self):
user = tusers.get_current_user()
if user:
form = ProfileForm(self.request.POST)
if (form.validate()):
user.full_name = form.name.data
user.current_institution = form.institution.data
user.public_profile = form.public.data
user.phone = form.phone.data
user.put()
if form.email.data:
user.change_email(form.email.data)
if form.email_code.data:
user.verify_email(form.email_code.data)
self.redirect('/update_profile')
else:
template_values = {
'user' : user,
'logout' : tusers.create_logout_url('/'),
'form' : form
}
template = JINJA_ENVIRONMENT.get_template('view/update_profile.html')
self.response.write(template.render(template_values))
else:
self.redirect(tusers.create_login_url(self.request.uri))
示例14: profile
def profile():
form = ProfileForm(request.form)
if request.method == 'POST' and form.validate():
#need to set up salalchemy and reset the redirect to a
#different url_fo()
return redirect(url_for('profile'))
return render_template('profile.html', form=form)
示例15: profile
def profile(request): #处理个人资料功能
if not request.user.is_authenticated():
return redirect('/weblogin')
user = request.user
if request.method =='GET':
form = ProfileForm(instance=user, initial={
'name': user.webuser.name,
'telephone': user.webuser.telephone,
'hospital': user.webuser.hospital,
'position': user.webuser.position,
'department': user.webuser.department,
'abstract': user.webuser.abstract
})
if request.user.is_superuser:
return render(request, 'adminuser/person_page_info.html', {'form': form})
return render(request, 'webuser/person_page_info.html', {'form': form})
else:
form = ProfileForm(request.POST)
if form.is_valid():
webuser = Webuser.objects.get(user=request.user)
webuser.name = form.cleaned_data.get('name')
webuser.telephone = form.cleaned_data.get('telephone')
webuser.hospital = form.cleaned_data.get('hospital')
webuser.position = form.cleaned_data.get('position')
webuser.department = form.cleaned_data.get('department')
webuser.abstract = form.cleaned_data.get('abstract')
webuser.save()
messages.add_message(request, messages.SUCCESS, u'您的资料已经编辑成功.')
if request.user.is_superuser:
return render(request, 'adminuser/person_page_info.html', {'form': form})
else:
return render(request, 'webuser/person_page_info.html', {'form': form})