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


Python User.query方法代码示例

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


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

示例1: get

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def get(self):
     username = self.request.get("user")
     password = self.request.get("password")
     
     self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
     
     if not username or not password:
         # some fields were missing in the request
         self.response.write(json_error('invalid', ''))
     else:
         # check if username exists in db
         query_user = User.query(User.username == username).fetch()
         if query_user:
             # check if password is correct
             query = User.query(ndb.AND(User.username == username, User.pswd == password)).fetch()
             if query:
                 # generate 64 char session cookie and send it back
                 cookie = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(64))
                 session = Session(cookie = cookie, user = username)
                 session.put()
                 self.response.write(login_response('ok', cookie))   
             else: 
                 # password was incorrect
                 self.response.write(json_error('failure', 'password'))
         else:
             # user didn't exist
             self.response.write(json_error('failure', 'user'))
开发者ID:tuvior,项目名称:WhatsFree,代码行数:29,代码来源:login.py

示例2: get_high_scores

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def get_high_scores(self, request):
     """
     Returns a list of high scores in descending order.
     Optional Parameter: number_of_results to limit the number of results returned.
     """
     if request.number_of_results:
       users = User.query().order(-User.high_score).fetch(request.number_of_results, offset=0)
     else:
       users = User.query().order(-User.high_score).fetch()
     # users = sorted(users, key=lambda x: x.high_score, reverse=True)
     return HighScoresForm(scores=[user.high_score for user in users])
开发者ID:dianafisher,项目名称:yahtzee,代码行数:13,代码来源:yahtzee.py

示例3: _pre_delete_hook

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def _pre_delete_hook(cls, key):
     q1 = User.query(ndb.OR(
         User.held_coupons == key,
         User.old_coupons == key
     ))
     q2 = User.query(User.old_coupons == key)
     for u in q1.iter():
         try:
             u.held_coupons.remove(key)
         except ValueError:
             u.old_coupons.remove(key)
         finally:
             u.put()
开发者ID:rootlis,项目名称:wolfings,代码行数:15,代码来源:coupon.py

示例4: get

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
    def get(self):
        """Send a reminder email to each User with an email who has
        games in progress. Email body includes a count of active games and their
        urlsafe keys
        Called every hour using a cron job"""
        app_id = app_identity.get_application_id()
        users = User.query(User.email != None)
        for user in users:
            # Query for Users which have games in progress.
            games = Game.query(Game.user == user.key).\
                filter(Game.game_over == False)
            if games.count() > 0:
                subject = 'This is a reminder!'
                body = 'Hello {}, you have {} games in progress. Their' \
                       ' keys are: {}'.\
                       format(user.name, games.count()
                        ,', '.join(game.key.urlsafe() for game in games))
                logging.debug(body)

            # This will send test emails, the arguments to send_mail are:
            # from, to, subject, body
            mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
                           user.email,
                           subject,
                           body)
开发者ID:dianafisher,项目名称:yahtzee,代码行数:27,代码来源:main.py

示例5: delete_user

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def delete_user(self, request):
     """Deletes the User.
     """
     print request.user_name
     user = User.query(User.name == request.user_name).get()
     if user:
         user.key.delete()
         return StringMessage(message='User {} deleted.'.format(request.user_name))
     else:
         raise endpoints.NotFoundException('User not found!')
开发者ID:dianafisher,项目名称:yahtzee,代码行数:12,代码来源:yahtzee.py

示例6: create_game

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
    def create_game(self, request):
        """Creates new game."""
        print 'new game requested for user ', request.user_name
        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')

        game = Game.new_game(user.key)

        return game.to_form()
开发者ID:dianafisher,项目名称:yahtzee,代码行数:13,代码来源:yahtzee.py

示例7: create_user

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def create_user(self, request):
     """Creates 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!')
     user = User(name=request.user_name, email=request.email)
     user.put()
     # return StringMessage(message='User {} created!'.format(
     #         request.user_name))
     return user.to_form()
开发者ID:dianafisher,项目名称:yahtzee,代码行数:13,代码来源:yahtzee.py

示例8: get_user_games

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
    def get_user_games(self, request):
        """Returns the user's active games."""

        # Query for a user with this user name.
        user = User.query(User.name == request.user_name).get()
        if not user:
            message = ('User {} not found!').format(request.user_name)
            raise endpoints.NotFoundException(message)
        # Query for all active games for this user.
        games = Game.query(Game.user == user.key).filter(
            Game.game_over == False)
        return GameForms(games=[game.to_form() for game in games])
开发者ID:dianafisher,项目名称:yahtzee,代码行数:14,代码来源:yahtzee.py

示例9: update_user

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def update_user(self, request):
     """Updates the User.
     """
     user = User.query(User.name == request.user_name).get()
     if user:
         if request.email:
             user.email = request.email
         if request.high_score:
             user.high_score = request.high_score
         user.put()
         return user.to_form()
     else:
         raise endpoints.NotFoundException('User not found!')
开发者ID:dianafisher,项目名称:yahtzee,代码行数:15,代码来源:yahtzee.py

示例10: get

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def get(self):
   continue_url = self.request.get('continue')
   if not continue_url:
     continue_url = '/'
   user = users.get_current_user()
   if user:
     existing_user = User.query(User.id == user.email()).fetch(1)
     if not existing_user:
       User(id=user.email(), user=user).put()
     self.redirect(continue_url)
   else:
     data = { 'login_url': users.create_login_url('/login') }
     html = utils.render_template('tl/login.html', data)
     self.response.write(html)
开发者ID:smfoote,项目名称:fastsunday,代码行数:16,代码来源:login.py

示例11: get

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def get(self):
     username = self.request.get("user")
     password = self.request.get("password")
     email = self.request.get("email")
    
     self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
      
     if not username or not password or not email:
         # some fields were missing in the request
         self.response.write(json_error('invalid', ''))
     else:
         query_user = User.query(User.username == username).fetch()
         query_email = User.query(User.email == email).fetch()
         if query_user:
             # a user with this username exists already
             self.response.write(json_error('failure', 'username'))
         elif query_email:
             # a user with this email exists already
             self.response.write(json_error('failure', 'email'))
         else: 
             # create a new user with the data recieved
             user = User(username = username, pswd = password, email = email)
             db_result = user.put()
             self.response.write(register_response('ok'))
开发者ID:tuvior,项目名称:WhatsFree,代码行数:26,代码来源:register.py

示例12: get

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
    def get(self):
        self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
        name = self.request.get('name')

        if not name:
            error = json_error('delete user', 'failure', 'name')
            self.response.write(json.dumps(error))

        else:
            user = User.query(User.username == name).get()
            
            if not user:
            	error = json_error('delete user', 'failure', 'no such user')
                self.response.write(json.dumps(error))

            else:
            	user.key.delete()
            	response = {'delete user': {'status': 'ok'}}
            	self.response.write(json.dumps(response))
开发者ID:tuvior,项目名称:WhatsFree,代码行数:21,代码来源:delete_user.py

示例13: get_holders

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def get_holders(self, keys_only=False):
     '''
     Returns a list of users that are holding this coupon
     '''
     qry = User.query(User.held_coupons == self.key)
     return [u for u in qry.iter()]
开发者ID:rootlis,项目名称:wolfings,代码行数:8,代码来源:coupon.py

示例14: delete

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def delete(self):
     users = User.query(User.held_coupons == self.key)
     users.held_coupons.remove(self.key)
     users.put()
     self.key.delete()
开发者ID:rootlis,项目名称:wolfings,代码行数:7,代码来源:coupon.py

示例15: get_users

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
 def get_users(self, request):
     """Returns all Users in the database."""
     return UserForms(users=[user.to_form() for user in User.query()])
开发者ID:dianafisher,项目名称:yahtzee,代码行数:5,代码来源:yahtzee.py


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