当前位置: 首页>>代码示例>>Python>>正文


Python UserProfileForm.user方法代码示例

本文整理汇总了Python中forms.UserProfileForm.user方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfileForm.user方法的具体用法?Python UserProfileForm.user怎么用?Python UserProfileForm.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.UserProfileForm的用法示例。


在下文中一共展示了UserProfileForm.user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import user [as 别名]
def user_profile(request):
	user = User.objects.get_or_create(pk=request.user.id)
	if request.method == 'POST':
		form = UserProfileForm(request.POST, instance=request.user)
		if form.is_valid():
			form.save()
			form.user = request.user
			return HttpResponseRedirect('/accounts/loggedin')
	else:
		
		form= UserProfileForm(instance=request.user)
	args={}
	args.update(csrf(request))
	args['form'] = form
	return render_to_response('profile.html',args, context_instance=RequestContext(request))

# 
#   # def user_profile(request):
#     success = False
#     user = User.objects.get(pk=request.user.id)
#     if request.method == 'POST':
#         upform = UserProfileForm(request.POST, instance=user.get_profile())
#         if upform.is_valid():
#             up = upform.save(commit=False)
#             up.user = request.user
#             up.save()
#             success = True
#     else:
#         upform = UserProfileForm(instance=request.user)
# 
#     return render_to_response('profile.html',
#         locals(), context_instance=RequestContext(request))

 
#
开发者ID:avs8,项目名称:address,代码行数:37,代码来源:views.py

示例2: profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import user [as 别名]
def profile(request):
    if request.method == "POST":
        if request.user.is_authenticated(): 
	  
	    try:
	      u=User.objects.get(username=request.user.username)
	    except User.DoesNotExist:
	      u = None
	    print u
	    up=UserProfile.objects.get_or_create(user=u)[0]
	    print up
            user_profile_form=UserProfileForm(data=request.POST)
            user_profile_form.user=u
            if user_profile_form.is_valid():
                print "valid form"
                if 'avatar' in request.FILES:
		  up.location=request.POST['location']
		  #up.avatar=request.FILES['avatar'],
		  up.user_skills=request.POST['skills']
		  up.save()
		  image=request.FILES['avatar']
		  print image.content_type
		  print image.size
		  if image.content_type in ["image/jpeg","image/png","image/jpg"] and (image.size/1024) <= 1024:
		    up.avatar.save(image.name,image)		 
		  else:
		    return render_to_response('after_profile_update.html',
					  {"message": "file type is invalid or size exceeds 1 MB"},
					  RequestContext(request))
		else:
		  up.location=request.POST['location']
		  up.user_skills=request.POST['skills']
		  up_avatar=up.avatar
		  up.avatar=up_avatar
		  up.save()
                return render_to_response(
                    'after_profile_update.html',
                    {"message": "Your profile has been updated"},
                    RequestContext(request)) 
            else:
		print "the form submitted was invalid"
		print user_profile_form.errors
		#this handles the ValidationError raised in forms.py
                return render_to_response('after_profile_update.html',
					  {"message": "please enter valid data.The location and skills field are required. Profile photo is optional"},
					  RequestContext(request))
        else:
	    #the user has to login to post and is displayed the login to post message if he does so without logging in
            return HttpResponse("login to post")
    # displaying the form for the first time.
    
    else:   
	      user_profile_form = UserProfileForm()
	      return render_to_response(
	      'update_profile.html',
	      {'user_profile_form': user_profile_form},
	      RequestContext(request))
开发者ID:kavleenkalra,项目名称:AakashTechSupport,代码行数:59,代码来源:views.py


注:本文中的forms.UserProfileForm.user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。