本文整理汇总了Python中models.Player.put方法的典型用法代码示例。如果您正苦于以下问题:Python Player.put方法的具体用法?Python Player.put怎么用?Python Player.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.put方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def post(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url("/"))
return
game_name = self.request.get("game_name")
if not game_name:
self.response.write("No game name specified")
return
game_key = db.Key.from_path("Game", game_name)
game = db.get(game_key)
if not game:
game = Game(key_name=game_name)
game.put()
logging.info("Game: {0}".format(game))
player = Player(user=user, parent=game)
player.put()
token = channel.create_channel("{0}:{1}".format(game_name, user.user_id()))
logging.info("/game?gamename={0}&token={1}".format(game.key().id_or_name(), token))
self.redirect("/game?gamename={0}&token={1}".format(game.key().id_or_name(), token))
示例2: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def post(self):
request_data = json.loads(self.request.body)
logging.info(request_data)
user = users.get_current_user()
# VALIDATION
if not validate_request_data(self.response, request_data, ['nick', 'player_class']):
return
if not validate_logged_inn(self.response):
return
if not self._validate_has_not_player_already(user):
return
if Player.query(Player.nick_lower == request_data['nick'].lower()).count() > 0:
error_400(self.response, "ERROR_NICK_TAKEN", "The nickname %s is already taken" % request_data['nick'])
return
if not is_valid_player_class_name(request_data['player_class']):
error_400(self.response, "ERROR_BAD_PLAYER_CLASS", "Player class ' %s ' is not valid." % request_data['player_class'])
return
# REGISTER PLAYER
new_player = Player(
id=user.user_id(),
nick=request_data['nick']
)
for player_class in player_class_metrics:
if player_class['name'] == request_data['player_class']:
logging.info(player_class['stat_modifiers'])
for stat_name, stat_value in player_class['stat_modifiers'].iteritems():
current_stat_value = getattr(new_player, stat_name)
new_stat_value = current_stat_value + stat_value
setattr(new_player, stat_name, new_stat_value)
new_player.put().get()
set_json_response(self.response, new_player.get_data("full"))
示例3: create_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def create_player(self, request):
"""Creates a new player.
This function creates a new player. It will also make sure
that the chosen username is not yet taken.
(NB: Currently this function does not implement any validity checks
on the email address, such as a regex etc.)
Returns:
StringMessage -- confirmation of player creation
Raises:
ConflictException -- if username or email address is taken already
"""
# Check username and email address for conflicts
if Player.query(Player.email_address == request.email_address).get():
raise endpoints.ConflictException(
'A Player with that email address already exists.')
if Player.query(Player.user_name == request.user_name).get():
raise endpoints.ConflictException(
'A Player with that name already exists.')
# Create player
player = Player(user_name=request.user_name,
email_address=request.email_address)
player.put()
# Return confirmation of player creation
return StringMessage(message='Player successfully created.')
示例4: create_Player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def create_Player(self, request):
"""Create a User. Requires a unique username"""
query_player = Player.query(Player.name == request.user_name).get()
# somehow the if statement cannot be:
# if query_player1 == True and query_player2 == True
if query_player:
raise endpoints.ConflictException(
'A User with that name already exists in the DB! You do not need to create a new one')
player = Player(name=request.user_name, email=request.email)
player.put()
return StringMessage(message='Player {} created!'.format(
request.user_name))
示例5: get_player_from_email
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def get_player_from_email(email):
"""Helper method to get the Player object corresponding to the given User.
Creates a new Player object if one didn't exist already.
"""
email = email.lower()
player = Player.get_by_id(email, parent=get_parent_key_from_email(email))
logging.info("player = " + str(player))
if not player:
logging.info("Failed to find player by id, creating new user")
player = Player(parent=get_parent_key_from_email(email), id=email)
player.put()
return player
示例6: new_user
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def new_user():
username = request.json.get['username']
password = request.json.get['password']
email = request.json.get['email']
if username is None or password is None:
abort(400) # missing arguments
# if User.query.filter_by(username = username).first is not None:
# abort(400) # username already exists
user = Player(username=username) # constructing new user
hash_password(password)
user.put() # put user in db
return jsonify({'username': user.username}), 201, {
'Location': url_for('get_user', id=user.username, _external=True)}
示例7: createPlayer
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def createPlayer(self, request):
"""
Create a Player. Requires a unique username; (an authenticated Google
user can create multiple Players as long as the entered user_name is
unique.)
"""
if request.user_name is None or request.email is None:
raise endpoints.UnauthorizedException(
'Need user_name and email to create a player.')
if Player.query(Player.displayName == request.user_name).get():
raise endpoints.ConflictException(
'A Player with that name already exists!')
player = Player(displayName=request.user_name, mainEmail=request.email)
player.put()
return player._copyPlayerToForm
示例8: get_create_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def get_create_player(game, player_name):
"""
:return: (player, '') or (None, err_msg)
"""
players_query = \
Player.query(ancestor=game.key).filter(ndb.GenericProperty('name') == player_name).order(-Player.date)
player = players_query.get()
if player is not None:
return player, ''
# player not found in datastore
players_query = Player.query(ancestor=game.key).order(-Player.date)
if players_query.count() >= PLAYERS_PER_GAME:
return None, 'Cannot create another player for this game. Game reached max players.'
# create a new player
player = Player(parent=game.key, name=player_name)
player.put()
return player, ''
示例9: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def post(self):
first_name = self.request.get("fname")
last_name = self.request.get("lname")
email_address = self.request.get("email")
phone_number = self.request.get("phone")
# we don't require a phone number, but we don't
# want it to be an empty string either
if phone_number == "":
phone_number = None
# make sure they fill out all required fields
if first_name == "" or last_name == "" or email_address == "":
self.response.out.write(RenderSignupPage(first_name, last_name, email_address,"Fill in all the fields", phone_number))
else:
# if a new player has been created, clear our memcache and add the new player
memcache.delete('players')
player = Player(fname=first_name, lname=last_name, email=email_address, goalie=False, rating=0, phone=phone_number)
player.put()
values = { "message":"Thank you for signing up!"}
path = os.path.join(os.path.dirname(__file__), 'templates/success.html')
self.response.out.write(template.render(path, values))
示例10: new_game
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def new_game(request):
player = Player.gql("WHERE imei = :1", request.GET['imei']).get()
if not player:
player = Player(imei = request.GET['imei'])
player.game_requested = datetime.now()
player.put()
# Because there cant be two inequals in one query
opponents = Player.gql("WHERE game_requested > :1 ", datetime.now() - timedelta(0, 45)).fetch(2)
opponents = filter(lambda x: x.imei != request.GET['imei'], opponents)
if opponents:
opponent = opponents[0]
player.game_requested, opponent.game_requested = None, None
game = CheckersGame.create(player1 = opponent, player2 = player)
player.game, opponent.game = game, game
game.setup()
game.put()
player.put()
opponent.put()
return HttpResponseRedirect("/api/action/?imei=%s"%request.GET['imei'])
return HttpResponse(sj.dumps({'status' : 'waiting'}))
示例11: create_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def create_player(self, request):
"""Create a Player. Optionally set a (non)unique username and email (not validated)"""
# LATER: filter using bleach and profanity pip libs to prevent XSS and xbox live community
# LATER: include funny response when popular slinger names are chosen
email = None
if request.email is not None:
email = request.email
player_name = None
if request.desired_name is not None:
player_name = request.desired_name
player_id = uniq_id()
player = Player(player_id=player_id,
player_name=player_name, player_email=email)
player.put()
return player.to_message()
示例12: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import put [as 别名]
def post(self):
isAdmin = login.isAdmin()
isPlayer = login.isPlayer()
user = users.get_current_user()
if not isAdmin and not isPlayer:
self.response.set_status(500, message='You must log in')
self.response.out.write('You must log in')
return
# get player data
logging.info(self.request.body)
try:
player_data = json.loads(self.request.body)
except ValueError:
player_data = self.request
logging.info(player_data)
if player_data and player_data.get('id'):
id = int(player_data.get('id'))
db_player = Player.get_by_id(id)
elif player_data.get('name'):
db_player = Player(name=player_data['name'])
else:
self.response.set_status(500, message='You have not specified an id or a name')
self.response.out.write('You have not specified an id or a name')
return
if not isAdmin and db_player.email != user.email():
logging.info(db_player.email)
logging.info(user.email())
self.response.set_status(500, message='You are not authorized')
self.response.out.write('You are not authorized')
return
# edit player in db
if db_player:
status = player_data.get('status') or 'waiting'
# check if status is valid
n_presents = Player.all().filter('status =', 'present').count()
if db_player.status != 'present' and status == 'present' and n_presents >= 10:
logging.info(user.nickname() + ' (' + user.email() +
') tried to set status to \'' + status +
'\' but it was full')
self.response.set_status(500, message='La lista e\' piena')
self.response.out.write('La lista e\' piena')
return
db_player.status = status
if isAdmin:
isStarred = player_data.get('isStarred') == 'True' or False
db_player.isStarred = isStarred
db_player.name = player_data.get('name')
if player_data.get('email'):
db_player.email = player_data.get('email')
db_player.put()
#send message to clients
result = playerToJSON(db_player, isAdmin)
sendMessage(result)
self.response.out.write(result)
else:
self.response.out.write('emptyName')