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


Python UserProfileForm.save方法代码示例

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


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

示例1: edit

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def edit(request):
    try:
        profile = UserProfile.objects.get(pk=1)
    except UserProfile.DoesNotExist:
        raise Http404

    if 'POST' == request.method:
        form = UserProfileForm(request.POST, instance=profile)
        if request.is_ajax():
            if form.is_valid():
                form.save()
                success = True
                errors = []
            else:
                success = False
                errors = [(k, unicode(v[0])) for k, v in form.errors.items()]
            json = simplejson.dumps(({'success': success,
                                      'errors': errors, }))
            return HttpResponse(json, mimetype='application/javascript')

        else:
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/edit/saved/')
    else:
        form = UserProfileForm(instance=profile)
    return render_to_response('accounts/edit.html',
                              {'form': form},
                              context_instance=RequestContext(request))
开发者ID:xaratt,项目名称:andrytest2,代码行数:31,代码来源:views.py

示例2: user_profile

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def user_profile(request):
    """
    Form to update User profile
    """
    user_ = get_user_in_token(request)

    if request.method == 'POST':
        nic = request.POST.get('nicname')
        profileForm = UserProfileForm(request.POST, request.FILES, instance=user_.get_profile())
        userForm = UserForm(request.POST, instance=user_)
        # if profileForm.is_valid() and userForm.is_valid():
        if profileForm.is_valid():
            profileForm.save()
            userForm.save()
            return output_format_json_response(201, message='프로필이 변경 되었습니다.', statusCode='0000')
    else:
        profile = request.user.get_profile()
        profile_data = {
            'nickname': profile.nickname,
            'picture_url': profile.get_image_url(),
            'phone_number': profile.phone_number
        }
        return output_format_response(200, statusCode='0000', data=profile_data)

    return output_format_json_response(message='요청이 잘못되었습니다.', statusCode='5555')
开发者ID:btcorp,项目名称:basket-together-apiserver-django,代码行数:27,代码来源:views.py

示例3: profile

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def profile(request):
    # fetch user from db
    user = User.objects.get(pk=request.user.id)
    
    # save the forms
    if request.method == "POST":
        # create the form to edit the user
        uform = EditUserForm(data=request.POST, instance=user)
        # also edit the profile of this user
        pform = UserProfileForm(data=request.POST, instance=request.user.get_profile())

        if uform.is_valid() and pform.is_valid():
            uform.save()
            pform.save()
            messages.success(request, 'User udated.')
        else:
            messages.success(request, 'There was an error.')

    else:
        # create the form to edit the user
        uform = EditUserForm(instance=user)
        # also edit the profile of this user
        pform = UserProfileForm(instance=request.user.get_profile())
        
    ctx = {
        'user_form':uform,
        'profile_form':pform,
    }
    
    return render(request, 'accounts/profile.html', ctx)    
开发者ID:anothergituser,项目名称:django-user-app,代码行数:32,代码来源:views.py

示例4: profile_edit

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def profile_edit(request):
    profile, is_created = UserProfile.objects.get_or_create(user=request.user)

    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            messages.success(request, 'Profile 정보가 업데이트되었습니다.')
            next_url = request.GET.get('next', 'accounts.views.profile_detail')
            return redirect(next_url)
    else:
        form = UserProfileForm(instance=profile)
    return render(request, 'form.html', {
        'form': form,
    })
开发者ID:heliotherapyy,项目名称:pystagram,代码行数:17,代码来源:views.py

示例5: edit_profile

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def edit_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.SUCCESS, 'Your profile has been updated')
            return HttpResponseRedirect('/profile')
        else:
            # form = ContactView()
            # messages.add_message(request, messages.ERROR, 'Your message not sent. Not enough data')
            return render(request, 'loggedin.html', {'form': form})

    else:
        form = UserProfileForm()
        return render(request, 'loggedin.html', {'form': form})
开发者ID:Andrewsyl,项目名称:WeAreSocialDeploy-DJANGO-,代码行数:17,代码来源:views.py

示例6: user_profile

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def user_profile(request):
    if request.method == "POST":
        form = UserProfileForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            # my_form = form.save(commit=False)
            form.save()
            # messages.add_message(request, messages.SUCCESS, 'Your message has been sent. Thank you.')
            return HttpResponseRedirect("/profile")
        else:
            # form = ContactView()
            # messages.add_message(request, messages.ERROR, 'Your message not sent. Not enough data')
            return render(request, "contact.html", {"form": form})

    else:
        form = UserProfileForm()
        return render(request, "contact.html", {"form": form})
开发者ID:Andrewsyl,项目名称:wearesocial,代码行数:18,代码来源:views.py

示例7: edit_my_profile

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def edit_my_profile(request):
	u = request.user
	
	try: profile = u.get_profile()
	except UserProfile.DoesNotExist: profile = None
	
	if request.method == 'POST':
		POST = request.POST.copy()
		POST['user'] = u.id
		
		profile_form = UserProfileForm(POST, request.FILES, instance=profile)
		user_form = UserForm(request.POST, request.FILES, instance=u)
		
		if user_form.is_valid() and profile_form.is_valid():
			u = user_form.save()
			profile = profile_form.save()
			profile.user = u
			
			request.user.message_set.create(message="Your Profile was updated")
			
			return HttpResponseRedirect(profile.get_absolute_url())
	else:
		user_form = UserForm(instance=u)
		
		if profile: profile_form = UserProfileForm(instance=profile)
		else: profile_form = UserProfileForm(initial={'user':request.user})
		
	return render(request, 'edit_profile.html', {'profile_form':profile_form, 'user_form':user_form})
开发者ID:jeKnowledge,项目名称:gestor,代码行数:30,代码来源:views.py

示例8: details

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def details(request):
    ctx = {}
    form = AccountForm(instance=request.user)
    pform = UserProfileForm(instance=request.user.get_profile())
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=request.user)
        pform = UserProfileForm(request.POST,
            instance=request.user.get_profile())
        if form.is_valid() and pform.is_valid():
            form.save()
            pform.save()
            messages.info(request, _('Account updated.'))
    ctx['form'] = form
    ctx['pform'] = pform
    return render_to_response('accounts/details.html', ctx,
        context_instance=RequestContext(request))
开发者ID:Frankie-666,项目名称:locksmith,代码行数:18,代码来源:views.py

示例9: registration

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def registration(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()
            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,
            'accounts/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
开发者ID:caocaoofweimlhy,项目名称:assignment3,代码行数:32,代码来源:views.py

示例10: post

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
 def post(self, request, *args, **kwargs):
     # Attempt to grab information from the raw form information.
     # Note that we make use of both UserForm and PublicForm.
     form_args = {
         'data': request.POST,
     }
     user_form = UserForm(data=request.POST, instance=request.user)
     instance = UserProfile.objects.get(user=request.user)
     kwargs.setdefault('curruser', instance)
     profile_form = UserProfileForm(data=request.POST, instance=instance)
     # If the two forms are valid...
     if user_form.is_valid() and profile_form.is_valid():
         # Save the user's form data to the database.
         user = user_form.save()
         # Now sort out the Public instance.
         # Since we need to set the user attribute ourselves, we set commit=False.
         # This delays saving the model until we're ready to avoid integrity problems.
         profile = profile_form.save(commit=False)
         profile.user = user
         # Did the user provide a profile picture?
         # If so, we need to get it from the input form and put it in the Public model.
         if 'picture' in request.FILES:
             profile.picture = request.FILES['picture']
         # Now we save the Public model instance.
         profile.save()
 
     # Invalid form or forms - mistakes or something else?
     # Print problems to the terminal.
     # They'll also be shown to the user.
     else:
         print user_form.errors, profile_form.errors
     kwargs.setdefault("user_form", self.user_form_class(instance=instance.user))
     kwargs.setdefault("profile_form", self.profile_form_class(instance=instance))
     return super(Profile, self).get(request, *args, **kwargs)
开发者ID:jianzhi-1,项目名称:finalproject2015,代码行数:36,代码来源:views.py

示例11: register

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

    context = RequestContext(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
            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    #Render the template depending on the context

    return render_to_response('register.html',
            {'user_form':user_form,'profile_form':profile_form,
                'registered':registered}, context )
开发者ID:jetbird,项目名称:hackerscoops,代码行数:30,代码来源:views.py

示例12: register

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


			profile.save()

		else:
			print user_form.errors, profile_form.errors

	else:
		user_form = UserForm()
		profile_form = UserProfileForm()

	context = {'user_form' : user_form, 'profile_form' : profile_form}
	return render_to_response('accounts/register.html', context, context_instance=RequestContext(request))
开发者ID:alejo8591,项目名称:cidei,代码行数:33,代码来源:views.py

示例13: register

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def register(request):
    registered = False
    profile = UserProfile.objects.get(user=request.user)

    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

	    profile.save()
            registered = True

        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
            'accounts/reg.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'profile': profile,} )
开发者ID:jeylordjuls,项目名称:trial,代码行数:30,代码来源:views.py

示例14: register

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def register(request):
    if request.method == "POST":
        uform = CreateUserForm(request.POST)
        pform = UserProfileForm(request.POST)
        if uform.is_valid() and pform.is_valid():
            # create the user and redirect to profile
            user = uform.save()
            profile = pform.save(commit=False)
            profile.user = user
            profile.save()
            # this would be usefull when the profile is 
            # allready created when post_save is triggered
            # profile = user.get_profile()
            # profile.address = pform.cleaned_data['address']
            # profile.save()
            
            # login the user automatically after registering
            user = authenticate(username=user.username, password=uform.cleaned_data['password'])
            login(request, user)
            
            return HttpResponseRedirect(reverse('fi_home'))
    else:
        uform = CreateUserForm()
        pform = UserProfileForm()

    ctx = {
        'user_form':uform,
        'profile_form':pform,
    }
            
    return render(request, 'accounts/register.html', ctx)
开发者ID:anothergituser,项目名称:django-user-app,代码行数:33,代码来源:views.py

示例15: change_user_profile

# 需要导入模块: from accounts.forms import UserProfileForm [as 别名]
# 或者: from accounts.forms.UserProfileForm import save [as 别名]
def change_user_profile(request):
    """
    View for display and processing of a user profile form.
    """
    try:
        # Try to get a existing user profile
        user_profile = request.user.get_profile()
    except UserProfile.DoesNotExist:
        user_profile = None
    if request.method == 'POST':
        # Form processing
        form = UserProfileForm(request.POST)
        if form.is_valid():
            profile = form.save(commit=False)

            if user_profile:
                profile.id = user_profile.id
            profile.user = request.user
            profile.save()

    else:
        # Render the form
        form = UserProfileForm(instance=user_profile)
    return render_to_response('accounts/profile_form.html', {
        'formset': form,}, context_instance=RequestContext(request))
开发者ID:westphahl,项目名称:verleihsystem,代码行数:27,代码来源:views.py


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