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


Python User.query方法代码示例

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


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

示例1: create_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
    def create_user(self, request):
        """Creates a User.
        Args:
            request: The USER_REQUEST objects, which includes a users
                chosen name and an email.
        Returns:
            StringMessage: A message that is sent to the client, saying that
                the user has been created.
        Raises:
            endpoints.BadRequestException: If no user name is provided.
            endpoints.ConflictException: If the user already exists.
            endpoints.BadRequestException: If no email is provided.
            endpoints.ConflictException: If a user with that email already exists.
        """
        if request.user_name is None:
            raise endpoints.BadRequestException(
                    'You must enter a user name to create a new user!')
        elif User.query(User.name == request.user_name).get():
            raise endpoints.ConflictException(
                    'A User with username {} already exists!'.format(request.user_name))

        if request.email is None:
            raise endpoints.BadRequestException(
                    'You must enter an email id to create a new user!')
        elif User.query(User.email == request.email).get():
            raise endpoints.ConflictException(
                    'A User with email {} already exists!'.format(request.email))

        # Create a new user with the user_name and email.
        user = User(name=request.user_name, email=request.email)
        # Add the user to the datastore with kind 'User'
        user.put()
        return StringMessage(message='User {} created!'.format(
                request.user_name))
开发者ID:geetimaRai,项目名称:hangmanAPI,代码行数:36,代码来源:api.py

示例2: test_new_user_non_unique_username

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
 def test_new_user_non_unique_username(self):
     '''
     a new user with a username that already exists shoudl raise a NameError
     '''
     new_user('jamesusername', 'James Smith', '[email protected]', '1')
     self.assertEqual(User.query().count(), 1)
     self.assertRaises(NameError, new_user, 'jamesusername', 'Bill Bradley', '[email protected]', '2')
     self.assertEqual(User.query().count(), 1)
开发者ID:qdonnellan,项目名称:lessonwell,代码行数:10,代码来源:modify_user_test.py

示例3: test_new_user_implementation

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
 def test_new_user_implementation(self):
     '''
     test that the new user controller is working correctly
     '''
     new_user('jamesusername', 'James Smith', '[email protected]', '12345678')
     self.assertEqual(User.query().count(), 1)
     new_user('foobar', 'James Smith', '[email protected]', '2')
     self.assertEqual(User.query().count(), 2)
开发者ID:qdonnellan,项目名称:lessonwell,代码行数:10,代码来源:modify_user_test.py

示例4: test_valid_sign_up_post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
 def test_valid_sign_up_post(self):
     self.create_google_user()
     self.assertEqual(User.query().count(), 0)
     data = {
         'username' : 'helloworld',
         'stripeToken' : self.generate_sample_token().id,
         }
     response = self.testapp.post('/sign_up', data)
     # there should now be a new user in the database!
     self.assertEqual(User.query().count(), 1)
     self.assertIn(
         'You have successfully created a lessonwell account', 
         response.follow().body
         )
开发者ID:qdonnellan,项目名称:lessonwell,代码行数:16,代码来源:sign_up_page_test.py

示例5: user_login

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
 def user_login(email, password):
     #check all credentials are right
     qry = User.query(User.email == email, User.password == password).get()
     if qry:
         return qry.key.id()
     else:
         #check password wrong
         q = User.query(User.email == email).get()
         if q and q.password == "None":
             return 2
         elif q:
             return 1
         elif q is None:
             return False
开发者ID:ItamarShDev,项目名称:attender-web,代码行数:16,代码来源:DAL.py

示例6: create_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
    def create_user(self, request):
        '''Create a User. Requires a unique username'''
        if User.query(User.name == request.user_name).get():
            raise endpoints.ConflictException(
                'A User with that name already exists!')

        if User.query(User.email == request.email).get():
            raise endpoints.ConflictException(
                'A User with that email already exists!')

        user = User(name=request.user_name, email=request.email)
        user.put()

        return StringMessage(
            message='User {} created!'.format(request.user_name))
开发者ID:OscarDoc,项目名称:Planticity,代码行数:17,代码来源:planticity.py

示例7: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
    def get(self):
        group = Group.get_by_id(int(self.request.get('group_id')))
        user = None
        if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
            user = User.checkToken(self.request.cookies.get('our_token'))

        if not user or group.admin != user.key:
            self.error(403)
            self.response.write('access denied')
            return

        new_user_email = self.request.get('member_email')
        logging.info("Email {}".format(new_user_email))
        new_user = User.query(User.email == new_user_email).get()

        if not new_user:
            self.error(404)
            self.response.write('User with email {} not found'.format(new_user_email))
            return

        group.members.append(new_user.key)
        group.put()
        members = group.getMembers()

        time.sleep(0.5)
        self.response.write(json.dumps({"status": "OK", "members": members}))
开发者ID:jce-il,项目名称:gae-login-example,代码行数:28,代码来源:add_member.py

示例8: get_user_scores

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
def get_user_scores(request):
    user = User.query(User.name == request.user_name).get()
    if not user:
        raise endpoints.NotFoundException(
            'A User with that name does not exist!')
    scores = Score.query(Score.user == user.key)
    return scores
开发者ID:danrhjones,项目名称:GameApi,代码行数:9,代码来源:hangman.py

示例9: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
    def post(self):
        user = users.get_current_user()
        title = self.request.get("title")
        content = self.request.get("content")
        tags = self.request.get("all-tags").split(",")
        instructor = self.request.get("instructor")
        if instructor:
            tags.append(instructor)

        author = users.get_current_user().nickname()

        if title and content and tags:
            topic = Topic.create(title, content, author, tags)
            topic.subscribers.append(user.email())
            topic.put()
            self.redirect("/topic/" + str(topic.key.id()))

            the_users = User.query(User.receive_updates==True).fetch()

            for user in the_users:
                email = user.email
                if user.first_name is None:
                    first_name = ""
                else:
                    first_name = user.first_name

                if email != users.get_current_user().email():
                    email_new_topic(first_name, title, topic.key.id(), email)
        else:
            self.redirect('/')
开发者ID:KlemenGlobocnik,项目名称:forum,代码行数:32,代码来源:TopicHandlers.py

示例10: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
	def get(self):
		mail=self.request.get('mail')
		name=self.request.get('name')
		type=self.request.get('type')
		hoursToAdd=self.request.get('hourstoadd')
		
		user = User.query(User.mail == mail).get()
		if not user:
			self.error(403)
			self.response.write('No user - access denied')
			return
		customer=Customer.query(Customer.name==name, Customer.user==user.mail).get()
		if not customer:
			self.error(402)
			self.response.write('no customer')
			return
			
		if type== 'manager':
			Customer.updateCustomerManagerHours(mail, name, int(hoursToAdd))
		elif type== 'worker':
			Customer.updateCustomerWorkerHours(mail, name, int(hoursToAdd))
		else:
			self.error(402)
			self.response.write('error')
			return

		self.response.write(json.dumps({"status": "OK"}))
开发者ID:liranharari,项目名称:WM--work-manager,代码行数:29,代码来源:updateCustomer.py

示例11: scores

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
 def scores(self, request):
     """Present User scores"""
     queryscore = User.query().order(-User.score)
     qscore = queryscore.fetch(request.HowManyToQuery, projection= \
         [User.name, User.score])
     qscore = sorted(qscore, key=lambda x: x.score, reverse=True)
     return ScoreForms(items=[i.to_score() for i in qscore])
开发者ID:mygethub-99,项目名称:mygamefinal,代码行数:9,代码来源:api.py

示例12: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
    def get(self):
        user = users.get_current_user()

        if user:
            # Filter by the google appengine user id property.
            active_user = User.query(User.google_id == user.user_id()).fetch(1)

            if not active_user:
                # If we couldn't find a user it means that is the first time it uses the application.
                # We just need to create a new entity with the get_current_user() information.
                active_user = User(email=user.email(), username=user.nickname(), google_id=user.user_id())
                active_user.put()
                logging.info("New user created. Email address is: %s", active_user.email)
            else:
                active_user = active_user[0]

            token = channel.create_channel(str(active_user.key.id()))
            memcache.add(key=str(active_user.key.id()), value=token)

            template_vars = {
                'user': active_user,
                'token': token,
                'logout_url': users.create_logout_url('/welcome'),
                'boards': Board.query().order(Board.created_at)

            }
            template = JINJA_ENVIRONMENT.get_template('root.html')
            self.response.write(template.render(template_vars))
        else:
            self.redirect('/welcome')
开发者ID:bilby91,项目名称:ganban,代码行数:32,代码来源:web.py

示例13: test_register_new_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
 def test_register_new_user(self):
     token = self.mydb.register("[email protected]", "12134", "Itamar", "Sharify")
     qry = User.query(User.email == "[email protected]")
     print "token", token
     for q in qry:
         print q.first_name , q.last_name, q.email
     self.assertTrue(qry.count() == 1)
开发者ID:ItamarShDev,项目名称:attender-web,代码行数:9,代码来源:login_test.py

示例14: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
	def get(self):
  		template_params={}
		mail=self.request.get('mail')
		name=self.request.get('name')
		
		user= User.query(User.mail == mail).get()
		if not user:
			self.error(403)
			self.response.write(' user Error')
			return
		customer=Customer.query(Customer.name==name, Customer.user==mail).get()
		if not customer:
			self.error(403)
			self.response.write('no customer')
			return
		
		template_params['address']=customer.address
		template_params['phone']=customer.phone
		template_params['email']=customer.email
		template_params['field1']=customer.field1
		template_params['field2']=customer.field2
		template_params['field3']=customer.field3
		template_params['field4']=customer.field4
		template_params['field5']=customer.field5
		template_params['field6']=customer.field6
		self.response.write(json.dumps(template_params))
开发者ID:liranharari,项目名称:WM--work-manager,代码行数:28,代码来源:info.py

示例15: new_game

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import query [as 别名]
    def new_game(self, request):
        """Creates new game"""
        player_one = User.query(User.name == request.player_one_name).get()
        if not player_one:
            raise endpoints.NotFoundException(
                'A User with that name {} does not exist!'.format(
                    request.player_one_name))

        player_two = User.query(User.name == request.player_two_name).get()
        if not player_two:
            raise endpoints.NotFoundException(
                'A User with that name {} does not exist!'.format(
                    request.player_two_name))

        game = Game.new_game(player_one.key, player_two.key)

        return game.to_form('Good luck playing Tic-Tac-Toe!')
开发者ID:herrkrebs,项目名称:udacity-fsnd-project-4-design-a-game,代码行数:19,代码来源:api.py


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