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


Python User.get方法代码示例

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


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

示例1: test_user_get_userid

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
    def test_user_get_userid(self):
        # Handler for `user2 = User.get(...)`
        Entry.single_register(
            Entry.POST,
            self.lastuser.endpoint_url(current_app.lastuser_config['getuser_userid_endpoint']),
            body=json.dumps({
                "status": "ok",
                "type": "user",
                "buid": "1234567890123456789012",
                "userid": "1234567890123456789012",
                "name": "user1",
                "title": "User 1",
                "label": "User 1 (@user1)",
                "oldids": ['0987654321098765432109'],
                "timezone": "Asia/Kolkata",
                }),
            headers={'content-type': 'application/json'}
            )

        user1 = User.get(userid=u"1234567890123456789012")
        user2 = User.get(userid=u"0987654321098765432109")
        user3 = User.get(userid=u"1234567890987654321234")

        self.assertEqual(user1, self.user1)
        self.assertEqual(user2, self.user1)  # Merged, so returns .merged_user()
        self.assertEqual(user3, self.user3)
开发者ID:hasgeek,项目名称:flask-lastuser,代码行数:28,代码来源:test_mergeuser.py

示例2: list

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def list():
    """Seznam lektorů """
    
    
    if request.params.get("promote"):
        lec = User.get( request.params.get("promote") )
        lec.addRole("master")
        msg("Lektor %s byl povýšen" % lec.login,"success")
        redirect(request.path)
        
    if request.params.get("degrade"):
        lec = User.get( request.params.get("degrade") )
        lec.removeRole("master")
        msg("Lektor %s byl ponížen :-)" % lec.login,"success")
        redirect(request.path)       
    
    # vložení nového lektora
    if request.forms.get("add"):
        login =  request.forms.decode().get("add")
        usr = User.insertLector(login, psw = login )
        if usr:
            msg("Lektor '%s' vytvořen" % usr.login, "success")
            msg("Heslo pro nového lektora bylo nastaveno na '%s'" % usr.login, "info")
        else:
            msg("Chyba při vytváření lektora","error")
        redirect("/lectors")
        
    lectors = User.getLectors() 
    
    return template("lectors", {"lectors" : lectors } )
开发者ID:Tezar,项目名称:Assigment-generator,代码行数:32,代码来源:user.py

示例3: chat

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def chat():

	# Require login
	if 'username' not in session:
		return redirect('/login/')

	# Get chat buddy
	name_them = request.args.get('user', None)
	user_them = None
	if name_them:
		try:
			user_them = User.get(User.username == name_them)
		except:
			pass

	# Bad user - add error
	if not user_them:
		if name_them:
			errors = ["Could not find user %s." % name_them]
		else:
			errors = ["Please specify a user to chat with."]
		return render_template('chat.html', data={'errors': errors});

	# Chat avatars
	user_you = User.get(User.username == session['username'])

	return render_template('chat.html', data={'yourPic': user_you.imageUrl, 'theirPic': user_you.imageUrl, 'otherUsername': name_them, 'myLanguage': user_you.language })
开发者ID:ace-n,项目名称:wildhacks-fa14,代码行数:29,代码来源:main.py

示例4: exists

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
 def exists(cls,iid,table):
     if table == "match":
         try:
             Match.get(iid=iid)
         except Match.DoesNotExist:
             return False
     if table == "odd":
         try:
             Odd.get(iid=iid)
         except Odd.DoesNotExist:
             return False
     if table == "cat":
         try:
             OddCategory.get(idd=iid)
         except OddCategory.DoesNotExist:
             return False
     if table == "result":
         try:
             Result.get(iid=iid)
         except Result.DoesNotExist:
             return False
     if table == "user":
         try:
             User.get(iid=iid)
         except User.DoesNotExist:
             return False
     return True
开发者ID:Okiria,项目名称:betting,代码行数:29,代码来源:sync.py

示例5: __call__

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
 def __call__(self, form, field):
     try:
         User.get(User.email == field.data)
     except Exception:
         pass
     else:
         raise ValidationError('User with this email already exists')
开发者ID:bequ1ck,项目名称:tornado-redis-angular-chat,代码行数:9,代码来源:forms.py

示例6: test_user_get_username

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
    def test_user_get_username(self):
        user1 = User.get(username=u'user1')
        user2 = User.get(username=u'user2')
        user3 = User.get(username=u'user3')

        self.assertEqual(user1, self.user1)
        self.assertEqual(user2, None)  # Username doesn't exist anymore
        self.assertEqual(user3, self.user3)
开发者ID:EugeneLiang,项目名称:flask-lastuser,代码行数:10,代码来源:test_mergeuser.py

示例7: test_user_get_userid

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
    def test_user_get_userid(self):
        user1 = User.get(userid=u"1234567890123456789012")
        user2 = User.get(userid=u"0987654321098765432109")
        user3 = User.get(userid=u"1234567890987654321234")

        self.assertEqual(user1, self.user1)
        self.assertEqual(user2, self.user1)  # Merged, so returns .merged_user()
        self.assertEqual(user3, self.user3)
开发者ID:EugeneLiang,项目名称:flask-lastuser,代码行数:10,代码来源:test_mergeuser.py

示例8: profile_post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def profile_post():

	# Get POST data
	userName = request.form["username"]
	curPw = request.form["curPassword"]
	newPw = request.form["newPassword"]
	imageUrl = request.form["imageUrl"]
	language = request.form["language"]

	# Verify passwords
	errors = verifyLength("Current Password", curPw, 5, 64)
	if len(newPw) != 0:
		errors = verifyLength("New Password", newPw, 5, 64)

	# Verify image URL
	errors.extend(verifyLength("Avatar URL", imageUrl, 10, 256))
	if not urlparse(imageUrl):
		errors.append("Invalid Avatar URL.")

	# Verify username
	errors.extend(verifyLength("Username", userName, 5, 64))
	if not re.search(r"^\w+$", userName):
		errors.append("Usernames can only contain letters and numbers.")
	if len(errors) == 0:

		# Check if username is already taken
		userObj = None
		errors = []
		
		try:
			User.get(User.username == userName).count()

			# Username is taken - so append an error
			errors.append("That username is already taken.")

		except:
			pass

	# Bug out if errors (exit 1 of 2)
	if len(errors):
		return render_template('profile.html', data={"errors": errors, "userName": userName, "imageUrl": imageUrl})

	# Get user instance
	userObj = User.get(User.username == session['username'])
	if userObj.password != curPw:
		return render_template('profile.html', data={"errors": ["Please re-enter your current password."], "userName": userName, "imageUrl": imageUrl, "language": language})

	# Update user instance
	if len(newPw) != 0:
		 userObj.password = newPw
	userObj.username = userName
	session['username'] = userName
	userObj.imageUrl = imageUrl
	userObj.language = language
	userObj.save()

	# Redirect
	return redirect("/profile")
开发者ID:ace-n,项目名称:wildhacks-fa14,代码行数:60,代码来源:main.py

示例9: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def authenticate():
    if session and session['curr_user']:
        try:
            User.get(User.id == session['curr_user'])
            return True
        except User.DoesNotExist:
            return False
    else:
        return False
开发者ID:brendanWeb,项目名称:old-brendanhenderson.com,代码行数:11,代码来源:helpers.py

示例10: test_registration

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
 def test_registration(self):
     """Test User creation through our POST route"""
     with test_database(self.TEST_DB, (User,)):
         rv = self.app.post('/register', data=self.data)
         self.assertIn("login", rv.get_data(as_text=True).lower())
         self.assertEqual(User.select().count(), 1)
         self.assertEqual(User.get().username, 'testUsername')
         self.assertEqual(User.get().email, '[email protected]')
         self.assertNotEqual(User.get().password, 'password')
         self.assertEqual(rv.status_code, 302)
开发者ID:nicolasjhampton,项目名称:python_tutorial_game_project,代码行数:12,代码来源:_server_tests.py

示例11: testUserGet

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
 def testUserGet(self):
     n = uuid.uuid4().hex
     u = User.create(n, fakePublicKey())
     u.put()
     w = User.get(n)
     self.assertEqual(w.name, n)
     self.assertEqual(u.public_key, w.public_key)
     self.assertEqual(u.timestamp, w.timestamp)
     u.delete()
     x = User.get(n)
     self.assertEqual(None, x)
开发者ID:league,项目名称:cryptodemo,代码行数:13,代码来源:tests.py

示例12: user_update

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def user_update(site, host, netloc, csrf, logged_in, user_id_logged_in):
    """
    Admin user url
    """

    # POST parameters
    user_id = int(request.POST.getunicode('id'))
    email = request.POST.getunicode('email')
    password1 = request.POST.getunicode('password1')
    password2 = request.POST.getunicode('password2')
    name = request.POST.getunicode('name')

    # Verify user
    if user_id_logged_in != user_id:
        # Logout
        session = request.environ.get('beaker.session')
        session['logged_in'] = False
        session['user_id_logged_in'] = None

        # Return error
        return dict(status=False, info='Sem permissão para acessar')

    # Verify password
    if password1 != password2:
        return dict(status=False, info='Senhas não coincidem')

    # User logged in
    try:
        user = User.get(User.id == user_id_logged_in)
    except User.DoesNotExist:
        return dict(status=False, info='Usuário não encontrado')

    # Verify changed email
    if user.email != email:
        try:
            other_user = User.get(User.email == email)
            return dict(status=False, info='Email já registrado')
        except User.DoesNotExist:
            pass

    # Update user data
    try:
        user.email = email
        if len(password1) > 0:
            user.password = md5(password1.encode('utf-8')).hexdigest()
        user.name = name
        user.save()
    except IntegrityError as exp:
        # Return error
        return dict(status=False, info='%s' % exp)

    # Return OK
    return dict(status=True, info='Atualizado com sucesso')
开发者ID:jfmedeirosneto,项目名称:opcms,代码行数:55,代码来源:opcms_user.py

示例13: validate_password

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
    def validate_password(self, field):
        account = self.account.data
        if '@' in account:
            user = User.get(email=account)
        else:
            user = User.get(name=account)

        if not user:
            raise ValidationError('用户名或密码错误')
        if user.check_password(field.data):
            self.user = user
            return user
        raise ValidationError('用户名或密码错误')
开发者ID:laofo,项目名称:collipa,代码行数:15,代码来源:user.py

示例14: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
	def get(self):
		### Session verification code ###
                session = get_current_session()
                try:
                        if not session['key'] or session['key'] == '':
                                self.redirect('/?exception=NoSession')
                        else:
                                template_values = {
                                'pagename': 'friends',
                                }

                                template_values['logged'] = True
                                template_values['unread'] = UnreadMessages(session['key'])

				friends = Friendship().all().filter("user =", session['key'])
				waitinglist = []
				pendinglist = []
				friendslist = []
				for friend in friends:
					try:
						ufriend = User.get(friend.friend)
						frienddict = {'key': str(ufriend.key()), 'nick': ufriend.nick, 'fname': ufriend.fname, 'lname': ufriend.lname, 'avatar': ufriend.avatar}
						if friend.status == 0:
							pendinglist.append(frienddict)
						elif friend.status == 1:
							friendslist.append(frienddict)
					except (KeyError, AttributeError):
						pass

				friends = Friendship().all().filter("friend =", session['key'])
				for friend in friends:
                                        try:
                                                ufriend = User.get(friend.friend)
                                                frienddict = {'key': str(ufriend.key()), 'nick': ufriend.nick, 'fname': ufriend.fname, 'lname': ufriend.lname, 'avatar': ufriend.avatar}
                                                if friend.status == 0:
                                                        waitinglist.append(frienddict)
                                        except KeyError:
                                                pass
				friendslist = sorted(friendslist, key=lambda k: k['nick'])
				if len(friendslist) > 0:
					template_values['friends'] = friendslist
				if len(pendinglist) > 0:
                                        template_values['pending'] = pendinglist
				if len(waitinglist) > 0:
                                        template_values['waiting'] = waitinglist

                                path = os.path.join(os.path.dirname(__file__), 'templates/friends.html')
                                self.response.out.write(template.render(path, template_values))
                except KeyError:
                        self.redirect('/?exception=NoSession')
开发者ID:ThomasMarcel,项目名称:thas,代码行数:52,代码来源:friends.py

示例15: test_create_outgoing

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
 def test_create_outgoing(self):
     """Create an outgoing record."""
     Category.create(category_id='001', description='Testing Stock')
     Project.create(project_id='001', project_description="Testing")
     Role.create(role_name='Admin')
     User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='JayPalm',
                 password='jfresh13', email='[email protected]')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='JayPalm')
     OutgoingStock.get(OutgoingStock.stock == '001').delete_instance()
     Stock.get(Stock.category == '001').delete_instance()
     User.get(User.username == 'JayPalm').delete_instance()
     Role.get(Role.role_name == 'Admin').delete_instance()
     Project.get(Project.project_id == '001').delete_instance()
     Category.get(Category.category_id == '001').delete_instance()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:17,代码来源:tests.py


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