本文整理汇总了Python中models.Team.get方法的典型用法代码示例。如果您正苦于以下问题:Python Team.get方法的具体用法?Python Team.get怎么用?Python Team.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Team
的用法示例。
在下文中一共展示了Team.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: team_iter
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get [as 别名]
def team_iter():
for team_data in leaderboard:
if team_data["total_cents"] == 0:
continue
if team_data["team"].startswith('{{team.key()}}'):
# sentinel value == no team
continue
team = Team.get(db.Key(team_data["team"]))
if team is None:
continue
yield team_data, team
示例2: testAggregation
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get [as 别名]
def testAggregation(self):
team = Team.create(name="Houkago Tea Time")
team.members.append(first_name="Ritsu" , last_name="Tainaka" , part="Dr" , age=17)
team.members.append(first_name="Mio" , last_name="Akiyama" , part="Ba" , age=17)
team.members.append(first_name="Yui" , last_name="Hirasawa", part="Gt1", age=17)
team.members.append(first_name="Tsumugi", last_name="Kotobuki", part="Kb" , age=16)
team.members.append(first_name="Azusa" , last_name="Nakano" , part="Gt2", age=17)
a = ("Akiyama", "Hirasawa", "Kotobuki", "Nakano", "Tainaka")
for i, m in enumerate(Team.get(1).members.order_by("last_name")):
self.assertEqual(m.last_name, a[i])
cnt = team.members.count()
self.assertEqual(cnt, 5)
sum_of_ages = team.members.all().aggregate(macaron.Sum("age"))
self.assertEqual(sum_of_ages, 84)
示例3: post
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get [as 别名]
def post(self):
tournament = Tournament.get(self.request.get("tournament_key"))
team = Team.get(self.request.get("team_key"))
member_count = TournamentMembership.all().ancestor(tournament).count()
if member_count < tournament.max_enrollment:
TournamentMembership(parent=tournament, team=team, active=True).put()
#Unretire team if retired.
if team.retired:
misc.unretire_team(team)
if (member_count + 1 == tournament.max_enrollment and
tournament.seed_by != "Custom"):
tournament.schedule()
views.Tournaments.clear()
示例4: get
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get [as 别名]
def get(self):
team_key = db.Key.from_path("Team", self.request.get("team_key_name"))
team = Team.get(team_key)
if not team:
self.response.out.write("%s is not a valid team<BR>" % team_key)
return
self.response.out.write("%s<BR>" % team.key().name())
players = team.player_set
try:
submit.update_player_leaders(players)
except:
for player in players:
self.response.out.write("Error!: %s<BR>" % team.key().name())
self.response.out.write("...%s:%s<BR>" % (player.name, player.key().name()))
submit.update_team_leaders(team)
self.response.out.write("Unretiring Team: %s<BR>" % team.key().name())
team.retired = False
team.put()
views.TeamLeaders.clear()
views.PlayerLeaders.clear()
示例5: testCRUDObject
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get [as 别名]
def testCRUDObject(self):
# Test for creating, reading, updating, deleteing
# Create team
name = "Houkago Tea Time"
team = Team.create(name=name)
self.assertEqual(str(team), "<Team '%s'>" % name)
self.assertEqual(team.id, 1)
# Create members
for idx, n in enumerate(self.names):
member = Member.create(band=team, first_name=n[0], last_name=n[1], part=n[2])
self.assertEqual(str(member), "<Member '%s'>" % n[3])
self.assertEqual(member.id, idx + 1)
# Get member with primary key
ritsu = Member.get(1)
self.assertEqual(str(ritsu), "<Member 'Ritsu Tainaka : Dr'>")
# Get team the member Ritsu belongs to is Houkago Tea Time
team = ritsu.band
self.assertEqual(str(team), "<Team 'Houkago Tea Time'>")
# Get members with iterator
for idx, m in enumerate(team.members):
self.assertEqual(str(m), "<Member '%s'>" % self.names[idx][3])
# Yui changes instrument to castanets
macaron.bake() # Commit before changes
yui = Member.get(first_name="Yui", last_name="Hirasawa")
self.assert_(yui)
yui.part = "Castanets"
self.assertEqual(yui.part, "Castanets")
yui.save()
# Re-fetch Yui
member = Member.get(3)
self.assertEqual(member.part, "Castanets")
# Delete all members
self.assertEqual(team.members.count(), 4)
team.members.select(first_name="Ritsu").delete()
self.assertEqual(team.members.count(), 3)
team.members.delete()
self.assertEqual(team.members.count(), 0)
# Test for rollback
# Cancel the changes
macaron.rollback()
team = Team.get(1)
self.assertEqual(team.members.count(), 4)
# Add another member 'Sawako' as Gt1
member = Member.create(band=team, first_name="Sawako", last_name="Yamanaka", part="Gt1")
self.assertEqual(str(member), "<Member 'Sawako Yamanaka : Gt1'>")
# Re-fetch Sawako with index
sawako = team.members[4]
self.assertEqual(str(sawako), "<Member 'Sawako Yamanaka : Gt1'>")
# But, Sawako is not a member of the team
sawako.delete()
# Add another member Azusa through reverse relation of ManyToOne
team.members.append(first_name="Azusa", last_name="Nakano", part="Gt2")
azu = Member.get(first_name="Azusa")
self.assertEqual(str(azu), "<Member 'Azusa Nakano : Gt2'>")
# Okay, Yui changes part to Gt1
yui = Member.get(first_name="Yui")
yui.part = "Gt1"
yui.save()
self.assertEqual(yui.part, "Gt1")
# At last, there are five menbers
nm = self.names[:]
nm[2] = ("Yui", "Hirasawa", "Gt1", "Yui Hirasawa : Gt1")
nm.append(("Azusa", "Nakano", "Gt2", "Azusa Nakano : Gt2"))
for idx, m in enumerate(team.members):
self.assertEqual(str(m), "<Member '%s'>" % nm[idx][3])
# Foreign key constraint works on sqlite3 >= 3.6.19
ver = macaron.sqlite_version_info
if ver >= (3, 6, 19):
# Test for ON CASCADE
team = Team.get(1)
team.id = 2
team.save()
cnt = 0
for member in Member.all():
cnt += 1
self.assertEqual(member.band_id, 2)
self.assertEqual(cnt, Member.all().count())
# Test for ON DELETE
team.delete()
cnt = 0
for member in Member.all():
self.assertEqual(member.band, None)
cnt += 1
self.assertEqual(cnt, Member.all().count())
#.........这里部分代码省略.........
示例6: get
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get [as 别名]
def get(self):
# check for a cached version
# --------------------------------------------------------------------#
team_key = db.Key.from_path("Team", self.request.get("team_key_name"))
if self.emit(self.response.out, team_key):
return
# not cached or evicted from cache; regenerate
# --------------------------------------------------------------------#
team = Team.get(team_key)
if not team:
return
# win/draw/loss bars and banner text color
# --------------------------------------------------------------------#
longest_bar_length = max(team.wins, team.draws, team.losses)
banner_text_color = misc.get_contrasting_monochrome(team.color)
# player_table
# --------------------------------------------------------------------#
def position_getter(player):
return player.position.key().name()
def name_getter(player):
if player.played:
return "<a rel='team_players' href='%s'>%s</a>" % (player.get_box_href(), player.name)
else:
return "<b>" + player.name + "</b>"
def mng_getter(player):
if player.missing_next_game:
return "<img src='images/logos/thumb/logo_neutre_10.png' />"
else:
return ""
player_table = Table(
columns=[
Column("#", "Player number", attrgetter("number"), center=True),
Column("MNG", "Missing next game", mng_getter, center=True),
Column("Player", "Player name", name_getter),
Column("Position", "Player position", position_getter, divider=True),
Column("MV", "Movement allowance", attrgetter("mv")),
Column("ST", "Strength", attrgetter("st")),
Column("AG", "Agility", attrgetter("ag")),
Column("AV", "Armor value", attrgetter("av"), divider=True),
Column("SPP", "Star player points", attrgetter("spp")),
Column("Level", "Level", attrgetter("level"), divider=True),
Column("Pl", "Matches played", attrgetter("played")),
Column("MVP", "Most Valuable Player awards", attrgetter("mvps")),
Column("TD", "Touchdowns", attrgetter("tds_for")),
Column("P", "Pass completions", attrgetter("passes_for")),
Column("YP", "Yards passing", attrgetter("pyards_for")),
Column("R", "Pass receptions", attrgetter("rec_for")),
Column("YR", "Yards rushing", attrgetter("ryards_for")),
Column("K", "Kills", attrgetter("kills_for")),
Column("C", "Casualties", attrgetter("cas_for")),
Column("KO", "Knock outs", attrgetter("ko_for")),
Column("S", "Stuns", attrgetter("stun_for")),
Column("T", "Tackles", attrgetter("tckl_for")),
Column("I", "Interceptions", attrgetter("int_for"), divider=True),
Column("Value", "Player value", attrgetter("value")),
],
query=team.player_set.filter("retired =", False),
id="%s-player-table" % team.key(),
cls="tablesorter",
)
# stat_table
# --------------------------------------------------------------------#
def get_left_header(tuple):
team, which = tuple
return which.capitalize()
def getter(stat):
def getter_closure(tuple):
team, which = tuple
attr = getattr(team, "%s_%s" % (stat, which))
return ("<span class='tot_stat'>%d</span>" % attr) + (
"<span class='ave_stat'>%.1f</span>" % (attr / float(team.matches))
)
return getter_closure
stat_table = Table(
columns=[
Column("<span class='link' id='%s-show-averages-toggle'></span>" % team.key(), "", get_left_header),
Column("TD", "Touchdowns", getter("tds")),
Column("P", "Pass completions", getter("passes")),
Column("YP", "Yards passing", getter("pyards")),
Column("R", "Pass receptions", getter("rec")),
Column("YR", "Yards rushing", getter("ryards")),
Column("K", "Kills", getter("kills")),
Column("C", "Casualties", getter("cas")),
Column("KO", "Knock outs", getter("ko")),
#.........这里部分代码省略.........