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


Python forms.UserProfileForm类代码示例

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


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

示例1: post

 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,代码行数:34,代码来源:views.py

示例2: edit_my_profile

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,代码行数:28,代码来源:views.py

示例3: signup

def signup(request):
	context = {}
	context['title'] = _('Register')
	user = User()
	if request.user.is_authenticated():
		return redirect('accounts_accounts')
	userProfile = UserProfile()
	if request.method == 'POST':
		userForm = UserForm(request.POST, instance=user)
		userProfileForm = UserProfileForm(request.POST, instance=userProfile)
		if userForm.is_valid() and userProfileForm.is_valid():
			userData = userForm.cleaned_data
			user.username = userData['username']
			user.first_name = userData['first_name']
			user.last_name = userData['last_name']
			user.email = userData['email']
			user.set_password(userData['password'])
			user.save()

			userProfile = user.get_profile()
			userProfileData = userProfileForm.cleaned_data
			userProfile.gender = userProfileData['gender']
			userProfile.birthday = userProfileData['birthday']
			userProfile.save()

			user = authenticate(username=userData['username'], password=userData['password'])
			login(request, user)
			return redirect('accounts_accounts')
	else:
		userForm = UserForm(instance=user)
		userProfileForm = UserProfileForm(instance=userProfile)
	context['userForm'] = userForm
	context['userProfileForm'] = userProfileForm
	return render_to_response('accounts/register.html', context, context_instance=RequestContext(request))
开发者ID:qij3,项目名称:django-accounts,代码行数:34,代码来源:views.py

示例4: register

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,代码行数:31,代码来源:views.py

示例5: change_user_profile

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,代码行数:25,代码来源:views.py

示例6: registration

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,代码行数:30,代码来源:views.py

示例7: register

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,代码行数:28,代码来源:views.py

示例8: profile

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,代码行数:30,代码来源:views.py

示例9: register

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,代码行数:31,代码来源:views.py

示例10: test_success_user_profile_form

 def test_success_user_profile_form(self):
     """正常な入力を行いエラーにならないことを検証"""
     print('Test Case 3-1')
     print()
     profile = UserProfile()
     form = UserProfileForm(data={'work_place': self.work_place01.id, 'work_status': self.work_state01.id,  'division': self.division01.id}, instance=profile)
     self.assertTrue(form.is_valid())
开发者ID:tech-sketch,项目名称:one_month,代码行数:7,代码来源:tests.py

示例11: test_failure_user_profile_form

 def test_failure_user_profile_form(self):
     """正常ではない入力を行いエラーになることを検証"""
     print('Test Case 3-2')
     print()
     profile = UserProfile()
     form = UserProfileForm(data={'work_place': '', 'work_status': self.work_state01.id,  'division': self.division01.id}, instance=profile)
     self.assertTrue(not(form.is_valid()))
开发者ID:tech-sketch,项目名称:one_month,代码行数:7,代码来源:tests.py

示例12: register

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,代码行数:28,代码来源:views.py

示例13: user_profile

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,代码行数:25,代码来源:views.py

示例14: register

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,代码行数:59,代码来源:views.py

示例15: post

 def post(self, request, *args, **kwargs):
   self.object = self.get_object()
   form_class = self.get_form_class()
   form = self.get_form(form_class)
   user_profile_form = UserProfileForm(self.request.POST, instance=self.object.get_profile())
   if form.is_valid() and user_profile_form.is_valid():
     return self.form_valid(form, user_profile_form)
   else:
     return self.form_invalid(form, user_profile_form)
开发者ID:jaredtmartin,项目名称:writer,代码行数:9,代码来源:views.py


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