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


Python ProfileForm.is_valid方法代码示例

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


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

示例1: test_create_profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
    def test_create_profile(self):
        form = ProfileForm({
            'username': 'test',
            'password': 'test',
            'email': '[email protected]' })
        self.assertTrue(form.is_valid(), 'Formularz jest niepoprawny.')

        form = ProfileForm()
        self.assertFalse(form.is_valid(), 'Formularz nie jest niepoprawny.')
开发者ID:lukaszsliwa,项目名称:Mapy,代码行数:11,代码来源:tests.py

示例2: edit_profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def edit_profile(request, template_name="profile_edit.html"):
    profile = get_object_or_404(Profile, pk=1)
    CFormSet = modelformset_factory(ContactField, can_delete=True,
                                           formset=ContactsFormSet,
                                           extra=2,
                                           fields=('uid', 'contact_type'))

    if request.method == 'POST':
        postdata = request.POST.copy()
        profile_form = ProfileForm(postdata, instance=profile)
        contact_forms = CFormSet(postdata, profile=profile)
        if request.is_ajax():
            # This is for formset validation if profile form is not valid
            contact_forms.is_valid()
            if profile_form.is_valid() and contact_forms.is_valid():
                # Save changes in forms
                profile_form.save()
                contact_forms.save()

                ret = {'status': 'ok'}
            else:
                ret = {
                    'status': 'fail',
                    'profile_errors': profile_form.errors,
                    'contacts_errors': contact_forms.errors,
                    'contacts_nonform_errors': contact_forms.non_form_errors(),
                }
            json = simplejson.dumps(ret)
            return HttpResponse(json, mimetype='application/json')

        else:
            # This is for formset validation if profile form is not valid
            contact_forms.is_valid()
            if profile_form.is_valid() and contact_forms.is_valid():
                # Save changes in forms
                profile_form.save()
                contact_forms.save()
                return HttpResponseRedirect(reverse('edit_profile'))
    else:
        profile_form = ProfileForm(instance=profile)
        contact_forms = CFormSet(profile=profile)

    context_dict = {
                    'profile_form': profile_form,
                    'contatcs_forms': contact_forms,
                   }

    return render_to_response(template_name,
                              context_dict,
                              context_instance=RequestContext(request))
开发者ID:pkeeper,项目名称:42-test-keeper,代码行数:52,代码来源:views.py

示例3: registration

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def registration(request):
    if(request.user.is_authenticated()):
        return redirect(list_bundles)
    
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            form.save()
            user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
            login(request,user)
            messages.success(request, 'You have successfully registered!')
            if form.data['next']:
                return redirect(form.data['next'])
            return redirect('/')
        else:
            for error in form.non_field_errors():
                messages.error(request,error)
            return render_to_response('server/register.html',{'form': form, 'next': form.data['next']}, 
                                      context_instance=RequestContext(request))
            
    form = ProfileForm()
    if 'next' in request.GET:
        next_page = request.GET['next']
    else:
        next_page = ''
    return render_to_response('server/register.html', {'form': form, 'next': next_page}, 
                              context_instance=RequestContext(request))
开发者ID:readingr,项目名称:provenance,代码行数:29,代码来源:views.py

示例4: activate

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def activate(request, activation_key,
             template_name='userena/activate_fail.html',
             extra_context=None):
   """
   Activate a user with an activation key.
   """
   user = UserenaSignup.objects.activate_user(activation_key)
   if user:
      # Sign the user in.
      auth_user = authenticate(identification=user.username,
                               check_password=False)
      UserDetail.set_activation_datetime(auth_user)
      login(request, auth_user)
      if userena_settings.USERENA_USE_MESSAGES:
          messages.success(request, _('Congratulations -- your Art of Gratitude account is confirmed!'),
                           fail_silently=True)
      if request.method == 'POST':
         form = ProfileForm(request.POST, user=user)
         if form.is_valid():
            form.save()
      redirect_to = settings.LOGIN_REDIRECT_URL % {'username': user.username }
      return redirect(redirect_to)
   else:
      if not extra_context: extra_context = {}
      return ExtraContextTemplateView.as_view(template_name=template_name,
                                            extra_context=extra_context)(request)
开发者ID:adamfeuer,项目名称:ArtOfGratitude_app,代码行数:28,代码来源:views.py

示例5: edit

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def edit(request):
    """ Update UserProfile """

    if request.method == 'POST':
        form = ProfileForm(request.POST,
                           instance=UserProfile.objects.get(user=request.user))
        if form.is_valid(): # All validation rules pass
            try:
                User.objects.filter(email=form.cleaned_data['email']).\
                exclude(pk=request.user.pk).get()
                request.session['flash'] = ['This e-mail is already in use',
                                            'error']
                return HttpResponseRedirect(
                    request.META.get('HTTP_REFERER', '/'))
            except User.DoesNotExist:#Check if the e-mail is not already in use
                pass
            request.user.email = form.cleaned_data['email']
            request.user.save()
            form.save()
            request.session['flash'] = ['Your profile has been updated',
                                        'success']
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
    else:
        form = ProfileForm(instance=UserProfile.objects.get(user=request.user),
                           initial = {'email': request.user.email})
    return render_to_response('accounts/edit.html', {'form': form},
                              context_instance=build_context(request))
开发者ID:joskid,项目名称:snippify,代码行数:29,代码来源:views.py

示例6: contact_edit

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def contact_edit(request, first_name, last_name):
    '''
    get contact page
    @param request:
    @param first_name: Profile.first_name
    @param last_name: Profile.last_name
    '''
    profile = get_object_or_404(Mybio, 
                                pk=1)

    if request.method == "POST":
        profile_form = ProfileForm(request.POST, instance=profile)
        if profile_form.is_valid():
            profile = profile_form.save()

    if request.method == "GET":
        profile_form = ProfileForm(instance=profile)

    return {
            "profile": profile,
            "profile_form": profile_form,
            "utility_links": ((reverse('profile-view',
                                      kwargs={"first_name": profile.first_name,
                                              "last_name": profile.last_name, }), 
                              _("View profile"),
                              {}),)}
开发者ID:Desperado,项目名称:Ruslan-test-project,代码行数:28,代码来源:views.py

示例7: profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def profile(request):
    if not request.user.is_authenticated():
        raise PermissionDenied

    record = request.user.courses_taken.all()

    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            # Validate
            if form.cleaned_data['password0']:
                if form.cleaned_data['password0'] == form.cleaned_data['password1']:
                    request.user.set_password(form.cleaned_data['password0'])
                    messages.success(request, "<strong>Success!</strong> Password changed.")
                else:
                    messages.error(request, "The two passwords do not match.")
            if request.user.option != form.cleaned_data['option']:
                request.user.option = form.cleaned_data['option']
                messages.success(request, "<strong>Success!</strong> Option selected.")
            request.user.save()
            return HttpResponseRedirect(reverse('profile'))
    else:
        form = ProfileForm(initial={'option': request.user.option})
    return render_to_response(
        'student/edit-profile.html',
        {'form': form, 'record': record},
        context_instance=RequestContext(request))
开发者ID:SamArmand,项目名称:orario,代码行数:29,代码来源:views.py

示例8: edit

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def edit(request, profile_id):
    profile = UserProfile.objects.get(id=profile_id)
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            cd = form.cleaned_data

            user_profile = UserProfile.objects.get(id=profile_id)
            user_profile.pic = cd['pic']
            user_profile.url = cd['url']
            user_profile.mobile = cd['mobile']
            user_profile.save()
            return HttpResponseRedirect('/')
    else:
        form = ProfileForm(initial={
            'id': profile.id,
            'pic': profile.pic,
            'url': profile.url,
            'mobile': profile.mobile})

    args = {}
    args.update(csrf(request))

    args['form'] = form

    return render(request, "edit.html", args)
开发者ID:Alsum,项目名称:CRUD,代码行数:28,代码来源:views.py

示例9: profile_edit

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def profile_edit(request, username=None):
    if username is None:
        p = request.user.get_profile()
        user = request.user
    else:
        user = User.objects.get(username=username)
        p = user.get_profile()

    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=user)
        profile_form = ProfileForm(request.POST, instance=p, editor=request.user)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            p = profile_form.save()

            if 'is_active' in request.POST and request.user.has_perm('auth.change_user'):
                user.is_active = True
                user.save()
                send_mail(
                    "Your myschoolcommute.com account has been approved",
                    "You may login at http://%s/%s" % (request.META['HTTP_HOST'], reverse('login'),),
                    settings.SERVER_EMAIL,
                    [user.email]
                )

            return HttpResponseRedirect(reverse('user_detail', args=[user.username]))
    else:
        user_form = UserForm(instance=user)
        profile_form = ProfileForm(instance=p, editor=request.user)

    profile_form.helper.add_input(Submit('submit', 'Save account'))

    return render_to_response("accounts/edit.html", {
        'user_form' : user_form, 'profile_form': profile_form, 'user': user
    }, context_instance=RequestContext(request) )
开发者ID:MAPC,项目名称:myschoolcommute,代码行数:37,代码来源:views.py

示例10: base_profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def base_profile(request):
    f_password = forms.PasswordChangeForm(request.POST)
    f_profile = ProfileForm(instance=request.user.profile)
    f_user = UserEditForm(instance=request.user)
    commit = False
    if request.method == "POST":
        f_profile = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
        f_user = UserEditForm(request.POST, request.FILES, instance=request.user)
        if f_password.is_valid():
            f_password.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            f_profile.save(commit=True)
            commit = True
        if f_profile.is_valid():
            f_profile.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            commit = True
        if f_user.is_valid():
            user = f_user.save(commit=True)
            commit = True
    return render_to_response(
        "user/profile.html",
        {"profile": f_profile, "f_pw": f_password, "f_user": f_user, "commit": commit},
        context_instance=RequestContext(request),
    )
开发者ID:hisoka999,项目名称:silverbb,代码行数:27,代码来源:views.py

示例11: getProfile

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

    if request.method == 'POST':
        profile_form = ProfileForm(request.POST,
                                   request.FILES,
                                   instance=profile)

        user_form = UserForm(request.POST,
                             instance=request.user)
        if profile_form.is_valid() and user_form.is_valid():

            profile_form.save()
            user_form.save()

            resize_post_image.delay(profile_form.save())
            messages.success(request, _("Profile updated succesfully."))
            return redirect('index')
    else:
        profile_form = ProfileForm(instance=profile)
        user_form = UserForm(instance=request.user)

    return render(request, 'account/profile.html', {
        'formProfile': profile_form,
        'formUser': user_form
    })
开发者ID:yusufdemir,项目名称:newblog,代码行数:30,代码来源:views.py

示例12: register

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def register(request):
  if request.method == "POST":
    data = json.loads(request.raw_post_data)
    uForm = UserForm(data = data)
    pForm = ProfileForm(data = data)
    aForm = None 
    if data['artist']:
      aForm = ArtistForm(data = data)
    if uForm.is_valid() and pForm.is_valid() and (aForm == None or aForm.is_valid()):
      user = uForm.save()
      user.save()
      profile = pForm.save(commit = False)
      profile.user = user
      if not profile.invites:
        profile.invites = 0
      profile.save()
      if aForm:
        artist = aForm.save(commit = False)
        artist.profile = profile
        artist.save()
      user = authenticate(username = data['username'],
                          password = data['password1'])
      login(request, user)
      resp = HttpResponse(json.dumps({'success': 'true'}), mimetype="application/json")
      resp.status_code = 201
      return resp 
    else:
      error = dict(uForm.errors.items()
                  + pForm.errors.items())
  else:
    error = "The request must be a POST"
  resp = HttpResponse(json.dumps({'error': error}), mimetype="applcation/json")
  resp.status_code = 400
  return resp
开发者ID:baugarten,项目名称:Heartbeat,代码行数:36,代码来源:views.py

示例13: profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def profile(request): #处理个人资料功能
    if not request.user.is_authenticated():
        return redirect('/weblogin')
    user = request.user
    if request.method =='GET':
        form = ProfileForm(instance=user, initial={
            'name': user.webuser.name,
            'telephone': user.webuser.telephone,
            'hospital': user.webuser.hospital,
            'position': user.webuser.position,
            'department': user.webuser.department,
            'abstract': user.webuser.abstract
        })
        if request.user.is_superuser:
            return render(request, 'adminuser/person_page_info.html', {'form': form})
        return render(request, 'webuser/person_page_info.html', {'form': form})
    else:
        form = ProfileForm(request.POST)
        if form.is_valid():
            webuser = Webuser.objects.get(user=request.user)
            webuser.name = form.cleaned_data.get('name')
            webuser.telephone = form.cleaned_data.get('telephone')
            webuser.hospital = form.cleaned_data.get('hospital')
            webuser.position = form.cleaned_data.get('position')
            webuser.department = form.cleaned_data.get('department')
            webuser.abstract = form.cleaned_data.get('abstract')
            webuser.save()
            messages.add_message(request, messages.SUCCESS, u'您的资料已经编辑成功.')
    if request.user.is_superuser:
        return render(request, 'adminuser/person_page_info.html', {'form': form})
    else:
        return render(request, 'webuser/person_page_info.html', {'form': form})
开发者ID:541435721,项目名称:XMQB_platform,代码行数:34,代码来源:views.py

示例14: update_profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def update_profile(request):
    try:
        promoter = request.user.promoterprofile
    except PromoterProfile.DoesNotExist:
        error_meta = {
            "method": "promoter.views.update_profile",
        }
        ErrorLog.objects.create_log(4, "Promoter Object Error", error_meta, request)
        raise SuspiciousOperation('Error Code: 4')
    form = ProfileForm(request.POST or None, instance=promoter)
    context = {
        "form": form
    }
    if request.POST:
        if form.is_valid():
            form.save()
            activity_meta = {
                "method": "promoter.views.update_profile",
                "form_validation": "True"
            }
            ActivityLog.objects.create_log(request, "Update Promoter Account", activity_meta)
            return redirect('/pr/account/')
        else:
            return render(request, "promoter/edit_profile.html", context)
    else:
        activity_meta = {
            "method": "promoter.views.update_profile",
        }
        ActivityLog.objects.create_log(request, "Update Promoter Account", activity_meta)
        return render(request, "promoter/edit_profile.html", context)
开发者ID:rushil02,项目名称:Vidzert,代码行数:32,代码来源:views.py

示例15: edit

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import is_valid [as 别名]
def edit(request):
    key = ApiKey.objects.get(user = request.user)
    if request.method == 'POST':
        form = ProfileForm(request.POST,request=request)
        if form.is_valid():
            # update basic data
            email = form.cleaned_data.get("email")
            first_name = form.cleaned_data.get("first_name")
            last_name = form.cleaned_data.get("last_name")
            request.user.email = email
            request.user.first_name = first_name
            request.user.last_name = last_name
            request.user.save()
            messages.success(request, _(u"Profile updated"))
            
            # if password should be changed
            password = form.cleaned_data.get("password")
            if password:
                request.user.set_password(password)
                request.user.save()
                messages.success(request, _(u"Password updated"))
    else:
        
        form = ProfileForm(initial={'username':request.user.username,
                                    'email':request.user.email,
                                    'first_name':request.user.first_name,
                                    'last_name':request.user.last_name,
                                    'api_key': key.key},request=request)
        
    return render(request, 'mquiz/profile/profile.html', {'form': form,})
开发者ID:DigitalCampus,项目名称:django-mquiz-core,代码行数:32,代码来源:views.py


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