Exemplo n.º 1
0
def player_stats(request, key):
  player = get_object(Player, key)
  # Calculate the player's ranking on the fly
  singles_ranking = 0
  doubles_ranking = 0
  singles_players = Player.gql("WHERE owner = :owner AND active = True ORDER BY singles_ranking_points DESC, name",
                                owner=request.user)
  for sp in singles_players:
    singles_ranking += 1
    if sp.key == player.key:
      break
  doubles_players = Player.gql("WHERE owner = :owner AND active = True ORDER BY doubles_ranking_points DESC, name",
                                owner=request.user)
  for dp in doubles_players:
    doubles_ranking += 1
    if dp.key == player.key:
      break

  games = []
  pgs = PlayerGame.gql("WHERE player = :player ORDER BY date_played DESC LIMIT 20", player=player)
  for pg in pgs:
    games.append(pg)
  return render_to_response(request, 'pingpong/player_stats.html',
    { 'player': player, 'singles_ranking': singles_ranking, 
      'doubles_ranking': doubles_ranking, 'games': games })
Exemplo n.º 2
0
def delete_player_games(game):
  pgs = PlayerGame.gql("WHERE game = :game", game=game)
  for pg in pgs:
    pg.delete()
Exemplo n.º 3
0
    for g in games:
      db_create(PlayerGame, player=p, game=g, date_played=g.date_played)
  # Find all teams where p is player2 (no gql OR operator)
  teams = Team.gql("WHERE player2 = :player", player=p)
  for t in teams:
    # Delete all games in which t played
    games = Game.gql("WHERE team1 = :team", team=t)
    for g in games:
      db_create(PlayerGame, player=p, game=g, date_played=g.date_played)
    games = Game.gql("WHERE team2 = :team", team=t)
    for g in games:
      db_create(PlayerGame, player=p, game=g, date_played=g.date_played)

# Populating extant PlayerGame entities with new won property
from pingpong.models import PlayerGame
for pg in PlayerGame.all():
  pg.won = pg.game.won(pg.player)
  pg.put()

# Populating extant PlayerGame entities with new team1_points, team2_points,
# t1p1, t1p2, t2p1 and t2p2 properties
from pingpong.models import PlayerGame
# Work in blocks specifying limit and offset here...
pgs = PlayerGame.all().fetch(limit=1000)
for pg in pgs:
  pg.team1_points = pg.game.team1.points
  pg.team2_points = pg.game.team2.points
  pg.t1p1 = pg.game.team1.player1
  pg.t1p2 = pg.game.team1.player2
  pg.t2p1 = pg.game.team2.player1
  pg.t2p2 = pg.game.team2.player2