本文整理汇总了Python中forms.UserProfileForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfileForm.is_valid方法的具体用法?Python UserProfileForm.is_valid怎么用?Python UserProfileForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UserProfileForm
的用法示例。
在下文中一共展示了UserProfileForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
if request.method == 'POST':
userForm = UserForm(data=request.POST)
profileForm = UserProfileForm(data=request.POST)
locationForm = LocationForm(data=request.POST)
if userForm.is_valid() and profileForm.is_valid() and \
locationForm.is_valid():
userObj = userForm.save()
userObj.set_password(userObj.password)
userObj.save()
location = locationForm.save(commit=False)
location.name = 'Home'
location.save()
profileObj = profileForm.save(commit=False)
profileObj.user = userObj
profileObj.address = location
profileObj.save()
profileObj.locations.add(location)
profileObj.save()
userObj = authenticate(username=userObj.username,
password=userObj.password)
login(request, userObj)
return render(request, 'socketbox/index.html', {})
else:
if not locationForm.is_valid():
print("Location is bad!")
print locationForm.errors
if not userForm.is_valid():
print("user is bad!")
print userForm.errors
print request.POST
if not profileForm.is_valid():
print("profile is bad!")
print profileForm.errors
return index(request)
else:
profileForm = UserProfile()
locationForm = Location()
userForm = User()
contextDict = {'profileForm': profileForm, 'locationForm': locationForm,
'userForm': userForm}
return render(request, "registration/registration_form.html", contextDict)
示例2: add_user
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def add_user(request):
if request.method == "POST":
uform = UserForm(data = request.POST)
pform = UserProfileForm(data = request.POST)
if uform.is_valid() and pform.is_valid():
user = uform.save()
user.set_password(user.password)
user.save()
profile = UserProfile(user=user,
country=pform.cleaned_data['country'],
profile=pform.cleaned_data['profile'],
dob=pform.cleaned_data['dob'])
profile.save()
return HttpResponseRedirect('/registration_success/') # Redirect after POST
data, errors = {}, {}
uform = UserForm()
pform = UserProfileForm()
pagequerydict = pushitem.objects.none()
r = makepage(request,pagequerydict,{'title':LANGUAGE['Register'],
'uform': uform,
'pform': pform,
'errors': {},},
"registration/registration_form.html",
)
return r
示例3: register
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'picture' in request.FILES:
profile.picture = request.FILES['picture']
print profile.picture
print type(profile.picture)
profile.save()
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
login(request, user)
return redirect('/blog/')
else:
print user_form.errors
error = user_form.errors.as_data().values()[0][0].messages[0]
print type(error)
return render(request, 'blog/auth/register.html',
{'error': error})
else:
return render(request, 'blog/auth/register.html')
示例4: register
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'picture' in request.FILES:
profile.picture = request.FILES['picture']
profile.save()
registered = True
else:
print user_form.errors, profile_form.errors
else:
user_form = UserForm()
profile_form = UserProfileForm()
return render(request, 'rango/register.html',
{'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
示例5: send_update_profile
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def send_update_profile(request):
if request.method == 'POST':
form = UserProfileForm(request.POST)
if form.is_valid():
userProfile = UserProfile.objects.get(user=request.user)
description = form.cleaned_data['description']
rank = form.cleaned_data['rank']
weapon = form.cleaned_data['weapon']
friend_code = form.cleaned_data['friend_code']
hunter_name = form.cleaned_data['hunter_name']
nintendo_name = form.cleaned_data['nintendo_name']
skype_name = form.cleaned_data['skype_name']
teamspeak_name = form.cleaned_data['teamspeak_name']
userProfile.description = description
userProfile.rank = rank
userProfile.weapon = weapon
userProfile.friend_code = friend_code
userProfile.hunter_name = hunter_name
userProfile.nintendo_name = nintendo_name
userProfile.skype_name = skype_name
userProfile.teamspeak_name = teamspeak_name
userProfile.save()
return redirect('/roster/profile/' + str(userProfile.id))
else:
form = UserProfileForm()
return redirect('/roster/send_update_profile/')
示例6: register
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
context = RequestContext(request)
registered = False
cat_list = get_category_list()
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'picture' in request.FILES:
profile.picture = request.FILES['picture']
profile.save()
registered = True
else:
print user_form.errors, profile_form.errors
else:
user_form = UserForm()
profile_form = UserProfileForm()
return render_to_response(
'rango/register.html',
{'user_form': user_form, 'profile_form':profile_form, 'cat_list':cat_list, 'registered': registered},
context)
示例7: user_profile
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def user_profile(request):
if request.method == 'POST':
form = UserProfileForm(request.POST, instance=request.user.profile)
if form.is_valid():
form.save()
return HttpResponseRedirect('/diary/%s' % request.user.profile.id)
else:
user = request.user
profile = user.profile
form = UserProfileForm(instance=profile)
args = {}
args.update(csrf(request))
args['form'] = form
args['username'] = request.user.username
args['user_profile_id'] = request.user.profile.id
return render_to_response('profile.html', args)
# def list_api(request):
# item_list = UserProfile.objects.all()
# output_list = []
#
# for item in item_list:
# output_item = {}
# output_item["system_id"] = item.id
# output_item["first_name"] = item.first_name
# output_list.append(output_item)
#
# return HttpResponse(
# json.dumps(output_list),
# content_type="application/json"
# )
示例8: user_profile
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def user_profile(request):
user = User.objects.get(email = request.user.email)
try:
profiles = UserProfile.objects.get(user = user)
except:
profiles = ""
if request.method == 'POST':
email = request.user.email
form = UserProfileForm(request.POST,request.FILES,instance=request.user.profile)
if form.is_valid():
save_it = form.save(commit = False)
save_it.email_id = email
save_it.save()
return HttpResponseRedirect('/profile/')
else:
user = request.user
profile = user.profile
form = UserProfileForm(instance=profile)
args = {}
args.update(csrf(request))
args['form'] = form
args['profiles'] = profiles
try:
profile_name = UserProfile.objects.get(user = user)
args['email'] = profile_name.name
except:
args['email'] = request.user.email
return render_to_response('profile/profile.html', args,context_instance=RequestContext(request))
示例9: register
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
registerd = False
context_dict = {}
context_dict["registerd"] = registerd
if request.method == "POST":
user_form = UserForm(request.POST)
profile_form = UserProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if "picture" in request.FILES:
profile.picture = request.FILES["pictures"]
profile.save()
registerd = True
context_dict["registerd"] = registerd
else:
print user_form.errors, profile_form.errors
else:
context_dict["user_form"] = UserForm
context_dict["profile_form"] = UserProfileForm
return render(request, "rango/register.html", context_dict)
示例10: user_
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def user_(request):
# user = User.objects.get(pk=get_user(request).pk)
# u_profile = MyUserModel.objects.get(user=user)
# profile_form = MultiUserForm(instance=u_profile)
# return render(request, 'userprofile/user.html', {'profile_form': profile_form})
user = User.objects.get(pk=get_user(request).pk)
try:
u_profile = MyUserModel.objects.get(user=user)
except(Exception):
u_profile = MyUserModel(user=user)
if request.method == "POST":
profile_form = UserProfileForm(request.POST, request.FILES, instance=u_profile)
if profile_form.is_valid():
profile_form.save()
user_form = UserForm(request.POST, instance=user)
if user_form.is_valid():
user_form.save(commit=False)
if "password" in request.POST:
user.set_password(request.POST["password"])
user_form.save()
else:
profile_form = UserProfileForm(instance=u_profile)
user_form = UserForm(instance=user)
return render(request, 'userprofile/user.html', {'profile_form': profile_form, 'user_form': user_form})
示例11: user_private
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def user_private(request):
if request.method == 'POST':
user_form = UserForm(request.POST, instance=request.user)
profile_form = UserProfileForm(request.POST,
instance=request.user.get_profile())
# Forms are displayed together thus both of them
# should be valid before saving the whole user data
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
profile = profile_form.save(commit=False)
profile.user = request.user
profile.save()
user_profile = request.user.get_profile()
profile_form = UserProfileForm(instance=user_profile)
user_form = UserForm(instance=request.user)
api_consumer = Consumer.objects.get(user=request.user)
api_access_token = api_consumer.token_set.get(token_type=Token.ACCESS,
user=request.user)
extra_context = {
'profile_form': profile_form,
'user_form': user_form,
'api_consumer': api_consumer,
'api_access_token': api_access_token
}
return object_detail(request, object_id=request.user.pk,
queryset=User.objects.all(),
template_name='users/user_private.html',
extra_context=extra_context)
示例12: view_profile
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def view_profile(request, pk=""):
title = "Profiles"
latest_data = fetch_latest()
if not pk:
try:
profile = request.user.get_profile()
except:
return HttpResponseRedirect(reverse('profile-home'))
else:
try:
# FIXME: UserProfile pk doesn't necessarily match that of the User's.
# Solution: Grab User(pk=pk), then UserProfile from that
profile = UserProfile.objects.get(pk=pk)
except:
return HttpResponseRedirect(reverse('profile-home'))
if request.method == 'POST':
f = UserProfileForm(request.POST, request.FILES, instance=profile)
if f.is_valid():
f.save()
else:
f = UserProfileForm(instance=profile)
# TODO: set title based on User's name
return render_to_response('profile.djt', locals(), context_instance=RequestContext(request))
示例13: signup
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def signup(request):
try:
if request.method == 'POST':
user_data = dict(zip(request.POST.keys(), request.POST.values()))
import ipdb; ipdb.set_trace()
dept_name = user_data.get('department', 'resistance') or 'resistance'
designation = user_data.get('designation', 'Engineer') or 'Engineer'
is_exists = Department.objects.filter(
designation=designation).exists()
if is_exists:
messages.error(request, """Sorry, Leader has been Set!!""")
raise Exception('Leader Exists Error.')
form = UserProfileForm(user_data)
if form.is_valid():
form.save()
user = form.instance
dept_details = {'name': dept_name,
'designation': designation,
'user': user}
dept_obj = Department.objects.create(**dept_details)
return HttpResponseRedirect(reverse('login_view'))
except Exception as ex:
print ex.message
form = UserProfileForm()
return render_to_response('registration.html', {'form': form},
context_instance=RequestContext(request))
示例14: edit_user_profile
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def edit_user_profile(request):
user = get_object_or_404(User, username=request.user.username)
profile = user.get_profile()
if request.method == "POST":
form = UserProfileForm(request.POST)
if form.is_valid():
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.email = form.cleaned_data['email']
user.save()
profile.bio = form.cleaned_data['bio']
profile.save()
return redirect("/profile/%s/" % request.user.username)
else:
pass
else:
initial_data = {
'first_name' : user.first_name,
'last_name' : user.last_name,
'email' : user.email,
'bio' : profile.bio,
}
form = UserProfileForm(initial=initial_data)
return render_to_response(
'userprofile/edit_profile.html',
{'form': form},
context_instance=RequestContext(request))
示例15: profile_set
# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def profile_set(request):
user = request.user
if not user.is_authenticated():
return HttpResponseNotFound('You must be logged in to see this page.')
profile = user.get_profile()
is_journalist = profile.is_journalist()
if request.method == 'POST': # If the form has been submitted...
profile_form = UserProfileForm(request.POST, request.FILES)
if profile_form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data and return to the admin
profile.full_name = profile_form.cleaned_data['full_name']
profile.avatar = request.POST.get('avatar')
#profile.bio = profile_form.cleaned_data['bio']
#profile.major = profile_form.cleaned_data['major']
profile.profile_set = True
user.email = profile_form.cleaned_data['email']
user.save()
profile.save()
return HttpResponseRedirect('/') # Redirect after POST
else:
if profile.profile_set == False: # if the user has not submitted their information
profile_form = UserProfileForm(initial={'full_name': profile.full_name, 'email': user.email}) # An unbound form
return render_to_response('journalism/user_profile_edit.html', {
'profile_form': profile_form,
}, context_instance=RequestContext(request))
else:
return HttpResponseRedirect('/')