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


Python UserForm.save方法代码示例

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


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

示例1: edit_user

# 需要导入模块: from accounts.forms import UserForm [as 别名]
# 或者: from accounts.forms.UserForm import save [as 别名]
def edit_user(request):
	profile = User_Profile.objects.get(User_associated=request.user)
	user = User.objects.get(id=request.user.id)
	# img = None

	if request.method == "POST":  
		profileForm = ProfileForm(request.POST, instance=profile, prefix="profile_form")
		userForm = UserForm(request.POST, instance=user, prefix="user_form")
		# passwordForm = PasswordChangeForm(data=request.POST, user=request.user, prefix="password_form")
		if profileForm.is_valid() and userForm.is_valid():
			profileForm.save()
			userForm.save()
			# passwordForm.save()

	else:
		profileForm = ProfileForm(prefix="profile_form", instance=profile,
				initial={"Degree": profile.Degree,
					"Year_first_enrolled": profile.Year_first_enrolled,})
		userForm = UserForm(prefix="user_form", instance=user,
			initial={'username': user.username,
					'email': user.email,
					'first_name': user.first_name,
					'last_name': user.last_name})
	   
	return render_to_response("accounts/settings.html", 
		{"profile_form": profileForm, "user_form": userForm}, context_instance=RequestContext(request))
开发者ID:ghar1821,项目名称:studyDrone,代码行数:28,代码来源:views.py

示例2: user_profile

# 需要导入模块: from accounts.forms import UserForm [as 别名]
# 或者: from accounts.forms.UserForm 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 UserForm [as 别名]
# 或者: from accounts.forms.UserForm import save [as 别名]
def profile(request):
    form = UserForm(instance=request.user)
    pwd_form = PasswordChangeForm(request.user)
    
    associations = {'twitter': False, 'google_oauth2': False, 'github': False}
    for association in request.user.social_auth.all():
        associations[association.provider.replace('-', '_')] = True
    
    if request.method == 'POST':
        if request.POST.get('do_password'):
            pwd_form = PasswordChangeForm(request.user, request.POST)

            if pwd_form.is_valid():
                pwd_form.save()
                messages.success(request, "Password successfully changed.")
            else:
                messages.error(request, "Could not update password. See errors below.")
        elif request.POST.get('do_profile'):
            form = UserForm(request.POST, instance=request.user)
        
            if form.is_valid():
                form.save()
                messages.success(request, 'Profile successfully updated.')
            else:
                messages.error(request, 'You have an error in your profile. See below errors.')
        else:
            messages.error(request, "Er, something weird happened. Contact the site admin.")
        
    
    return render(request, 'accounts/profile.html', locals())
开发者ID:nickpegg,项目名称:home,代码行数:32,代码来源:views.py

示例4: user_profile

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

    profile = request.user.get_profile()

    if request.method == "POST":
        # Read params
        form = ProfileForm(request.POST, instance=profile)
        subscriptionform = SubscriptionForm(request.POST, instance=profile)
        userform = UserForm(request.POST, instance=request.user)
        if appsettings.DEMO_SERVER and request.user.username == "demo":
            messages.warning(request, _("You can not change demo profile on the demo server."))
            return redirect("profile")

        if form.is_valid() and userform.is_valid() and subscriptionform.is_valid():
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = redirect("profile")

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _("Your profile has been updated."))

            return response
    else:
        form = ProfileForm(instance=profile)
        subscriptionform = SubscriptionForm(instance=profile)
        userform = UserForm(instance=request.user)

    social = request.user.social_auth.all()
    social_names = [assoc.provider for assoc in social]
    new_backends = [x for x in load_backends(BACKENDS).keys() if x == "email" or x not in social_names]

    response = render_to_response(
        "accounts/profile.html",
        RequestContext(
            request,
            {
                "form": form,
                "userform": userform,
                "subscriptionform": subscriptionform,
                "profile": profile,
                "title": _("User profile"),
                "licenses": Project.objects.exclude(license=""),
                "associated": social,
                "new_backends": new_backends,
            },
        ),
    )
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language)
    return response
开发者ID:spc-12,项目名称:weblate,代码行数:62,代码来源:views.py

示例5: post

# 需要导入模块: from accounts.forms import UserForm [as 别名]
# 或者: from accounts.forms.UserForm import save [as 别名]
    def post(self, request):
        profile_form = UserForm(request.POST, request.FILES, instance=request.user)

        if profile_form.is_valid():
            profile_form.save()
            return redirect('accounts_profile')
        else:
            return self._render(request, profile_form=profile_form)
开发者ID:squallcs12,项目名称:daykem,代码行数:10,代码来源:profile_view.py

示例6: register_view

# 需要导入模块: from accounts.forms import UserForm [as 别名]
# 或者: from accounts.forms.UserForm import save [as 别名]
def register_view(request):
    form = UserForm()
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponse('<h2>Thank you! You are now registered!</h2>')
    return render(request, 'accounts/registration_form.html', {'form': form})
开发者ID:jebin007,项目名称:Vehicle-Recalls,代码行数:10,代码来源:views.py

示例7: edit_profile

# 需要导入模块: from accounts.forms import UserForm [as 别名]
# 或者: from accounts.forms.UserForm import save [as 别名]
def edit_profile(request):
    if request.method == 'POST':
        form = UserForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('account')
    else:
        form = UserForm(instance=request.user)

    return render(request, 'registration/edit_profile.html', {'form':form})
开发者ID:policy-innovations,项目名称:expense-tracker,代码行数:12,代码来源:views.py

示例8: user_profile

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

    profile = request.user.get_profile()

    if request.method == "POST":
        # Read params
        form = ProfileForm(request.POST, instance=profile)
        subscriptionform = SubscriptionForm(request.POST, instance=profile)
        userform = UserForm(request.POST, instance=request.user)
        if form.is_valid() and userform.is_valid() and subscriptionform.is_valid():
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = HttpResponseRedirect(reverse("profile"))

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _("Your profile has been updated."))

            return response
    else:
        form = ProfileForm(instance=profile)
        subscriptionform = SubscriptionForm(instance=profile)
        userform = UserForm(instance=request.user)

    response = render_to_response(
        "profile.html",
        RequestContext(
            request,
            {
                "form": form,
                "userform": userform,
                "subscriptionform": subscriptionform,
                "profile": profile,
                "title": _("User profile"),
                "licenses": Project.objects.exclude(license=""),
            },
        ),
    )
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language)
    return response
开发者ID:ChrisOelmueller,项目名称:weblate,代码行数:52,代码来源:views.py

示例9: post

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

示例10: registration

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

示例11: register

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

示例13: register

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

示例14: edit_my_profile

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

示例15: register

# 需要导入模块: from accounts.forms import UserForm [as 别名]
# 或者: from accounts.forms.UserForm import save [as 别名]
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # 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 we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile 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 UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # 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

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    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:alejo8591,项目名称:backend-lab,代码行数:61,代码来源:views.py


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