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


Python User.save方法代码示例

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


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

示例1: test_status

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
    def test_status(self):
        username = 'admin'
        password = 'station1'
        user = User(username=username)
        user.set_password(password)
        user.kind = User.ADMIN
        user.save()

        # login
        data = {'username': username, 'password': password,
                'api_key': settings.API_KEY, 'version': settings.API_VERSION}
        client = APIClient()
        client.post(reverse('register'), data, format='json')

        try:
            session = Session.objects.get(user=user)
        except:
            session = None
        else:
            url = '/api/status'
            data = {
                'token': session.token,
                'api_key': settings.API_KEY, 'version': settings.API_VERSION,
            }
            response = self.client.post(url, data)
开发者ID:azdkj532,项目名称:ntu-vote-auth-server,代码行数:27,代码来源:test.py

示例2: process_request

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def process_request(request):
    # if already logged in.
    if request.user.is_authenticated():
        return HttpResponseRedirect('/account/manage/')

    # Process the form
    form = SignupForm()
    if request.method == 'POST': # Just submitted the form
        form = SignupForm(request.POST)
        if form.is_valid():
            # create a user object
            u = User()
            # fill the user object with the data from the form
            u.username = form.cleaned_data.get('username')
            u.first_name = form.cleaned_data.get('first_name')
            u.last_name = form.cleaned_data.get('last_name')
            u.address1 = form.cleaned_data.get('address1')
            u.address2 = form.cleaned_data.get('address2')
            u.set_password(form.cleaned_data.get('password'))
            u.birth = form.cleaned_data.get('birth')
            u.phone_number = form.cleaned_data.get('phone_number')
            u.save()
            u2 = authenticate(username=form.cleaned_data.get('username'), password=form.cleaned_data.get('password'))
            login(request, u2)
            return HttpResponseRedirect('/homepage/index/')

    template_vars = {
        'SignupForm': form
    }

    return dmp_render_to_response(request, 'signup.html', template_vars)
开发者ID:ggomez1225,项目名称:chf,代码行数:33,代码来源:signup.py

示例3: process_request

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def process_request(request):
  
  #process the form
  form = SignupForm()
  if request.method == 'POST':  # just submitted the form
    form = SignupForm(request.POST)
    if form.is_valid():
      u = User()
      u.username = form.cleaned_data.get('username')
      u.first_name = form.cleaned_data.get('first_name')
      u.last_name = form.cleaned_data.get('last_name')
      u.address1 = form.cleaned_data.get('address1')
      u.address2 = form.cleaned_data.get('address2')
      u.set_password(form.cleaned_data.get('password'))
      u.save()
      # authenticate(username=form.cleaned_data.get('username'),password=form.cleaned_data.get('password'))
      # login(request, form.user)    
      # create a user object
      # fill the user object with the data from the form
      return HttpResponseRedirect('/homepage/index/')
      
  template_vars = {
    'form': form,
  }
  return dmp_render_to_response(request, 'signup.html', template_vars)
开发者ID:trev91,项目名称:CHF,代码行数:27,代码来源:signup.py

示例4: new

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def new(request):
    form = CreateUserForm()

    if request.method == "POST":
        form = CreateUserForm(request.POST)
        if form.is_valid():
            user = User()

            user.username = form.cleaned_data.get('username')
            user.set_password(form.cleaned_data.get('password'))
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.address1 = form.cleaned_data.get('address1')
            user.address2 = form.cleaned_data.get('address2')
            user.birth = form.cleaned_data.get('birth')
            user.phone_number = form.cleaned_data.get('phone_number')

            user.save()

            return HttpResponseRedirect('/manager/users')

    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'users.new.html', template_vars)
开发者ID:boxershorts7,项目名称:School,代码行数:27,代码来源:users.py

示例5: create_account

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def create_account(request):
    c = {}
    c.update(csrf(request))
    is_signed_in = request.user.is_authenticated()
    is_admin = request.user.is_superuser
    matched = False
    if request.method == 'POST':
        match = models.User.objects.filter(username=request.POST['usr'])
        if len(match) > 0:
            matched = True
            return render(request,'sign-up.html',{'signed_in': is_signed_in,'admin':is_admin, 'guest': not is_signed_in,'matched':matched})
        else:
            djuser = models.User.objects.create_user(username = request.POST['usr'],
                                                     email = request.POST['mail'],
                                                     password= request.POST['pass'],
                                                     )
            djuser.first_name = request.POST['name'],
            djuser.last_name = request.POST['lastname'],
            user = User( address = request.POST['addr'],
                         phone_num = request.POST['tel'],
                         gender = request.POST['gender'],
                         avatar = None,
                         userType = 'Normal',
                         )
            user.user = djuser
            djuser.save()
            user.save()
        is_signed_in = request.user.is_authenticated()
        is_admin = request.user.is_superuser
        return redirect('/main/')
开发者ID:hvdharya,项目名称:SysRaVi,代码行数:32,代码来源:views.py

示例6: test_null_station_id

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
    def test_null_station_id(self):
        username = 'station2'
        password = 'station2'
        user = User(username=username)
        user.set_password(password)
        user.kind = User.STATION
        user.save()

        station = Station()
        station.name = 'no name'
        station.user = user
        station.max_sessions = 3
        station.save()
        # login
        data = {'username': username, 'password': password,
                'api_key': settings.API_KEY}
        client = APIClient()
        client.post(reverse('general:register'), data, format='json')

        try:
            session = Session.objects.get(user=user)
        except:
            session = None

        data = {'token': session.token,
                'api_key': settings.API_KEY}
        response = self.client.post(self.url, data)
        self.assertEqual(response.data, {'status': 'error', 'reason': 'station_error'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
开发者ID:NTUOSC,项目名称:ntu-vote-auth-server,代码行数:31,代码来源:test.py

示例7: process_request

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def process_request(request):
    print('>>>>>>>>>>>>>>>>>>>>> THIS IS SIGNUP.PY')

    clientemail = request.POST.get('first_name')
    clientmessage = request.POST.get('last_name')
    print('>>>>>>>>>> fname was', clientemail)
    print('>>>>>>>>>> lname was', clientmessage)

    # process the form (ie validation)
    form = SignupForm()
    if request.method == 'POST': # just submitted the form
        form = SignupForm(request.POST)
        if form.is_valid():
            print('>>>>>>>>>>>>>>>>>> THE FORM IS VALID?')
            u = User()
            u.username = form.cleaned_data.get('username')
            u.first_name = form.cleaned_data.get('first_name')
            u.last_name = form.cleaned_data.get('last_name')
            u.email = form.cleaned_data.get('email')
            u.set_password(form.cleaned_data.get('password'))
            u.address1 = form.cleaned_data.get('address')
            u.address2 = form.cleaned_data.get('address2')
            u.save()
            return HttpResponseRedirect('/homepage/index/')

    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'signup.html', template_vars)
开发者ID:devin42r,项目名称:CHF,代码行数:31,代码来源:signup.py

示例8: process_request

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def process_request(request):

    form = CreateAccountForm()
    if request.method == "POST":
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            # create the user here
            u = User()
            u.username = form.cleaned_data.get("username")
            u.first_name = form.cleaned_data.get("first_name")
            u.last_name = form.cleaned_data.get("last_name")
            u.BirthDate = form.cleaned_data.get("BirthDate")
            u.Phone = form.cleaned_data.get("Phone")
            u.set_password(form.cleaned_data.get("password"))

            u.save()

            return HttpResponse(
                """
            <script>
                window.location.href = '/homepage/index/';
            </script>
          """
            )

    template_vars = {"form": form}

    return dmp_render_to_response(request, "createaccount.html", template_vars)
开发者ID:jdkoelliker,项目名称:CHFSite,代码行数:30,代码来源:createaccount.py

示例9: create

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def create(request):
    form = CreateForm()
    if request.method == 'POST':
        form = CreateForm(request.POST)
        if form.is_valid():
            u = User()
            u.username = form.cleaned_data.get('username')
            u.first_name = form.cleaned_data.get('first_name')
            u.last_name = form.cleaned_data.get('last_name')
            u.address1 = form.cleaned_data.get('address1')
            u.address2 = form.cleaned_data.get('address2')
            u.birth = form.cleaned_data.get('birth')
            u.set_password(form.cleaned_data.get('password'))
            u.save()

            u.groups.clear()
            u.user_permissions.clear()
            # print('Group name:', form.cleaned_data['groups'])
            for group in form.cleaned_data['groups']:
                print(group)  # For debugging
                u.groups.add(group)
            for permission in form.cleaned_data['permissions']:
                print(permission)  # For debugging
                u.user_permissions.add(permission)
            u.save()
            return HttpResponseRedirect('/manager/users/')

    template_vars = {
        'form':form,
}
    return dmp_render_to_response(request, 'users.create.html', template_vars)
开发者ID:lucaspcarvalho,项目名称:IS411-413,代码行数:33,代码来源:users.py

示例10: register2

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def register2(request):
    print("hhhhhhhhh====")
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
			
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            phone = uf.cleaned_data['phone']
            email = uf.cleaned_data['email']
            #将表单写入数据库
            print('1111======')
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            user.email = email
            user.save()
            print('save======')
            #返回注册成功页面
            return render(request, 'success.html', {'username':username})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf':uf})
开发者ID:xinxiang16,项目名称:website,代码行数:27,代码来源:views.py

示例11: create_users

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def create_users():
	User.objects.exclude(pk=1).delete()
	
	for pk, fields in users.iteritems():
		if pk != 1:
			if fields['email'] != '':
				existing = User.objects.filter(email = fields['email'])
				if existing.count() > 0:
					ou = existing[0]
					if ou.is_active == False and fields['is_active'] == True:
						replace_users[ou.pk] = pk
						for k,v in replace_users.iteritems():
							if v == ou.pk:
								replace_users[k] = pk
						ou.delete()
					elif ou.is_active == True and fields['is_active'] == False:
						replace_users[pk] = ou.pk
						for k,v in replace_users.iteritems():
							if v == pk:
								replace_users[k] = ou.pk
						continue
					else:
						replace_users[ou.pk] = pk
						for k,v in replace_users.iteritems():
							if v == ou.pk:
								replace_users[k] = pk
						ou.delete()

			#print "email:", fields['email']
			nu = User(pk=pk)
			nu.username = fields['username']
			if fields['email']:
				nu.email = fields['email']
				nu.status = 1
			nu.password = fields['password']
			nu.full_name = fields['profile']['full_name']
			nu.message = fields['profile']['message']
			nu.is_active = fields['is_active']
			nu.is_staff = fields['is_staff']
			nu.is_superuser = fields['is_superuser']
			nu.comment_count = fields['profile']['comment_count']
			nu.dateo_count = fields['profile']['item_count']
			nu.vote_count = fields['profile']['vote_count']
			nu.client_domain = datea
			nu.save()

			joined = date_parser(fields['date_joined'])
			lastlog = date_parser(fields['last_login'])
			User.objects.filter(pk=nu.pk).update(date_joined=joined, created=joined, last_login=lastlog)

	for pk, fields in usersSocial.iteritems():
		if fields['user'] != 1:
			nusoc = UserSocialAuth(pk=pk)
			nusoc.provider = fields['provider']
			nusoc.uid = fields['uid']
			nusoc.user_id = get_user(int(fields['user']))
			nusoc.extra_data = fields['extra_data']
			nusoc.save()
开发者ID:lafactura,项目名称:datea-migrate-db,代码行数:60,代码来源:import_data.py

示例12: process_request

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def process_request(request):
  
  #process the form
  form = CreateUserForm()
  if request.method == 'POST':  # just submitted the form
    form = CreateUserForm(request.POST)
    if form.is_valid():
      u = User()
      u.username = form.cleaned_data.get('username')
      u.first_name = form.cleaned_data.get('first_name')
      u.last_name = form.cleaned_data.get('last_name')
      u.address1 = form.cleaned_data.get('address1')
      u.address2 = form.cleaned_data.get('address2')
      u.set_password(form.cleaned_data.get('password'))
      u.email = form.cleaned_data.get('email')
      u.birth = form.cleaned_data.get('birthdate')
      u.phone_number = form.cleaned_data.get('phone_number')
      
      perms = form.cleaned_data.get('user_permissions')
      groups = form.cleaned_data.get('groups')
      u.save()
      
      u.user_permissions.clear()
      for x in perms:
        u.user_permissions.add(x)
        print(x)
        
      u.groups.clear()
      for x in groups:
        u.groups.add(x)
        print(x)
      u.save()
      
     
      
      #u2 = UserUserGroups()
      
      #u2.user_id = u.id
      #u2.permission_id = form.cleaned_data.get('user_permissions')
      #u2.group = form.cleaned_data.get('groups')
      
      #u.save()
      #u2.save()
      # authenticate(username=form.cleaned_data.get('username'),password=form.cleaned_data.get('password'))
      # login(request, form.user)    
      # create a user object
      # fill the user object with the data from the form
      return HttpResponseRedirect('/manager/users/')
      
  template_vars = {
    'form': form,
  }
  return dmp_render_to_response(request, 'userscreate.html', template_vars)
开发者ID:trev91,项目名称:CHF,代码行数:55,代码来源:userscreate.py

示例13: save

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
 def save (self):
     user = User(username=self.cleaned_data['username'],
             email=self.cleaned_data['email'],
             is_staff=self.cleaned_data['is_staff'],
             is_active=self.cleaned_data['is_active'],
             is_superuser=self.cleaned_data['is_superuser'],
             )
     user.save()
     for g in self.cleaned_data['groups']:
         user.groups.add(g)
     for p in self.cleaned_data['user_permissions']:
         user.user_permissions.add(p)
     return user
开发者ID:Czlyc,项目名称:ylinux,代码行数:15,代码来源:forms.py

示例14: register

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
def register(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            user = User()
            user.username = username
            user.password = password
            user.save()
            return render_to_response('success.html',{'username':username}, context_instance = RequestContext(request))
    else:
        uf = UserForm()
        return render_to_response('register.html', {'uf' : uf}, context_instance = RequestContext(request))
开发者ID:yfjelley,项目名称:cqt,代码行数:16,代码来源:views.py

示例15: test_user_creation

# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import save [as 别名]
 def test_user_creation(self):
     """
     Create user
     """
     u = User(username=self.user_username, email=self.user_email)
     u.set_password(self.user_password)
     u.save()
     self.assertIsNotNone(u.id)
     self.assertTrue(User.objects.filter(
         username=self.user_username).exists())
     self.assertEqual(User.objects.get(
         username=self.user_username).email, self.user_email)
     self.assertTrue(User.objects.get(username=self.user_username).is_active)
     self.assertIsNotNone(User.objects.get(
         username=self.user_username).created_at)
开发者ID:pombredanne,项目名称:snippit,代码行数:17,代码来源:test_models.py


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