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


Python UserForm.save方法代码示例

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


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

示例1: user_login

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

示例2: user_edit

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

示例3: test_user_form

# 需要导入模块: from users.forms import UserForm [as 别名]
# 或者: from users.forms.UserForm import save [as 别名]
 def test_user_form(self):
     """Test the combined User and SystersUser form"""
     form = UserForm(instance=self.user)
     self.assertEqual(type(form.systers_user_form), SystersUserForm)
     data = {'first_name': 'Foo',
             'last_name': 'Bar',
             'blog_url': 'http://example.com/'}
     form = UserForm(data=data, instance=self.user)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(self.user.first_name, 'Foo')
     self.assertEqual(self.user.last_name, 'Bar')
     systers_user = SystersUser.objects.get(user=self.user)
     self.assertEqual(systers_user.blog_url, 'http://example.com/')
开发者ID:systers,项目名称:portal,代码行数:16,代码来源:test_forms.py

示例4: registration

# 需要导入模块: from users.forms import UserForm [as 别名]
# 或者: from users.forms.UserForm import save [as 别名]
def registration(request):
    form = None

    if request.method == "POST":
        form = UserForm(request.POST)

        if form.is_valid():
            form.save()

            return redirect(reverse_lazy('user_profile'))
    else:
        form = UserForm()

    return render(request, 'user/registration.html', {'form': form})
开发者ID:stabone,项目名称:papillon,代码行数:16,代码来源:views.py

示例5: register

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

示例6: post

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

示例7: user_register

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

示例8: post

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

示例9: register_rater

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

示例10: _update

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

示例11: post

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

示例12: signup

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

示例13: register

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

示例14: user_edit

# 需要导入模块: from users.forms import UserForm [as 别名]
# 或者: from users.forms.UserForm import save [as 别名]
def user_edit(request):
    if request.method == 'POST':
        form = UserForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 _("Your data has been successfully saved."))
            return redirect('home')
    else:
        form = UserForm(instance=request.user)

    context = {
        'cancel_url': reverse('user_profile'),
        'form': form,
    }

    return render_to_response('accounts/edit.jade', context,
                              context_instance=RequestContext(request))
开发者ID:avenet,项目名称:django-project-template,代码行数:20,代码来源:views.py

示例15: registration

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


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