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


Python ProfileForm.is_valid方法代码示例

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


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

示例1: user_register

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def user_register(request):
    if request.method == "GET":
        user_form = UserForm()
        profile_form = ProfileForm()
    elif request.method == "POST":
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(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
            profile.save()

            password = user.password
            # The form doesn't know to call this special method on user.
            user.set_password(password)
            user.save()

            # You must call authenticate before login. :(
            user = authenticate(username=user.username,
                                password=password)
            login(request, user)
            messages.add_message(
                request,
                messages.SUCCESS,
                "Congratulations, {}, on creating your new account! You are now logged in.".format(
                    user.username))
            return redirect('index')
    return render(request, "users/register.html", {'user_form': user_form,
                                                   'profile_form': profile_form})
开发者ID:Callus4815,项目名称:mowdie,代码行数:32,代码来源:views.py

示例2: post

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
    def post(self, request):
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(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
            profile.save()

            password = user.password
            user.set_password(password)
            user.save()

            user = authenticate(username=user.username,
                                password=password)

            login(self.request, user)
            messages.add_message(
                request,
                messages.SUCCESS,
                "Account Successfully Created.")
            return redirect("/")

        else:
            return render(request, "users/register.html", {"form1": user_form, "form2": profile_form})
开发者ID:IHautaI,项目名称:stat_tracker,代码行数:27,代码来源:views.py

示例3: edit_profile

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def edit_profile(request):
    user = request.user
    users = User.objects.get(username=user)
    profile = Profile.objects.get(user=user)
    group = Group.objects.get(name='user')
    user_members = group.user_set.all()
    if user in user_members:
        if request.method == 'POST':
            form1 = EditUserForm(request.POST, instance=users)
            form2 = ProfileForm(request.POST, instance=profile)
            if form1.is_valid() and form2.is_valid():
                form2.save()
                form1.save()
                return HttpResponseRedirect('/')
        else:
     	    form1 = EditUserForm(instance=users)
       	    form2 = ProfileForm(instance=profile)
       	variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1, 'form2':form2})
    else:
    	if request.method == 'POST':
    		form1 = MerchantForm(request.POST, instance=users)
    		if form1.is_valid():
    			form1.save()
    			return HttpResponseRedirect('/')
    	else:
    		form1 = MerchantForm(instance=users)

        variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1})
    return render_to_response('users/edit_profile.html', variables)
开发者ID:sivajipr,项目名称:flipkart,代码行数:31,代码来源:views.py

示例4: post

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
 def post(self, request):
     if request.GET.get('login'):
         self.post_login(request)
         username = request.POST.get('username')
         password = request.POST.get('password')
         user = authenticate(username=username, password=password)
         if user:
             if user.is_active:
                 login(request, user)
                 return redirect('tasks:index')
         return render(request, 'users/login.html', {'user_form': UserForm(), 'profile_form': ProfileForm()})
     else:
         user_form = UserForm(data=request.POST)
         profile_form = ProfileForm(data=request.POST)
         if user_form.is_valid() and profile_form.is_valid():
             with atomic():
                 user = user_form.save()
                 user.set_password(user.password)
                 user.save()
                 profile = profile_form.save(commit=False)
                 profile.user = user
                 profile.creating = True
                 profile.updating = True
                 thread = Thread()
                 thread.save()
                 profile.thread = thread
                 profile.save()
             login(request, user)
             return redirect('tasks:index')
         else:
             return render(request, 'users/login.html', {'user_form':user_form, 'profile_form': profile_form})
开发者ID:ivegor,项目名称:trello,代码行数:33,代码来源:views.py

示例5: edit_profile

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def edit_profile(request):
    """Edit user profile."""
    try:
        user_profile = request.user.get_profile()
    except Profile.DoesNotExist:
        # TODO: Once we do user profile migrations, all users should have a
        # a profile. We can remove this fallback.
        user_profile = Profile.objects.create(user=request.user)

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES, instance=user_profile)
        if form.is_valid():
            user_profile = form.save()
            new_timezone = user_profile.timezone
            if request.session.get('timezone', None) != new_timezone:
                request.session['timezone'] = new_timezone
            return HttpResponseRedirect(reverse('users.profile',
                                                args=[request.user.id]))
    else:  # request.method == 'GET'
        form = ProfileForm(instance=user_profile)

    # TODO: detect timezone automatically from client side, see
    # http://rocketscience.itteco.org/2010/03/13/automatic-users-timezone-determination-with-javascript-and-django-timezones/

    return jingo.render(request, 'users/edit_profile.html',
                        {'form': form, 'profile': user_profile})
开发者ID:Disabledpeople,项目名称:kitsune,代码行数:28,代码来源:views.py

示例6: post

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
    def post(self, *args, **kwargs):
        if not self.request.user.is_authenticated():
            return self.render({'error': 'Please log in before posting'})

        form = ProfileForm(data=json.load(self.request), instance=self.request.user)
        if form.is_valid():
            form.save()
            return self.get(*args, **kwargs)
        else:
            return self.render({'error': 'Data is invalid', 'errors_list': form.errors})
开发者ID:PythonEcuador,项目名称:eyes-of-time,代码行数:12,代码来源:views.py

示例7: save

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def save(request, user_id): # action
	# saves changes to user profile
	user = get_object_or_404(User, pk=user_id)
	userProfile = Profile.objects.get(user=user)
	if request.method == 'POST':
		form = ProfileForm(request.POST,instance=userProfile)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(reverse('users:profile', args=[user_id]))
		else:
			
			return HttpResponseRedirect(reverse('users:edit', args=[user_id]))
开发者ID:kmartine,项目名称:pushpin-d,代码行数:14,代码来源:views.py

示例8: handle_profile_save

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def handle_profile_save(request):
    """Edit or create a user profile."""
    profile = request.user.get_profile()
    if request.method == 'POST':
        form = ProfileForm(data=request.POST,
                           files=request.FILES,
                           instance=profile)
        if form.is_valid():
            profile = form.save(commit=False)
            profile.user = request.user
            profile.save()
        return form
    return ProfileForm(instance=profile)
开发者ID:ozten,项目名称:betafarm,代码行数:15,代码来源:utils.py

示例9: save_settings

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def save_settings(request):
    if not request.user.is_authenticated():  # XXX improve this
        return {'error': 'Not logged in'}
    from users.forms import ProfileForm
    profile = request.user.get_profile()
    form = ProfileForm(instance=profile, data=request.POST)
    if form.is_valid():
        profile = form.save(commit=False)
        profile.country = form.cleaned_data['country']
        profile.save()
        return {'ok': True}
    else:
        return {'form_errors': form.errors}
开发者ID:mozilla,项目名称:pto,代码行数:15,代码来源:views.py

示例10: edit_profile

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def edit_profile(request):
    profile = get_profile(request.user)

    if request.method == "GET":
        profile_form = ProfileForm(instance=profile)
    elif request.method == "POST":
        profile_form = ProfileForm(instance=profile, data=request.POST)
        if profile_form.is_valid():
            profile_form.save()
            messages.add_message(request, messages.SUCCESS,
                                 "Your profile has been updated.")

    return render(request, "users/edit_profile.html", {"form": profile_form})
开发者ID:Callus4815,项目名称:mowdie,代码行数:15,代码来源:views.py

示例11: lk

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def lk(request):
    c = get_common_context(request)
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/')
    if request.method == 'GET':
        c['form'] = ProfileForm(instance=request.user.get_profile())
    else:
        form = ProfileForm(request.POST, instance=request.user.get_profile())
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/lk/')
        c['form'] = form
    return render_to_response('lk.html', c, context_instance=RequestContext(request))
开发者ID:kpx13,项目名称:galant,代码行数:15,代码来源:views.py

示例12: user_edit

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def user_edit(request, pk):
    user = User.get(pk)
    form = UserForm(request.POST or None, instance=user)
    profile = ProfileForm(request.POST or None, instance=get_profile(user))
    if form.is_valid() and profile.is_valid():
        form.save()
        profile.save()
        return HttpResponseRedirect(reverse("user-list"))
    return direct_to_template(request, "user_edit.html", extra_context={
        "form": form,
        "profile": profile,
        "nav": {"selected": "users",},
    })
开发者ID:andymckay,项目名称:arecibo,代码行数:15,代码来源:views.py

示例13: register

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def register(request):
    c = get_common_context(request)
    register_form = ProfileForm()
    c['register_form'] = register_form
    auth_form = AuthenticationForm()
    c['auth_form'] = auth_form
    
    if request.method == "POST":
        if request.POST['action'] == 'register':
            register_form = ProfileForm(request.POST, request.FILES)
            if register_form.is_valid():
                error = False
                if len(User.objects.filter(username=register_form.data.get('email'))):
                    register_form._errors["email"] = ErrorList([u'Такой емейл уже зарегистрирован.'])
                    error = True
                if not error:
                    email = register_form.data.get('email')
                    u = User(username= email, 
                             email=email,
                             first_name=register_form.data.get('fio'))
                    password = password_generator()
                    u.set_password(password)
                    u.save()
                    p = register_form.save(commit=False)
                    p.user = u
                    p.save()
                    user = auth.authenticate(username=email, password=password)
                    auth.login(request, user)
                    
                    p.send(password)
                    
                    return HttpResponseRedirect('/edu/')
            c['register_form'] = register_form
        elif request.POST['action'] == 'auth':
            auth_form = AuthenticationForm(request.POST)
            if auth_form.is_valid():
                pass
            username = request.POST.get('username', '')
            password = request.POST.get('password', '')
            user = auth.authenticate(username=username, password=password)
            if user is not None:
                auth.login(request, user)
                return HttpResponseRedirect('/edu/')
            else:
                auth_form._errors = {}
                auth_form._errors["username"] = ErrorList([u'Неверный логин или пароль.'])
            c['auth_form'] = auth_form
    
    c['title'] = u'Регистрация'
    
    return render_to_response('register.html', c, context_instance=RequestContext(request))
开发者ID:kpx13,项目名称:vv,代码行数:53,代码来源:views.py

示例14: reg_page

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def reg_page(request):
    c = get_common_context(request)
    
    if request.method == 'GET':
        client_form = ClientForm()
        profile_form = ProfileForm()
        user_form = UserForm()
    elif request.method == 'POST':
        client_form = ClientForm(request.POST)
        profile_form = ProfileForm(request.POST)
        user_form = UserForm(request.POST)
        if request.POST.get('confirm', None) is None:
            user_form.errors['confirm'] = ErrorList([u'Необходимо согласиться с договором.'])
        elif user_form.data['passwd1'] != user_form.data['passwd2']:
            user_form.errors['passwd1'] = ErrorList([u'Пароли не совпадают.'])
        elif not user_form.data['email']:
            user_form.errors['email'] = ErrorList([u'Обязательное поле.'])
        elif client_form.is_valid() and profile_form.is_valid() and user_form.is_valid():
            try:
                u = auth.models.User(username=user_form.data['email'],
                                     email=user_form.data['email'],
                                     first_name=user_form.data['first_name'],
                                     )
                u.save()
                u.set_password(user_form.data['passwd1'])
                u.save()
            except:
                u = None
                user_form.errors['email'] = ErrorList([u'Пользователь с таким email уже существует'])
                
            if u: # user saved, all is right
                p = u.get_profile()
                p.phone = profile_form.data['phone']
                p.work_phone=profile_form.data['work_phone']
                p.qiwi=profile_form.data['qiwi']
                p.user = u
                p.type = 'c'
                p.save()

                Client.add(u, client_form.data['name'])
                user = auth.authenticate(username=user_form.data['email'], password=user_form.data['passwd1'])
                auth.login(request, user)
                messages.success(request, u'Вы успешно зарегистрировались в системе в качестве клиента.')
                return HttpResponseRedirect('/cabinet')
    
    c['client_form'] = client_form
    c['profile_form'] = profile_form
    c['user_form'] = user_form
    
    return render_to_response('client/reg.html', c, context_instance=RequestContext(request))
开发者ID:kpx13,项目名称:derm_svp,代码行数:52,代码来源:client_views.py

示例15: edit_profile

# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import is_valid [as 别名]
def edit_profile(request):
    try:
        profile = Profile.objects.get(user=request.user)
    except Profile.DoesNotExist:
        raise Http404
    if request.method == 'POST':
        form = ProfileForm(data=request.POST, files=request.FILES, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/user/')
    else:
        print profile
        form = ProfileForm(instance=profile)
    return render(request, 'profiles/edit_profile.html', {"profile": profile, "form": form})
开发者ID:xtranophilist,项目名称:reelphil,代码行数:16,代码来源:views.py


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