本文整理汇总了Python中models.Player.name方法的典型用法代码示例。如果您正苦于以下问题:Python Player.name方法的具体用法?Python Player.name怎么用?Python Player.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_field_serialization
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import name [as 别名]
def test_custom_field_serialization(self):
"""Tests that custom fields serialize and deserialize intact"""
team_str = "Spartak Moskva"
player = Player()
player.name = "Soslan Djanaev"
player.rank = 1
player.team = Team(team_str)
player.save()
serial_str = serializers.serialize(self.serializer_name,
Player.objects.all())
team = self._get_field_values(serial_str, "team")
self.assertTrue(team)
self.assertEqual(team[0], team_str)
deserial_objs = list(serializers.deserialize(self.serializer_name, serial_str))
self.assertEqual(deserial_objs[0].object.team.to_string(),
player.team.to_string())
示例2: update_players
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import name [as 别名]
def update_players():
'''
Updates the Player table with the json retrieved from Kimono.
If a player is not in the table it creates one.
Returns the number of new palyers added to the db
'''
logger.info('Updating players...')
url = settings.KIMONO['players_url']
players = _get_results_collection1(url)
logger.info(' - Updating database...')
no_new_players = 0
for player in players:
p = Player()
# If the player is already in the db, using the same pk end up updating
# the past value
p.id = _id_from_url(player['name']['href'])
if not Player.objects.filter(pk=p.id).exists():
no_new_players += 1
p.name = player['name']['text']
p.role = _fix_role(player['role'])
p.team = Team.objects.get(name__iexact=player['team'])
p.price = player['price']
# Replacing the '-' character with 0 in remaining fields
p.attendances = _fix_zero(player['attendances'])
p.gol = _fix_zero(player['gol'])
p.assist = _fix_zero(player['assist'])
p.yellow_cards = _fix_zero(player['yellow_cards'])
p.red_cards = _fix_zero(player['red_cards'])
p.penalties_kicked = _fix_zero(player['penalties_kicked'])
p.penalties_scored = _fix_zero(player['penalties_scored'])
p.penalties_missed = _fix_zero(player['penalties_missed'])
p.penalties_saved = _fix_zero(player['penalties_saved'])
p.vote_avg = _fix_zero(player['vote_avg'])
p.magicvote_avg = _fix_zero(player['magicvote_avg'])
# Storing on the db
p.save()
return no_new_players
示例3: handle_post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import name [as 别名]
def handle_post(request):
if request.method == "POST":
#Loads json received from POST
received_json_data = json.loads(request.body)
#Check if we got player data
if 'player' in received_json_data or received_json_data['player']['social_id'] is not None or received_json_data['player']['email'] is not None or received_json_data['player']['puzzle_data'] is not None:
inputid = received_json_data['player']['social_id']
#See if player data already exist in database
if len(Player.objects.filter(social_id=inputid))<1:
#New Player
p = Player()
p.email = received_json_data['player']['email']
p.social_id = received_json_data['player']['social_id']
p.name = received_json_data['player']['name']
p.save()
playerPuzzleData = received_json_data['player']['puzzle_data']
#Create puzzle data
for i in range(len(playerPuzzleData['puzzles'])):
pdata = PuzzleData()
pdata.puzzles = playerPuzzleData['puzzles'][i]
pdata.scores=playerPuzzleData['scores'][i]
pdata.stars=playerPuzzleData['stars'][i]
pdata.save()
p.puzzle_data.add(pdata)
p.save()
data = serializers.serialize("python", p.puzzle_data.all())
data = [d['fields'] for d in data]
data = json.dumps(data)
data = {'player': data}
data = {'message': data}
return render(request, "update.html", data)
else:
#Not a new player so have to see if we need to update scores and stars
#I'll assume that players have unique social ids
p = Player.objects.get(social_id=received_json_data['player']['social_id'])
inputplayerPuzzleData = received_json_data['player']['puzzle_data']
mylevels = {}
#Create a list of levels and data pairs
for currentlevel in p.puzzle_data.all():
mylevels[currentlevel.puzzles]=currentlevel
#Check through each puzzle and update if needed
for i in range(len(inputplayerPuzzleData['puzzles'])):
findlevel = inputplayerPuzzleData['puzzles'][i]
if findlevel not in mylevels:
#New puzzle level to add to puzzle data
pdata = PuzzleData()
pdata.puzzles = inputplayerPuzzleData['puzzles'][i]
pdata.scores=inputplayerPuzzleData['scores'][i]
pdata.stars=inputplayerPuzzleData['stars'][i]
pdata.save()
p.puzzle_data.add(pdata)
else:
#Puzzle data already exists, check if scores or stars is greater value
storedlevel = mylevels[findlevel]
if inputplayerPuzzleData['scores'][i] > storedlevel.scores:
storedlevel.scores = inputplayerPuzzleData['scores'][i]
if inputplayerPuzzleData['stars'][i] > storedlevel.stars:
storedlevel.stars = inputplayerPuzzleData['stars'][i]
storedlevel.save()
p.save()
#serialize puzzle data and return player's data in JSON
data = serializers.serialize("python", p.puzzle_data.all())
data = [d['fields'] for d in data]
data = json.dumps(data)
data = {'player': data}
data = {'message': data}
return render(request, "update.html", data)
else:
mymessage = {'message':"Did not find player data in JSON or badly formed JSON"}
return render(request, "summary.html", mymessage)
else:
#Was not post request
mymessage = {'message':"Did not make a POST request"}
return render(request, "summary.html", mymessage)
示例4: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import name [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')
示例5: clearscreen
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import name [as 别名]
#!/usr/bin/env python3
# Blackjack.py - by Clyde Miller
from decimal import Decimal
from models import Card, Deck, Hand, Player
from utils import clearscreen, get_bet, win_conditions, blackjack_test
# Starting with a nice, clear screen:
clearscreen()
# Getting the player info
player = Player()
player.name = input("What's your name, pardner? ")
money = (
input(
"How much money are you bringing to the table, {}? $".format(
player.name)))
player.money = Decimal(money)
player.start_money = player.money
bet = 0
# Building the Deck with the number of packs of cards specified
while True:
try:
packs = int(
input("How many packs of cards should make up your deck? [1-10] "))
if packs < 0:
raise ValueError()
break
except ValueError:
print("{} is not a valid number of packs. They will throw you out of Vegas for that kinda crap".format(packs))
示例6: new_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import name [as 别名]
def new_player(name):
player = Player()
player.name = name
return player