本文整理汇总了Python中model.User.query方法的典型用法代码示例。如果您正苦于以下问题:Python User.query方法的具体用法?Python User.query怎么用?Python User.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get(self):
parser = reqparse.RequestParser()
parser.add_argument("cursor", type=ArgumentValidator.create("cursor"))
args = parser.parse_args()
users_future = User.query().order(-User.created).fetch_page_async(10, start_cursor=args.cursor)
total_count_future = User.query().count_async(keys_only=True)
users, next_cursor, more = users_future.get_result()
users = [u.to_dict(include=User.get_public_properties()) for u in users]
return make_list_response(users, next_cursor, more, total_count_future.get_result())
示例2: new_game
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def new_game(self, request):
"""Start a new five card poker game"""
player_one = User.query(User.name == request.player_one).get()
player_two = User.query(User.name == request.player_two).get()
err_msg = '{0} does not exist!'
if not player_one:
raise endpoints.NotFoundException(
err_msg.format(request.player_one)
)
if not player_two:
raise endpoints.NotFoundException(
err_msg.format(request.player_two)
)
game_id = Game.allocate_ids(size=1)[0]
game = Poker.new_game(player_one.key, player_two.key, game_id)
return game.to_form()
示例3: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get(self):
apt_name = self.request.get(IDENTIFIER_APT_NAME)
user_email = self.request.get(IDENTIFIER_USER_EMAIL)
apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()
# print "called: " + user_email + ", " + apt_name
cur_apt = None
for apt in apt_lst:
if user_email in apt.user_email_lst:
cur_apt = apt
user_info_lst = []
for user_email in apt.user_email_lst:
users = User.query(User.user_email == user_email).fetch()
user = users[0]
user_info = {}
user_info['email:'] = user_email
user_info['nick_name'] = user.nick_name
user_info['owe'] = user.cost
user_info['owed'] = user.borrow
user_info['balance'] = user.owe
user_info_lst.append(user_info)
self.respond(user_info_lst = user_info_lst, total_cost = apt.total_cost, status="Success")
示例4: get_game_history
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get_game_history(self, request):
"""Get player game history."""
player = User.query(User.name == request.player).get()
if not player:
raise endpoints.NotFoundException(
'{0} does not exist!'.format(request.player)
)
games = Game.query(
ndb.AND(
Game.game_over == True, # noqa
ndb.OR(
Game.player_one == player.key,
Game.player_two == player.key
)
)
)
game_histories = []
for game in games:
player_one = game.player_one.get()
player_two = game.player_two.get()
if game.is_forfeit:
game_histories.append(
GameHistoryForm(
game_urlsafe_key=game.key.urlsafe(),
player_one=player_one.name,
player_two=player_two.name,
is_forfeit=game.is_forfeit,
winner=game.winner.get().name
)
)
else:
p1_hands = Hand.query(
Hand.game == game.key,
Hand.player == player_one.key
)
p1_hands = Poker.get_player_start_end_hands(p1_hands)
p2_hands = Hand.query(
Hand.game == game.key,
Hand.player == player_two.key
)
p2_hands = Poker.get_player_start_end_hands(p2_hands)
game_histories.append(
GameHistoryForm(
game_urlsafe_key=game.key.urlsafe(),
player_one=player_one.name,
player_one_start_hand=repr(p1_hands[0]),
player_one_end_hand=repr(p1_hands[1]),
player_two=player_two.name,
player_two_start_hand=repr(p2_hands[0]),
player_two_end_hand=repr(p2_hands[1]),
is_forfeit=game.is_forfeit,
winner=game.winner.get().name
)
)
return GameHistoryForms(
games=game_histories
)
示例5: cancel_game
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def cancel_game(self, request):
"""Player forfeits game."""
game = get_by_urlsafe(request.game_urlsafe_key, Game)
player = User.query(User.name == request.player).get()
if not player:
raise endpoints.NotFoundException(
'{0} does not exist!'.format(request.player)
)
if game.player_one != player.key and game.player_two != player.key:
raise endpoints.ForbiddenException(
'{0} is not part of this game!'.format(request.player)
)
if game.player_one == player.key:
game.winner = game.player_two
else:
game.winner = game.player_one
game.game_over = True
game.is_forfeit = True
game.active_player = None
game.put()
Poker.update_player_stats(game)
# Notify the opponent that they have won
taskqueue.add(
url='/tasks/send_player_forfeit_email',
params={
'game_key': game.key.urlsafe(),
'winner_key': game.winner.urlsafe(),
'loser_name': player.name
}
)
return StringMessage(message='You have forfeited the game!')
示例6: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get(self):
"""Send a reminder email to users with a game in progress."""
players = User.query(User.email != None) # noqa
for player in players:
games = Game.query(
ndb.AND(
Game.game_over == False, # noqa
Game.active_player == player.key
)
)
game_keys = ', '.join(game.key.urlsafe() for game in games)
number_of_games = games.count()
if number_of_games > 0:
subject = 'This is a reminder!'
body = '''Hey {0}, you have {1} games in progress. It is your
turn to make a move in these games! Their url safe keys are: {2}'''.format(
player.name,
number_of_games,
game_keys
)
print body
mail.send_mail(
'[email protected]{}.appspotmail.com'.format(
app_identity.get_application_id()
),
player.email,
subject,
body
)
示例7: initialize
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def initialize(self, request, response):
self.current='home'
webapp2.RequestHandler.initialize(self, request, response)
if hasattr(self,'setup'):
self.setup()
from model import User,Blog
self.blog = Blog.getBlog()
self.login_user = users.get_current_user()
self.is_login = (self.login_user != None)
self.loginurl=users.create_login_url(self.request.uri)
self.logouturl=users.create_logout_url(self.request.uri)
self.is_admin = users.is_current_user_admin()
if self.is_admin:
self.auth = 'admin'
self.author=User.query().filter(User.email ==self.login_user.email()).get()
if not self.author:
self.author=User(dispname=self.login_user.nickname(),email=self.login_user.email())
self.author.level=3
self.author.user=self.login_user
self.author.put()
elif self.is_login:
self.author=User.query().filter(User.email ==self.login_user.email()).get()
if self.author:
self.auth='author'
else:
self.auth = 'login'
else:
self.auth = 'guest'
try:
self.referer = self.request.headers['referer']
except:
self.referer = None
self.template_vals = {'self':self,'blog':self.blog,'current':self.current}
示例8: index
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def index():
user_dbs, more_cursor = util.retrieve_dbs(
User,
User.query(),
limit=util.param('limit', int),
cursor=util.param('cursor'),
order=util.param('order'),
name=util.param('name'),
)
if request.path.startswith('/_json/'):
return util.jsonify_model_dbs(user_dbs, more_cursor)
return render_template(
'admin/user/index.html',
title=u'Пользователи',
user_dbs=user_dbs,
more_url=util.generate_more_url(more_cursor)
)
示例9: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get(self):
#Set up our twitter auth object
config = self.app.config['twitter']
auth = OAuthHandler(config['consumer_key'], config['consumer_secret'], self.request.host_url + '/auth')
#Check the session state. If it contains a twitter token,
#The user has already gone through the authorization step
tkn = self.session.get('twitter')
if tkn:
#If we are on the second phase already
auth.set_request_token(tkn[0], tkn[1])
del self.session['twitter']
verifier = self.request.get('oauth_verifier')
if verifier:
#Get the verification code from the URL
auth.get_access_token(verifier)
me = API(auth).me()
#See if we already have a user that has this id.
results = User.query().filter(User.twitter_id == me.id).fetch()
if results:
user = results[0]
#Make sure all the properties are up-to-date
user.name = me.name
user.location = me.location
user.put()
else:
user = User(twitter_id=me.id, name=me.name, location=me.location)
user.put()
#The user_id should be part of the session
self.session['user'] = user.key.id()
self.redirect('/')
else:
#Grabs request_tokens and creates a URL for a redirect
redirect_url = auth.get_authorization_url(signin_with_twitter=True)
#Store the request_token information for the next step
self.session['twitter'] = (auth.request_token.key, auth.request_token.secret)
self.redirect(redirect_url)
示例10: create_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def create_user(self, request):
"""Create a player. Username must be unique."""
# Code Citation:
# https://github.com/udacity/FSND-P4-Design-A-Game/blob/master/Skeleton%20Project%20Guess-a-Number/api.py # noqa
if not request.name:
raise endpoints.BadRequestException('A name is required.')
if not request.email:
raise endpoints.BadRequestException('An email is required.')
if User.query(User.name == request.name).get():
raise endpoints.ConflictException(
'A User with that name already exists!'
)
user = User(name=request.name, email=request.email)
user.put()
return StringMessage(
message='User {0} created!'.format(request.name)
)
示例11: get_user_games
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get_user_games(self, request):
"""Get all active user games."""
player = User.query(User.name == request.player).get()
if not player:
raise endpoints.NotFoundException(
'{0} does not exist!'.format(request.player)
)
games = Game.query(
ndb.AND(
Game.game_over == False, # noqa
ndb.OR(
Game.player_one == player.key,
Game.player_two == player.key
)
)
)
return GameForms(
games=[game.to_form() for game in games]
)
示例12: get_user_hand
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get_user_hand(self, request):
"""Get player's most recent hand state for a given game."""
game = get_by_urlsafe(request.game_urlsafe_key, Game)
player = User.query(User.name == request.player).get()
if not player:
raise endpoints.NotFoundException(
'{0} does not exist!'.format(request.player)
)
if game.player_one != player.key and game.player_two != player.key:
raise endpoints.ForbiddenException(
'{0} is not part of this game!'.format(request.player)
)
def get_card_form(hand):
card_forms = []
hand = Poker.load_player_hand(hand.hand)
for card in hand:
card_forms.append(
CardForm(name=card.name, suit=card.suit, card_id=card.id)
)
return card_forms
cards = []
state = 'STARTING'
hands = Hand.query(
Hand.game == game.key, Hand.player == player.key
).fetch()
if len(hands) == 1:
cards = get_card_form(hands[0])
else:
state = 'ENDING'
for hand in hands:
if hand.state == HandState.ENDING.name:
cards = get_card_form(hand)
return PlayerHandForm(
name=player.name,
cards=cards,
state=state
)
示例13: make_move
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def make_move(self, request):
"""Make a move."""
game = get_by_urlsafe(request.game_urlsafe_key, Game)
player = User.query(User.name == request.player).get()
if not player:
raise endpoints.NotFoundException(
'{0} does not exist!'.format(request.player)
)
if game.player_one != player.key and game.player_two != player.key:
raise endpoints.ForbiddenException(
'{0} is not part of this game!'.format(request.player)
)
if game.active_player != player.key:
raise endpoints.ForbiddenException(
'It is not your turn {0}'.format(request.player)
)
hand = Poker.make_move(game, player, request.card_ids_to_exchange)
return StringMessage(
message='Your move has been made here is your final hand: {0}. '
'Good luck!'.format(str(hand))
)
示例14: get_user_rankings
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get_user_rankings(self, request):
"""Get player stats and ranking based on total points earned."""
player_rankings = User.query().order(-User.points)
player_rank = 1
player_rank_forms = []
for player in player_rankings:
player_stats = '{0}-{1}-{2} (Wins-Ties-Losses)'.format(
player.wins, player.ties, player.losses
)
player_rank_forms.append(
PlayerRankForm(
name=player.name,
stats=player_stats,
points=player.points,
rank=player_rank
)
)
player_rank += 1
return PlayerRankForms(
player_ranks=player_rank_forms
)
示例15: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import query [as 别名]
def get(self):
users = User.query().fetch()
users = [p.to_dct() for p in users]
self.response.write(json.dumps(users))