• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python forms.UserForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: create_user

def create_user(request):
    if request.method == 'POST':
        uform = UserForm(data=request.POST)
        pform = UserProfileForm(data=request.POST)

        if uform.is_valid() and pform.is_valid():
            new_user = User.objects.create_user(
                username=uform.cleaned_data['username'],
                email=uform.cleaned_data['email'],
                password=uform.cleaned_data['password1'],
                first_name=uform.cleaned_data['first_name'],
                last_name=uform.cleaned_data['last_name'])
            role = pform.cleaned_data['role']
            if role == 'M':
                manager = Manager(manager=new_user)
                manager.save()
            if role == 'W':
                waiter = Waiter(waiter=new_user)
                waiter.save()
            if role == 'B':
                bartender = Bartender(bartender=new_user)
                bartender.save()
            return HttpResponseRedirect('/manager/')

    else:
        uform = UserForm(data=request.POST)
        pform = UserForm(data=request.POST)
    variables = RequestContext(request, {
        'uform': uform,
        'pform': pform
    })

    return render_to_response('create_user.html',
                              variables)
开发者ID:irin4eto,项目名称:Bar-Management,代码行数:34,代码来源:views.py


示例2: user_register

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


示例3: register

def register(request):

	Context = RequestContext(request)

	if request.method == 'POST': #user bilgilerini girmis kayit ol butonuna basmis.
		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()
            #registered = True

			profile = profile_form.save(commit = False)
			profile.user = user

			if 'picture' in request.FILES:
				profile.picture = request.FILES['picture']

			profile.save()
			return render(request, 'users/register_success.html')

		else:
			print user_form.errors, profile_form.errors

	else: # henuz yeni register ekrani goren user icin
		user_form = UserForm()
		profile_form = UserProfileForm()
        
        return render_to_response(
		'users/registration.html',
		{'user_form':user_form, 'profile_form':profile_form}, Context)
开发者ID:oystertb,项目名称:Projectdj,代码行数:33,代码来源:views.py


示例4: register

def register(request):    
    if request.method == 'POST':
        msj = {}
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        confirmation = request.POST.get('Confirmar', None)
        if  password==confirmation:
            form = UserForm(request.POST)
            existente=User.objects.filter(username=username)
            if not existente:
                if form.is_valid():
                    user = User.objects.create_user(username =username, email='None', password = password)                    
                    authenticated = authenticate(username = username, password = password)
                    auth.login(request, authenticated)
                    user.save()
                    return redirect('show_books')
            else:
                request.session['username']=username
                msj['msj'] = '<center>The username already exists</center>'
                msj['id']='error'
                return render_to_response('register.html', {'form':form, 'msj':msj}, context_instance = RequestContext(request))  
        else:
            return render_to_response('register.html', {'form':form}, context_instance = RequestContext(request))  
           
    return render_to_response('register.html', context_instance = RequestContext(request))
开发者ID:sassybat,项目名称:Bookfiles,代码行数:25,代码来源:views.py


示例5: register_rater

def register_rater(request):
    if request.method == "POST":
        user_form = UserForm(request.POST)
        rater_form = RaterForm(request.POST)
        if user_form.is_valid() and rater_form.is_valid():
            user = user_form.save()

            rater = rater_form.save(commit=False)
            rater.user = user
            rater.save()

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

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

            login(request, user)

            messages.add_message(
                request,
                messages.SUCCESS,
                "Welcome, {}. You have successfully created an account and are now logged in".format(user.username))

            return redirect('top20')
    else:
        user_form = UserForm()
        rater_form = RaterForm()
    return render(request, "users/register.html", {'user_form': user_form,
                                                   'rater_form': rater_form})
开发者ID:benred42,项目名称:django-movies,代码行数:31,代码来源:views.py


示例6: post

 def post(self, request):
     form = UserForm(request.POST)
     if form.is_valid():
         new_user = User.objects.create_user(**form.cleaned_data)
         return redirect('/users/login/?error={}'.format("signup a success! now please login") )
     else:
         return render(request, 'users/create.html', {'error':"Not a valid name or password", 'form':UserForm(request.POST) } )
开发者ID:derek-dchu,项目名称:recession_survivor,代码行数:7,代码来源:views.py


示例7: register

def register(request):

	if request.method == 'GET':
		form = UserForm()
		greeting = 'Please register an account'

		context = {
			'form': form,
			'greeting': greeting
		}
		
		return render(request, 'users/register.html', context)

	else:
		form = UserForm(request.POST)
		
		if form.is_valid():
			user = User(username=form.cleaned_data['username'],
				email=form.cleaned_data['email'], 
				first_name=form.cleaned_data['first_name'], 
				last_name=form.cleaned_data['last_name'])
			user.set_password(form.cleaned_data['password'])
			user.save()
			profile = UserProfile(user=user)
			profile.save()
			return redirect('/login/')
		else:
			context = {
				'form': form,
				'greeting': 'Invalid fields, please check errors.'
			}
			return render(request, 'users/register.html', context)
开发者ID:alexm118,项目名称:Django-Chat-App,代码行数:32,代码来源:views.py


示例8: addUser

def addUser(request):
    form = UserForm(request.POST)
    
    if form.is_valid():
        try:
            with transaction.atomic():
                enterprise = Enterprise()
                enterprise.save()
                request.session['idEnterprise'] = enterprise.id;
                
                location= Location(enterprise=enterprise, lat=0, lng=0, name='Main Office')
                location.save()
                
                user = User(location = location, email=form.cleaned_data['email'], 
                        password=form.cleaned_data['password'])
                user.save()
                request.session['idUser'] = user.id;
                
                profile = Profile(user = user, role="Administrator")
                profile.save()
                
                return render(request, 'users/dashboard.html')
                
        except Exception as e:
            print(e)
            messages.error(request, 'Sorry, Internal Error')
                
    else:
        messages.error(request, 'Please fill the form')
        return HttpResponseRedirect('/signup')
开发者ID:edramos,项目名称:path00,代码行数:30,代码来源:views.py


示例9: post

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


示例10: post

 def post(self, request, *args, **kwargs):
     user_form = UserForm(request.POST)
     user_profile_form = SignUpProfileForm(request.POST)
     if user_form.is_valid() and user_profile_form.is_valid():
         user = user_form.save()
         user_profile = UserProfile(
             user = user,
             city = user_profile_form.data['city'],
             country = user_profile_form.data['country']
         )
         try:
             user_profile.save()
             user = authenticate(
                 username=user_form.data.get('username'),
                 password=user_form.data.get('password1')
             )
             login(self.request, user)
         except:
             transaction.rollback()
         return HttpResponseRedirect(self.success_url)
     else:
         context = {}
         context['user_form'] = user_form
         context['user_profile_form'] = user_profile_form
         context['cities'] = City.objects.all()
         context['countries'] = Country.objects.all()
         return self.render_to_response(context)
开发者ID:aeroheart-c6,项目名称:alab-server,代码行数:27,代码来源:views.py


示例11: post

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


示例12: _update

def _update(request, user):
    was_superuser = user.is_superuser
    
    form = UserForm(instance = user, data = request.PUT)
    if form.is_valid():
        user = form.save()
        
        # Check if modified user is the last superuser in which case
        # his super-user status must remain True
        if was_superuser \
        and not user.is_superuser \
        and not User.objects.filter(is_superuser = True):
            message = INFO_MSG%"Au moins un utilisateur doit être super-utilisateur."
            request.user.message_set.create( message = message )
            user.is_superuser = True
            user.save()
        
        # Changes have been made.
        message = SUCCESS_MSG % "Modification effectuée avec succès."
        request.user.message_set.create( message = message )
        if request.user.is_superuser:
            return redirect( 'user_collection' )
        else:
            return redirect( 'user_edit', request.user.id )
    else:
        message = ERROR_MSG % 'Le formulaire est invalide, veuillez corriger les erreurs suivantes.'
        request.user.message_set.create( message = message )
        return direct_to_template(request, "users/edit.html", {
            'user': user,
            'form': form
        })
开发者ID:jebif,项目名称:jebif-cv,代码行数:31,代码来源:views.py


示例13: user_login

def user_login(request):

    post = request.POST.copy()

    if request.method == 'POST':

        post['username'] = post['username'].lower()
        email = post['username']
        first_name = post['first_name']

        form = UserForm(post)
        user_profile_form = UserProfileForm(post)

        if email and first_name:
            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                if form.is_valid():
                    user = form.save(commit=False)
                    user.set_password(user.username)
                    user = form.save()

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

            if user is not None:
                if user.is_active:
                    login(request, user)

                    # FIXME
                    post['user'] = user.id
                    user_profile_form = UserProfileForm(post)
                    if user_profile_form.is_valid():
                        try:
                            profile = user.get_profile()
                        except:
                            aux = UserProfile.objects
                            profile, created = aux.get_or_create(user=user)
                        newsletter = user_profile_form.clean()['newsletter']
                        profile.newsletter = newsletter
                        profile.save()

                    try:
                        spectacle = Spectacle.objects.get(status=True)
                        if spectacle.mode == SPECTACLE_MODE_EASY or \
                           spectacle.mode == SPECTACLE_MODE_RESET:
                            url = spectacle.get_easy_show_url()
                        else:
                            url = spectacle.get_hard_show_url()
                        return HttpResponseRedirect(url)
                    except Spectacle.MultipleObjectsReturned:
                        msg = '<h1>%s</h1>' % _('Spectacle not found')
                        return HttpResponseNotFound(msg)
    else:
        form = UserForm()
        user_profile_form = UserProfileForm()

    c = { 'form':form, 'user_profile_form':user_profile_form }

    return render(request, 'login.html', c)
开发者ID:guilhermecomum,项目名称:incubadora,代码行数:59,代码来源:views.py


示例14: signup

def signup(request):
    form=UserForm(request.POST or None)
    if form.is_valid():
        save_it=form.save(commit=False)
        save_it.save()
        messages.success(request,'Thank you for Joining us')
        return HttpResponseRedirect('/signup/')
    return render_to_response("signup.html",locals(),context_instance=RequestContext(request))
开发者ID:msertacturkel,项目名称:django,代码行数:8,代码来源:views.py


示例15: register

def register(request):
    context = RequestContext(request)

    # Set boolean to false
    registered = False

    # if request is post
    if request.method == 'POST':
        # Initialize forms to collect user data
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # create user and userprofile classes to add data
        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

            # retrieve profile registration information
            if 'first name' in request.FILES:
            	profile.fistName = request.FILES['first name']

            if 'last name' in request.FILES:
            	profile.lastName = request.FILES['last name']

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            if 'school' in request.FILES:
            	profile.school = request.FILES['school']

            if 'are you a teacher?' in request.FILES:
            	profile.isTeacher = request.FILES['are you a teacher?']

            profile.save()
            registered = True
            
            # logs you in if your registration details check out
            user = authenticate(username=request.POST['username'], password=request.POST['password'])
            login(request, user)
            return HttpResponseRedirect('/forum/')
        else:
            print user_form.errors, profile_form.errors

    # if request is not post
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response(
            'users/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
开发者ID:amsan7,项目名称:athena,代码行数:57,代码来源:views.py


示例16: registration

def registration(request):
    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.
            # 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.
 
            user = user_form.save(commit=False)

           # Now we hash the password with the set_password method.
            user.set_password(user.password)

            profile = profile_form.save(commit=False)

            # 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 'avatar' in request.FILES:
                profile.avatar = request.FILES['avatar']

            # Now we save the UserProfile and User model instance.
            user.save()
            profile.user = user
            profile.save()
            
            # Update our variable to tell the template registration was successful.
            messages.success(request, _('Registration successful, you can log in.'))
            return HttpResponseRedirect(reverse('users:login'))
 


        # 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( 'users/registration.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
开发者ID:laciKE,项目名称:TuristickyZapisnik,代码行数:57,代码来源:views.py


示例17: post

 def post(self, request):
     new_user = UserForm(request.POST)
     if new_user.is_valid():
         hashed = make_password(request.POST['password'])
         user = User(username=request.POST['username'], password=hashed)
         user.save()
         request.session['user_id'] = user.id
         return redirect('/characters/')
     return redirect('/users/')
开发者ID:anthonyk1225,项目名称:lifeofpy_thon,代码行数:9,代码来源:views.py


示例18: user_edit

def user_edit(request, pk):
    form = UserForm(request.POST or None, instance=User.get(pk))
    if form.is_valid():
        obj = form.save(commit=False)
        obj.save()
        return HttpResponseRedirect(reverse("user-list"))
    return direct_to_template(request, "user_edit.html", extra_context={
        "form": form,
        "nav": {"selected": "users",},
    })
开发者ID:alanjds,项目名称:arecibo,代码行数:10,代码来源:views.py


示例19: post

 def post(self,request):
     submitted_form = UserForm(request.POST)
     username = submitted_form._raw_value('username')
     password = submitted_form._raw_value('password')
     authenticated_user = authenticate(username=username, password=password)
     if authenticated_user:
         login(request,authenticated_user)
         auth_user = User.objects.filter(username=authenticated_user)[0]
         return redirect('interface:profile', username = auth_user.username)
     return redirect('interface:login')
开发者ID:ConnorH2582,项目名称:pickem_football,代码行数:10,代码来源:views.py


示例20: user_form

def user_form(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user_name = form.cleaned_data['user_name']
            password = form.cleaned_data['password']
            User.objects.create_user(user_name, password)
            return HttpResponseRedirect('../')
    else:
        form = UserForm()
    return render(request, 'users/login_or_register.html', {'form': form})
开发者ID:Effessio,项目名称:catalog,代码行数:11,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.user_link函数代码示例发布时间:2022-05-27
下一篇:
Python forms.RegistrationForm类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap