本文整理汇总了Python中models.Player.create方法的典型用法代码示例。如果您正苦于以下问题:Python Player.create方法的具体用法?Python Player.create怎么用?Python Player.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def get_player(nick_name='', steam_id=''):
"""
gets player by given params.
If player changed nickname - replaces old one in db
If no such player - creates new
:param nick_name:
:param steam_id:
:param may_be_new:
:return:Player object
"""
print nick_name, steam_id
if nick_name and not steam_id:
try: # FIXME: temporary crutch while checking old players steam_id is impossible (asker required)
return Player.get(nick_name=nick_name)
except:
player = Player.create(steam_id=0, nick_name=nick_name)
return player
elif steam_id and not nick_name:
return Player.get(steam_id=steam_id)
elif steam_id and nick_name:
try:
player = Player.get(steam_id=steam_id)
except:
player = Player.create(steam_id=steam_id, nick_name=nick_name)
if nick_name != player.nick_name:
player.nick_name = nick_name # TODO: test for it
player.save()
return player
示例2: join_random
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def join_random(user):
"""Finds and joins the optimal random game."""
if user.num_random > 4:
return jsonify(), 418
game = Game.find_random(user)
if not game:
return jsonify(), 418
player = Player.create(user, game)
player.set_status_joined()
user.num_random += 1
joined = [p for p in game.players
if p.status == Player.JOINED]
if len(joined) == game.max_players:
game.start()
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify()
示例3: initialize_player_position
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def initialize_player_position(args):
player_id = get_player_id(args)
start_position = get_pos_by_name(args.location)
if len(Player.select().where(Player.player_id == player_id)) == 0:
Player.create(
player_id=player_id,
name=args.username,
enabled=True,
last_modified=datetime.now(),
start_latitude=start_position[0],
start_longitude=start_position[1]
)
else:
Player.update(
last_modified=datetime.now(),
start_latitude=start_position[0],
start_longitude=start_position[1]
).where(Player.player_id == player_id).execute()
示例4: sign_up
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def sign_up(self, message):
if self.is_bot(message['user']):
self.talk('Nice try, <@' + message['user'] + '>: ' + 'No bots allowed!')
return
try:
player = Player.create(slack_id=message['user'])
self.talk('<@' + message['user'] + '>: ' + 'You\'re all signed up. Good luck!')
except IntegrityError:
self.talk('<@' + message['user'] + '>: ' + 'You\'re already signed up!')
示例5: create_room
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def create_room():
"""
Route creates new room and redirects to the lobby.
It adds a new player to the room and sets session cookie if not present
"""
username = request.forms.get("username")
if len(username) == 0:
return HTTPError(403, "Username too short")
sessid = request.cookies.get("sessid", generate_sessid())
room = Room.create(code=generate_room_code())
player = Player.create(sessid=sessid, name=username, room=room)
room.owner = player
room.save()
response.set_cookie("sessid", sessid, path="/")
return redirect("/game/%s/lobby" % room.code)
示例6: register
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def register():
group_name = request.form['group'].strip()
player_name = request.form['player'].strip()
try:
# Perform case-insensitive search.
group = Group.get(fn.Lower(Group.name) == group_name.lower())
except:
group = Group.create(name=group_name)
try:
# Perform case-insensitive search.
player = Player.get(fn.lower(Player.name) == player_name.lower(), group=group)
except Player.DoesNotExist:
player = Player.create(
group=group, name=player_name, order=group.players.count())
return str(player.id)
示例7: add_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def add_player():
name = request.form.get('name')
surname = request.form.get('surname')
Player.create({'name': name, 'surname': surname})
return redirect(url_for('index'))
示例8: get_user
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def get_user(content):
"""
Find and return the user's info, or
create the user if he doesn't exist.
If the user doesn't exist, enter
the user into 3 random games and
add 5 random friends.
"""
token = content['token']
device = content['device']
now = datetime.now()
user = User.auth(token)
if not user:
user = User.create(token)
if not user:
return jsonify(), 418
else: # give the new user 3 random games and 5 random friends
games = Game.find_n_random(3, user)
players = [Player.create(user, game) for game in games]
[player.set_status_joined() for player in players]
for game in games:
joined = [p for p in game.players
if p.status == Player.JOINED]
if len(joined) == game.max_players:
game.start()
friends = User.find_n_random(5, user)
[f.add(user) for f in friends]
[user.add(f) for f in friends]
user.device = device
try:
db.session.commit()
except:
db.session.rollback()
raise
friendships = user.get_friendships()
friends = []
for friendship in friendships:
friend = \
friendship.sender if friendship.sender != user else \
friendship.receiver
friend_json = {
'name' : friend.name,
'email' : friend.email,
'picture': friend.picture
}
if friendship.valid:
friend_json['status'] = Friendship.VALID
elif friend == friendship.sender:
friend_json['status'] = Friendship.REQUEST
else:
friend_json['status'] = Friendship.PENDING
friends.append(friend_json)
return jsonify(**{
'name' : user.name,
'email' : user.email,
'picture': user.picture,
'token' : user.token,
'friends': friends,
'games' : [
{
'id' : p.game.id,
'name' : p.game.name,
'status' : p.game.status,
'player_status': p.status,
'seen' : p.seen,
'random' : p.game.random,
'players' : [
{
'name' : _p.user.name,
'email' : _p.user.email,
'picture': _p.user.picture,
'status' : _p.status,
'points' : _p.score
}
for _p in p.game.players
]
}
for p in user.players
if not p.game.end_time or p.game.end_time + timedelta(weeks=1) > now
]
})
示例9: test_find
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def test_find(self):
Player.create({"name": "test", "surname": "test"})
players = Player.find()
self.assertGreater(len(players), 0, "Players array should be greater than zero")