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


Python UserProfileForm.save方法代码示例

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


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

示例1: edit_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def edit_profile(request):
	if request.method == "POST":
		form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile)

		#succesful profil update view
		if form.is_valid():
			originalform = UserProfileForm(instance = request.user.profile)
			form.save()
			return HttpResponseRedirect('/accounts/profile')

	else:
		user = request.user
		profile = user.profile
		form = UserProfileForm(instance = profile)

	args = {}
	args.update(csrf(request))

	u = User.objects.get(username=user.username) # Get the first user in the system

	args['uname'] = u.username 
	args['name'] = u.first_name
	args['last'] = u.last_name
	args['email'] = u.email
	args['thumbnail'] = request.user.profile.user_avatar
	args['form'] = form

	return render_to_response('edit_profile.html', args, context_instance=RequestContext(request))
开发者ID:rajiteh,项目名称:cshub_site,代码行数:30,代码来源:views.py

示例2: login

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def login(request):  
    if request.user.is_authenticated(): # if there is a user logged in already
        user_name = UserProfile(name=request.user.username)
        
        if request.POST:
            form = UserProfileForm(request.POST, instance=user_name)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/')
        else:
            form = UserProfileForm(instance=user_name)
    
        args = {}
        args.update(csrf(request))
    
        args['form'] = UserProfileForm()
        print args
        context = {"full_name": request.user.username, "args" :args}
        return HttpResponseRedirect("", context) 
    else:
        c={}
        
        c.update(csrf(request))
        
        context = {"c": c}
        return render(request, "login.html", context)
开发者ID:ryanwongsa,项目名称:CareerStudyAdvisor,代码行数:28,代码来源:views.py

示例3: user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def user_profile():
    #修改教师/学生资料
    if request.method == 'GET':
        uid=request.args.get('id')
        if uid is None:
            return redirect("/admin/userlist")
        user=Student.query.get(uid)
        if user is None:
            user=Teacher.query.get(uid)
            if user is None:
                return redirect("/admin/userlist")
            return render_template('admin/user_profile.html',stu=None,tea=user)
        return render_template('admin/user_profile.html',stu=user,tea=None)

    form=UserProfileForm(request.form)

    if form.validate():
        form.save()
        flash(u"资料成功更新!")
    #current_app.logger.debug(3)
    for fieldName, errorMessages in form.errors.iteritems():
        for err in errorMessages:
            flash(err)
    #current_app.logger.debug(2)
    if form.stuid is not None and form.stuid.data!='':
        user=Student.query.get(form.stuid.data)
        return render_template('admin/user_profile.html',stu=user,tea=None)
    else:
        user=Teacher.query.get(form.teaid.data)
        return render_template('admin/user_profile.html',stu=None,tea=user)
开发者ID:ihciah,项目名称:xk-database,代码行数:32,代码来源:admin.py

示例4: user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [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

示例5: user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [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"
#     )
开发者ID:moniquemtucker,项目名称:simply-good,代码行数:36,代码来源:views.py

示例6: profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def profile(request):
    # We always have the user, but not always the profile. And we need a bit
    # of a hack around the normal forms code since we have two different
    # models on a single form.
    (profile, created) = UserProfile.objects.get_or_create(pk=request.user.pk)

    if request.method == "POST":
        # Process this form
        userform = UserForm(data=request.POST, instance=request.user)
        profileform = UserProfileForm(data=request.POST, instance=profile)

        if userform.is_valid() and profileform.is_valid():
            userform.save()
            profileform.save()
            return HttpResponseRedirect("/account/")
    else:
        # Generate form
        userform = UserForm(instance=request.user)
        profileform = UserProfileForm(instance=profile)

    return render_to_response(
        "account/userprofileform.html",
        {"userform": userform, "profileform": profileform},
        NavContext(request, "account"),
    )
开发者ID:a1exsh,项目名称:pgweb,代码行数:27,代码来源:views.py

示例7: user_

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [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})
开发者ID:igor-korobko,项目名称:pythontestsite,代码行数:32,代码来源:views.py

示例8: my_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def my_profile(request):
    context = get_context(request)
    if not request.user.is_authenticated():
        return redirect('login')
    else:
        user_profile = UserProfile.objects.get(user=request.user)
        if request.method == "POST":
            user_form = UserForm(request.POST, instance=request.user)
            user_profile_form = UserProfileForm(request.POST, instance=user_profile)
            if user_form.is_valid() and user_profile_form.is_valid():
                user_form.save()
                user_profile_form.save()

            return redirect_after_profile_save(request, 'data')
        else:
            user_form = UserForm(instance=request.user)
            user_profile_form = UserProfileForm(instance=user_profile)
            user_form.helper.form_tag = False
            user_profile_form.helper.form_tag = False
            context['user_form'] = user_form
            context['user_profile_form'] = user_profile_form
            context['user_profile_page_form'] = UserProfilePageForm(instance=user_profile)
            context['user_cover_letter_form'] = UserCoverLetterForm(instance=user_profile)
            context['user_info_page_form'] = UserInfoPageForm(instance=user_profile.user_info)
            context['is_editing_profile'] = True
            context['title'] = u'Mój profil'

            return render(request, 'profile.html', context)
开发者ID:Mrowqa,项目名称:aplikacjawww,代码行数:30,代码来源:views.py

示例9: view_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [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))
开发者ID:airstrike,项目名称:talkofthetown,代码行数:28,代码来源:views.py

示例10: signup

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [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))
开发者ID:Kotkar,项目名称:The-Resistance,代码行数:29,代码来源:views.py

示例11: change_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def change_profile(request):
	notifications = Notification.objects.filter(user = request.user, viewed = False).order_by('time').reverse()
	args = {}
	args.update(csrf(request))
	args['notifications'] = notifications
	if request.method == 'POST':
		form = UserProfileForm(request.POST, request.FILES, instance = request.user.profile,)
		if form.is_valid():
			form.save()
			#request.user.profile.picture = form.cleaned_data['picture']
			#request.user.profile.save()
			#messages.success(request,'You have updated the profile')
			args['form'] = form
			args['email'] = request.user.email
			args['profile'] = request.user.profile
			messages.success(request,u'修改资料成功!')
			return render(request,'page-settings.html',args)
	else:
		user = request.user
		profile = user.profile
		if profile.level:
			level = profile.level
		else:
			level = '3'
		form = UserProfileForm(instance=profile, initial={'phone':profile.phone, 'picture':profile.picture, 'level': level})

	args['form'] = form
	args['email'] = request.user.email
	args['profile'] = request.user.profile

	return render(request, 'page-settings.html',args)
开发者ID:Championzb,项目名称:TenniSoda,代码行数:33,代码来源:views.py

示例12: update_userprofileimg

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def update_userprofileimg(request):
    if request.method == "POST":
        uprofile_form = UserProfileForm(request.POST, request.FILES, instance=request.user.get_profile())
        print uprofile_form.errors
        if uprofile_form.is_valid():
            uprofile_form.save()
            
            return HttpResponseRedirect("/accounts/userinfo/" + str(request.user.id))

    raise Http404
开发者ID:swmaestro2012,项目名称:somap312_1,代码行数:12,代码来源:views.py

示例13: user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def user_profile(request):
    ensure_profile(request.user)

    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.userprofile)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.userprofile)
    return render(request, "users/user_profile.html", {"form":form})
开发者ID:Alitux,项目名称:redpanal,代码行数:12,代码来源:views.py

示例14: profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()

    else:
        form = UserProfileForm(instance=request.user)
    return render(request, "accounts/profile.html", {
        'form': form, 
        })
开发者ID:innlym,项目名称:loginhere,代码行数:13,代码来源:views.py

示例15: profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import save [as 别名]
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST, request.FILES, instance=request.user)

        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO, u'Profile was successfully updated')
    else:
        form = UserProfileForm(instance=request.user)

    return render(request, 'accounts/profile.html', {'form': form, 'user': request.user,})
开发者ID:moskrc,项目名称:django-init,代码行数:13,代码来源:views.py


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