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


Python UserProfileForm.is_valid方法代码示例

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


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

示例1: register

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
    if request.method == 'POST':
        userForm = UserForm(data=request.POST)
        profileForm = UserProfileForm(data=request.POST)
        locationForm = LocationForm(data=request.POST)

        if userForm.is_valid() and profileForm.is_valid() and \
           locationForm.is_valid():
            userObj = userForm.save()
            userObj.set_password(userObj.password)
            userObj.save()

            location = locationForm.save(commit=False)
            location.name = 'Home'
            location.save()

            profileObj = profileForm.save(commit=False)
            profileObj.user = userObj
            profileObj.address = location
            profileObj.save()
            profileObj.locations.add(location)
            profileObj.save()

            userObj = authenticate(username=userObj.username,
                                   password=userObj.password)
            login(request, userObj)

            return render(request, 'socketbox/index.html', {})
        else:
            if not locationForm.is_valid():
                print("Location is bad!")
                print locationForm.errors
            if not userForm.is_valid():
                print("user is bad!")
                print userForm.errors
                print request.POST
            if not profileForm.is_valid():
                print("profile is bad!")
                print profileForm.errors
            return index(request)
    else:
        profileForm = UserProfile()
        locationForm = Location()
        userForm = User()

    contextDict = {'profileForm': profileForm, 'locationForm': locationForm,
                   'userForm': userForm}

    return render(request, "registration/registration_form.html", contextDict)
开发者ID:justinonstine,项目名称:SocketBox,代码行数:51,代码来源:views.py

示例2: add_user

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def add_user(request):
    
    if request.method == "POST":
        uform = UserForm(data = request.POST)
        pform = UserProfileForm(data = request.POST)
        if uform.is_valid() and pform.is_valid():
            user = uform.save()
            user.set_password(user.password)
            user.save()
            profile = UserProfile(user=user,
                                  country=pform.cleaned_data['country'],
                                  profile=pform.cleaned_data['profile'],
                                  dob=pform.cleaned_data['dob'])
            profile.save()
            return HttpResponseRedirect('/registration_success/') # Redirect after POST
    
    data, errors = {}, {}
    uform = UserForm()
    pform = UserProfileForm()
    pagequerydict = pushitem.objects.none()
    r = makepage(request,pagequerydict,{'title':LANGUAGE['Register'],
                                        'uform': uform,
                                        'pform': pform,
                                        'errors': {},},
                                        "registration/registration_form.html",
                                        )
    return r
开发者ID:ASDAFF,项目名称:python-code-examples,代码行数:29,代码来源:views.py

示例3: register

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [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']
                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,代码行数:31,代码来源:views.py

示例4: register

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

            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, 'rango/register.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
开发者ID:zishanAhmad,项目名称:rango,代码行数:33,代码来源:views.py

示例5: send_update_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def send_update_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            userProfile = UserProfile.objects.get(user=request.user)
            description = form.cleaned_data['description']
            rank = form.cleaned_data['rank']
            weapon = form.cleaned_data['weapon']
            friend_code = form.cleaned_data['friend_code']
            hunter_name = form.cleaned_data['hunter_name']
            nintendo_name = form.cleaned_data['nintendo_name']
            skype_name = form.cleaned_data['skype_name']
            teamspeak_name = form.cleaned_data['teamspeak_name']
            userProfile.description = description
            userProfile.rank = rank
            userProfile.weapon = weapon
            userProfile.friend_code = friend_code
            userProfile.hunter_name = hunter_name
            userProfile.nintendo_name = nintendo_name
            userProfile.skype_name = skype_name
            userProfile.teamspeak_name = teamspeak_name
            userProfile.save()
            return redirect('/roster/profile/' + str(userProfile.id))

        else:
            form = UserProfileForm()

    return redirect('/roster/send_update_profile/')
开发者ID:FroggyRiseman,项目名称:MHC_Project,代码行数:30,代码来源:views.py

示例6: register

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def register(request):
    context = RequestContext(request)
    registered = False
    cat_list = get_category_list()

    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()

            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render_to_response(
            'rango/register.html', 
            {'user_form': user_form, 'profile_form':profile_form, 'cat_list':cat_list, 'registered': registered},
            context)
开发者ID:timkaboya,项目名称:tango_with_django,代码行数:32,代码来源:views.py

示例7: user_profile

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

示例8: user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
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,代码行数:33,代码来源:views.py

示例9: register

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
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,代码行数:28,代码来源:views.py

示例10: user_

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

示例11: user_private

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
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,代码行数:35,代码来源:views.py

示例12: view_profile

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

示例13: signup

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

示例14: edit_user_profile

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
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,代码行数:29,代码来源:views.py

示例15: profile_set

# 需要导入模块: from forms import UserProfileForm [as 别名]
# 或者: from forms.UserProfileForm import is_valid [as 别名]
def profile_set(request):
    user = request.user
    if not user.is_authenticated():
        return HttpResponseNotFound('You must be logged in to see this page.')

    profile = user.get_profile()
    is_journalist = profile.is_journalist()

    if request.method == 'POST': # If the form has been submitted...
        profile_form = UserProfileForm(request.POST, request.FILES)

        if profile_form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data and return to the admin
            profile.full_name = profile_form.cleaned_data['full_name']
            profile.avatar = request.POST.get('avatar')
            #profile.bio = profile_form.cleaned_data['bio']
            #profile.major = profile_form.cleaned_data['major']
            profile.profile_set = True

            user.email = profile_form.cleaned_data['email']
            user.save()
            profile.save()
        return HttpResponseRedirect('/') # Redirect after POST
    else:
        if profile.profile_set == False: # if the user has not submitted their information
            profile_form = UserProfileForm(initial={'full_name': profile.full_name, 'email': user.email}) # An unbound form
            return render_to_response('journalism/user_profile_edit.html', {
               'profile_form': profile_form,
            },  context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect('/')
开发者ID:CoJMC,项目名称:jaam,代码行数:33,代码来源:views.py


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