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


Python forms.UserProfileForm类代码示例

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


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

示例1: edit_user_profile

def edit_user_profile(request):
    user = get_object_or_404(User, username=request.user.username)
    profile = user.get_profile()
    if request.method == "POST":
        form = UserProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.save()
            profile.bio = form.cleaned_data['bio']
            profile.save()
            return redirect("/profile/%s/" % request.user.username)
        else:
            pass
    else:
        initial_data = {
            'first_name' : user.first_name,
            'last_name' : user.last_name,
            'email' : user.email,
            'bio' : profile.bio,
            }
        form = UserProfileForm(initial=initial_data)
    return render_to_response(
        'userprofile/edit_profile.html', 
        {'form': form},
        context_instance=RequestContext(request))
开发者ID:jpittman,项目名称:elephant-talk,代码行数:27,代码来源:views.py

示例2: login

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

示例3: 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']
                print profile.picture
                print type(profile.picture)
            profile.save()
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('/blog/')
        else:
            print user_form.errors
            error = user_form.errors.as_data().values()[0][0].messages[0]
            print type(error)
            return render(request, 'blog/auth/register.html',
                          {'error': error})
    else:
        return render(request, 'blog/auth/register.html')
开发者ID:BaichuanWu,项目名称:Blog_on_django,代码行数:29,代码来源:views.py

示例4: user_profile

def user_profile(request):
    if request.session['email']:
        if request.method =='POST':
            a=Join.objects.get(email=request.session['email'])
            try:
                b=UserProfile.objects.get(user=a)
            except:
                b = UserProfile(user=a)
                b.save()
                b=UserProfile.objects.get(user=a)
            form = UserProfileForm(request.POST,instance=b)
            if form.is_valid():
                f= form.save(commit=False)
                f.user=a
                f.save()
                return HttpResponseRedirect('/fb/login/')
            else:
                return render(request,'fb/profile.html',{'form':form})
        else:
            a=Join.objects.get(email=request.session['email'])
            try:
                b=UserProfile.objects.get(user=a)
            except:
                b = UserProfile(user=a)
                b.save()
                b=UserProfile.objects.get(user=a)
            form=UserProfileForm(instance=b)
            return render(request,'fb/profile.html',{'form':form})
    else:
        return HttpResponseRedirect('/fb/login/')
开发者ID:shekhar-singh,项目名称:learning,代码行数:30,代码来源:views.py

示例5: my_profile

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

示例6: profile

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

示例7: edit_profile

def edit_profile(request):

    user = User.objects.get(username=request.user)

    if request.method == "POST":
        form = UserProfileForm(request.POST, request.FILES)
        if form.is_valid():

            model_instance = form.save(commit=False)
            user_profile = UserProfile.objects.filter(user=user)[0]
            model_instance.id = user_profile.id
            model_instance.user_id = user_profile.user_id
            if request.FILES:
                model_instance.picture = request.FILES['picture']
            else:
                model_instance.picture = user_profile.picture

            if request.POST['description']:
                model_instance.description = request.POST['description']
            else:
                model_instance.description = user_profile.description

            model_instance.save()

            message = 'Your edit was successful!'

            context = {'message' : message, 'model_instance' : model_instance}
            return render(request, "thanks.html", context)
    else:
        form = UserProfileForm()

    context = { 'form' : form}

    return render(request, "edit_profile.html", context)
开发者ID:Gorgel,项目名称:khd_projects,代码行数:34,代码来源:views.py

示例8: register

def register(request):
    registerd = False
    context_dict = {}
    context_dict["registerd"] = registerd
    if request.method == "POST":
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(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["pictures"]
            profile.save()
            registerd = True
            context_dict["registerd"] = registerd
        else:
            print user_form.errors, profile_form.errors
    else:
        context_dict["user_form"] = UserForm
        context_dict["profile_form"] = UserProfileForm

    return render(request, "rango/register.html", context_dict)
开发者ID:avinashdevicode,项目名称:tangoWorkSpace,代码行数:26,代码来源:views.py

示例9: user_profile

def user_profile(request):
	user = User.objects.get(email = request.user.email)
	try:
		profiles = UserProfile.objects.get(user = user)
	except:
		profiles = ""
	if request.method == 'POST':
		email = request.user.email
		form = UserProfileForm(request.POST,request.FILES,instance=request.user.profile)
		if form.is_valid():
			save_it = form.save(commit = False)
			save_it.email_id = email
			save_it.save()

			return HttpResponseRedirect('/profile/')

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

	args = {}
	args.update(csrf(request))
	args['form'] = form
	args['profiles'] = profiles
	try:
		profile_name = UserProfile.objects.get(user = user)
		args['email'] = profile_name.name
	except:
		args['email'] = request.user.email
	return render_to_response('profile/profile.html', args,context_instance=RequestContext(request))
开发者ID:VigneshBalakrishnan,项目名称:raids,代码行数:31,代码来源:views.py

示例10: user_

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

示例11: profile

def profile():
    u = g.user
    mc = g.user.mark_count()
    bc = g.user.bookmark_count()
    fc = g.user.feed_count()
    lcm = g.user.mark_last_created()
    form = UserProfileForm(obj=u)
    if form.validate_on_submit():
        form.populate_obj(u)
        if form.password.data:
            pm = bMan()
            u.password = pm.encode(form.password.data)
        else:
            del u.password
        db.session.add(u)
        db.session.commit()
        flash('User %s updated' % (form.username.data), category='info')
        return redirect(url_for('profile'))
    return render_template('account/profile.html',
                           form=form,
                           title='Profile',
                           mc=mc,
                           bc=bc,
                           fc=fc,
                           lcm=lcm,
                           )
开发者ID:Cuahutli,项目名称:Flaskmarks,代码行数:26,代码来源:views.py

示例12: user_private

def user_private(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = UserProfileForm(request.POST,
                                       instance=request.user.get_profile())
        
        # Forms are displayed together thus both of them
        # should be valid before saving the whole user data
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile =  profile_form.save(commit=False)
            profile.user = request.user
            profile.save()
    
    user_profile = request.user.get_profile()
    profile_form = UserProfileForm(instance=user_profile)
    user_form = UserForm(instance=request.user)
    
    api_consumer = Consumer.objects.get(user=request.user)
    api_access_token = api_consumer.token_set.get(token_type=Token.ACCESS,
                                                     user=request.user)
        
    extra_context = {
        'profile_form': profile_form,
        'user_form': user_form,
        'api_consumer': api_consumer,
        'api_access_token': api_access_token
    }
    
    return object_detail(request, object_id=request.user.pk,
                         queryset=User.objects.all(),
                         template_name='users/user_private.html',
                         extra_context=extra_context)
开发者ID:aregee,项目名称:network-admin,代码行数:33,代码来源:views.py

示例13: view_profile

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

示例14: signup

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

示例15: 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(request.POST,request.FILES)
       # p = UserProfileForm(data=request.FILES)
        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():# and p.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:
               # p.picture = request.FILES['picture']
               # p.save()
               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(
            'registration.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
开发者ID:aashitadutta,项目名称:Q-Aforum,代码行数:60,代码来源:views.py


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