本文整理汇总了Python中models.Team.save方法的典型用法代码示例。如果您正苦于以下问题:Python Team.save方法的具体用法?Python Team.save怎么用?Python Team.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Team
的用法示例。
在下文中一共展示了Team.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bench_test
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def bench_test(self):
User.objects.create_user("dillen", "[email protected]", "letmein")
team1 = Team(team_name="Winners",owner=User.objects.get(username__exact="dillen"))
p1 = Player(full_name="abc1",position="WR",team=team1,benched=False)
p2 = Player(full_name="abc2",position="WR",team=team1,benched=False)
team1.wr_count = 2
p3 = Player(full_name="abc3",position="WR",team=team1)
p4 = Player(full_name="abc4",position="WR")
team1.save()
p1.save()
p2.save()
p3.save()
p4.save()
#Bench someone already benched
self.assertEqual(bench(p3),False)
self.assertEqual(team1.wr_count,2)
self.assertEqual(p3.benched,True)
#Bench someone not on a team
self.assertEqual(bench(p4),False)
self.assertEqual(team1.wr_count,2)
self.assertEqual(p4.benched,True)
#Bench a WR
self.assertEqual(bench(p2),False)
self.assertEqual(team1.wr_count,1)
self.assertEqual(p1.benched,False)
self.assertEqual(p2.benched,True)
示例2: post
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def post(self):
post = self.request.POST
team = Team(name=post['team_name'])
team.save()
self.response.out.write("submitted")
示例3: test_swap_players_valid
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def test_swap_players_valid(self):
User.objects.create_user("dillen", "[email protected]", "letmein")
User.objects.create_user("eli", "[email protected]", "letmein")
team1 = Team(team_name="Winners",owner=User.objects.get(username__exact="dillen"))
team2 = Team(team_name="Losers",owner=User.objects.get(username__exact="eli"))
team1.save()
team2.save()
p1 = Player(full_name="abc1",position="WR",team=team1,benched=False)
p1_rb = Player(full_name="abc2",position="RB",team=team1,benched=False)
p1_benched = Player(full_name="abc3",position="WR",team=team1)
p1_team2 = Player(full_name="abc4",position="WR",team=team2,benched=False)
p1.save()
p1_rb.save()
p1_benched.save()
p1_team2.save()
p2 = Player(full_name="def1",position="WR",team=team1)
p2_rb = Player(full_name="def2",position="RB",team=team1)
p2_not_benched = Player(full_name="def3",position="WR",benched=False,team=team1)
p2_team2 = Player(full_name="def4",position="WR",team=team2)
p2.save()
p2_rb.save()
p2_not_benched.save()
p2_team2.save()
#Swap p1 and p2
self.assertEqual(swap_players(p1,p2),True)
self.assertEqual(p1.benched,True)
self.assertEqual(p2.benched,False)
self.assertEqual(swap_players(p2,p1),True)
self.assertEqual(p1.benched,False)
self.assertEqual(p2.benched,True)
#Try to swap a wr and rb
self.assertEqual(swap_players(p1,p2_rb),False)
self.assertEqual(p1.benched,False)
self.assertEqual(p2_rb.benched,True)
#Try to swap two not benched wr's
self.assertEqual(swap_players(p1,p2_not_benched),False)
self.assertEqual(p1.benched,False)
self.assertEqual(p2_not_benched.benched,False)
#Try to swap a benched wr with a not benched wr
self.assertEqual(swap_players(p1_benched,p2),False)
self.assertEqual(p1_benched.benched,True)
self.assertEqual(p2.benched,True)
#Try to swap two players from different teams
self.assertEqual(swap_players(p1_team2,p2),False)
self.assertEqual(p1_team2.benched,False)
self.assertEqual(p2.benched,True)
self.assertEqual(swap_players(p1,p2_team2),False)
self.assertEqual(p1.benched,False)
self.assertEqual(p2_team2.benched,True)
示例4: register_team
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def register_team(request):
serialized = TeamSerializer(data=request.DATA)
team = Team()
team.name = serialized.init_data['name']
team.email = serialized.init_data['email']
team.key = "something"
team.save()
return Response(TeamSerializer(team).data, status=status.HTTP_201_CREATED)
示例5: save_model
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def save_model(self, request, obj, form, change):
if not change:
team = Team()
team.name = obj.handle + " (Team)"
team.save()
obj.save()
team.members.add(obj)
team.save()
else:
obj.save()
示例6: init_teams
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def init_teams():
'''
Initialize the Team table with the team names retrieved from Kimono.
It removes all the entries and re-adds them.
'''
logger.info('Initializing teams...')
url = settings.KIMONO['teams_url']
teams = _get_results_collection1(url)
teams_name = [team['name'] for team in teams]
for team_name in teams_name:
if not Team.objects.filter(name__iexact=team_name).exists():
t = Team()
t.name = team_name
t.save()
示例7: test_play
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def test_play(self):
User.objects.create_user("dillen", "[email protected]", "letmein")
User.objects.create_user("eli", "[email protected]", "letmein")
team1 = Team(team_name="Winners",owner=User.objects.get(username__exact="dillen"))
p1 = Player(full_name="abc1",position="WR",team=team1,benched=False)
team1.wr_count = 1
p2 = Player(full_name="abc2",position="WR",team=team1)
p3 = Player(full_name="abc3",position="WR")
p4 = Player(full_name="abc4",position="QB",team=team1,benched=False)
team1.qb_count = 1
p5 = Player(full_name="abc5",position="QB",team=team1)
team1.save()
p1.save()
p2.save()
p3.save()
p4.save()
p5.save()
#Wrong position
self.assertEqual(play(p2,"QB"),False)
self.assertEqual(p2.benched,True)
self.assertEqual(team1.qb_count,1)
#Already playing
self.assertEqual(play(p1,"WR"),False)
self.assertEqual(p1.benched,False)
self.assertEqual(team1.wr_count,1)
#Not on a team
self.assertEqual(play(p3,"WR"),False)
self.assertEqual(p3.team, None)
self.assertEqual(p3.benched, True)
self.assertEqual(team1.wr_count,1)
#2 QB's at the same time
self.assertEqual(play(p5,"QB"),False)
self.assertEqual(p4.benched, False)
self.assertEqual(p5.benched, True)
self.assertEqual(team1.qb_count,1)
#2 WR's at the same time (valid)
self.assertEqual(play(p2,"WR"),True)
self.assertEqual(p2.benched, False)
self.assertEqual(team1.wr_count,2)
示例8: build_teams
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def build_teams():
clubs = Club.objects.all()
levels = Level.objects.all()
for c in clubs:
count_teams = randint(2,6)
index = 0
selected = []
while index < count_teams:
level = levels[randint(0, levels.count() - 1)]
while level in selected:
level = levels[randint(0, levels.count() - 1)]
selected.append(level)
team_name = '{club_name} {level_name}'.format(club_name=c.name, level_name=level.description)
t = Team(name=team_name, club=c)
t.save()
t.level.add(level)
index += 1
示例9: backdoor
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def backdoor(request):
war = war_gogo_or_404()
thisround = round_gogo_or_404(war, '/time') #First round should be gogo
if request.method == 'POST':
form = BackdoorLoginForm(request.POST)
if form.is_valid():
team = Team(war=war,
name=form.cleaned_data['team_name'],
passed_open_round_at=datetime.now(),
confirmed=False)
team.save()
return render_to_response('codewars2013/success.html', {})
else:
form = BackdoorLoginForm()
return render_to_response('codewars2013/backdoor.html', {
'form': form,
}, context_instance=RequestContext(request))
示例10: registerTeam
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def registerTeam(request):
if request.method == 'POST':
form = TeamForm(request.POST)
if form.is_valid():
rt = Team()
rt.teamName = form.cleaned_data["teamName"]
rt.member1 = form.cleaned_data["member1"]
rt.member2 = form.cleaned_data["member2"]
rt.member3 = form.cleaned_data["member3"]
rt.member4 = form.cleaned_data["member4"] or None
rt.member5 = form.cleaned_data["member5"] or None
rt.save()
return HttpResponseRedirect ("/confirmation")
elif request.method == 'GET':
form = TeamForm()
else:
return HttpResponseRedirect ("/404/")
return render(request, 'registerTeam.html', {"form": form, "teams": Team.objects.all().order_by("teamName")})
示例11: register
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def register(request):
if request.method == 'POST':
data = request.POST
print data
myDict = dict(data.iterlists())
players = []
for n in range(5):
name = myDict['name'][n]
email = myDict['email'][n]
print name, email
if not Riot.is_riot_user(name, email):
return HttpResponse("Player "+name+" is not in the db of riot")
role = myDict['role'][n]
print role
player = Player(name=name, email=email, role=role)
players.append(player)
team_name = myDict['team_name'][0]
Riot.is_top_team(team_name)
team_email = myDict['team_email'][0]
team = Team(name= team_name, email= team_email)
team.save()
team.set_password(myDict['password'][0])
team.save()
group = Group.objects.get(name='Team')
team.group.add(group)
team.save()
for player in players:
player.set_team(team)
player.save()
data_email = {'type': "confirmation",'team':team_name, 'players':players}
Riot.send_email(team_email, data_email)
#log in
team = authenticate(username=team_name, password=myDict['password'][0])
if team:
if team.is_active:
login(request, team)
return HttpResponseRedirect('/team/'+team_name)
else:
return HttpResponse("Your account is disabled")
else:
print "Invalid log details: {0}, {1}".format(team_name, myDict['password'][0])
return HttpResponse("Invalid log details")
else:
team_form = TeamForm()
player_form = PlayerForm()
return render(request, 'Register.html', {'team_form': team_form, 'player_form': player_form})
示例12: create_team
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def create_team(name, classification):
team = Team(name=name, colors='red', classification=classification)
team.save()
return team
示例13: add
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def add(request, site_id=None):
if request.method == "POST":
form = AddGameForm(request.POST)
teamFormset = TeamFormSet(request.POST, prefix="teamForm")
roleFormset = RoleFormSet(request.POST, prefix="roleForm")
if form.is_valid() and teamFormset.is_valid() and roleFormset.is_valid():
try:
# return HttpResponse(formset.forms[0].cleaned_data['players'])
print "adding game to site", site_id
print "Sites are", Site.objects.all()
print "Players are", Player.objects.all()
site = Site.objects.get(pk=site_id)
name = teamFormset.forms[0].cleaned_data["players"]
moderator, created = Player.objects.get_or_create(name=form.cleaned_data["moderator"], site=site)
if created:
moderator.save()
else:
moderator.clearCache()
game = Game(
title=form.cleaned_data["title"],
moderator=moderator,
start_date=form.cleaned_data["start_date"],
end_date=form.cleaned_data["end_date"],
site=site,
gameType=form.cleaned_data["type"],
)
if form.cleaned_data["url"] is not "":
game.url = form.cleaned_data["url"]
game.save()
for pName in form.cleaned_data["livedToEnd"]:
player, created = Player.objects.get_or_create(
name=pName, site=site, defaults={"firstGame": game, "lastGame": game, "score": 0, "played": 1}
)
player.save()
game.livedToEnd.add(player)
for tForm in teamFormset.forms:
if ("title" in tForm.cleaned_data) and (tForm.cleaned_data["title"] != ""):
title = tForm.cleaned_data["title"]
else:
title = tForm.cleaned_data["type"].title()
category = Category.objects.get(title=tForm.cleaned_data["type"])
# category = tForm.cleaned_data['type']
won = tForm.cleaned_data["won"]
players = [
Player.objects.get_or_create(name=p, site=site, defaults={"firstGame": game, "lastGame": game})[
0
]
for p in tForm.cleaned_data["players"]
]
for p in players:
p.save()
team = Team(title=title, category=category, site=site, won=won, game=game)
team.save()
for p in players:
team.players.add(p)
p.updateDates(game)
p.clearCache()
team.save()
game.team_set.add(team)
for rForm in roleFormset.forms:
if rForm.has_changed():
title = rForm.cleaned_data["title"]
pName = rForm.cleaned_data["player"]
text = rForm.cleaned_data["text"]
player, created = Player.objects.get_or_create(
name=pName, site=site, defaults={"firstGame": game, "lastGame": game}
)
role, created = Role.objects.get_or_create(title=title, game=game, player=player, text=text)
role.save()
game.save()
return HttpResponseRedirect(reverse("mafiastats_game", args=[game.id]))
except Exception as e:
logging.exception(e.args[0])
raise # let the default behavior handle the error, we just want to log it
else:
form = AddGameForm()
teamFormset = TeamFormSet(prefix="teamForm")
roleFormset = RoleFormSet(prefix="roleForm")
def boxIfString(val): # render either returns an iterable or
if type(val) is str: # a string. a string screws with the template
retval = [val] # so we must box strings up in a list
else:
retval = val
return retval
sheets = boxIfString((form.media + teamFormset.media).render_css())
bodyscripts = boxIfString((form.media + teamFormset.media).render_js())
if site_id:
site = Site.objects.get(pk=site_id)
else:
site = None
left_attrs = [("Team Name:", "title"), ("Team Type:", "type"), ("Won:", "won")]
for tform in teamFormset.forms:
tform.left_attrs = [(label, tform[property], property) for label, property in left_attrs]
return render_to_response(
"addGame.html",
{
"game_form": form,
#.........这里部分代码省略.........
示例14: edit
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def edit(request, game_id):
game = get_object_or_404(Game, pk=game_id)
if request.method == "POST":
form = AddGameForm(request.POST)
teamForm = TeamFormSetEdit(request.POST, prefix="teamForm")
roleForm = RoleFormSet(request.POST, prefix="roleForm")
if form.is_valid() and teamForm.is_valid() and roleForm.is_valid():
game = Game.objects.get(pk=form.cleaned_data["game_id"])
game.title = form.cleaned_data["title"]
game.url = form.cleaned_data["url"]
game.gameType = form.cleaned_data["type"]
moderator, created = Player.objects.get_or_create(
name=form.cleaned_data["moderator"],
site=game.site,
defaults={"firstGame": game, "lastGame": game, "score": 0, "played": 0},
)
if created:
moderator.save()
game.moderator = moderator
game.start_date = form.cleaned_data["start_date"]
game.end_date = form.cleaned_data["end_date"]
game.save()
game.livedToEnd.clear()
for pName in form.cleaned_data["livedToEnd"]:
player, created = Player.objects.get_or_create(
name=pName, site=game.site, defaults={"firstGame": game, "lastGame": game}
)
if created:
player.save()
game.livedToEnd.add(player)
for t in Team.objects.filter(game=game):
t.delete()
for tForm in teamForm.forms:
if ("title" in tForm.cleaned_data) and (tForm.cleaned_data["title"] != ""):
title = tForm.cleaned_data["title"]
else:
title = tForm.cleaned_data["type"].title()
team = Team(
game=game,
title=title,
category=Category.objects.get(title=tForm.cleaned_data["type"]),
site=game.site,
won=tForm.cleaned_data["won"],
)
team.save()
for pName in tForm.cleaned_data["players"]:
p, created = Player.objects.get_or_create(
name=pName,
site=game.site,
defaults={"firstGame": game, "lastGame": game, "score": 0, "played": 0},
)
p.updateDates(game)
p.save()
team.players.add(p)
team.save()
for role in Role.objects.filter(game=game):
role.delete()
for rForm in roleForm.forms:
if rForm.has_changed():
p, created = Player.objects.get_or_create(
name=rForm.cleaned_data["player"],
site=game.site,
defaults={"firstGame": game, "lastGame": game, "score": 0, "played": 0},
)
role = Role(game=game, player=p, text=rForm.cleaned_data["text"], title=rForm.cleaned_data["title"])
role.save()
game.save()
return HttpResponseRedirect(reverse("mafiastats_game", args=[game.id]))
else:
game = get_object_or_404(Game, pk=game_id)
teams = Team.objects.filter(game=game)
dateFormat = "%m/%d/%Y"
gameData = {
"title": game.title,
"url": game.url,
"livedToEnd": [p.name for p in game.livedToEnd.all()],
"moderator": game.moderator.name,
"start_date": game.start_date.strftime(dateFormat),
"end_date": game.end_date.strftime(dateFormat),
"type": game.gameType,
"game_id": game.id,
}
teamData = [
{
"title": team.title,
"won": team.won,
"type": team.category.title,
"team_id": team.id,
"players": [p.name for p in team.players.all()],
}
for team in teams
]
roleData = [
{"title": role.title, "player": role.player.name, "text": role.text}
for role in Role.objects.filter(game=game)
]
form = AddGameForm(gameData)
teamForm = TeamFormSetEdit(initial=teamData, prefix="teamForm")
roleForm = RoleFormSet(initial=roleData, prefix="roleForm")
left_attrs = [("Team Name:", "title"), ("Team Type:", "type"), ("Won:", "won")]
#.........这里部分代码省略.........
示例15: welcome_categories
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import save [as 别名]
def welcome_categories(request):
#must create project!
if request.method == 'POST': # If the form has been submitted...
#from session
email = request.session.get("signup-email")
password = request.session.get("signup-password")
username = request.session.get("signup-username")
#from request parameters
project = request.POST.get("project", "")
twitter = request.POST.get("twitter", "")
facebook = request.POST.get("facebook", "")
hashtags = request.POST.get("hashtags", "")
accounts = {}
accounts['twitter'] = twitter
accounts['facebook'] = facebook
twitter_properties = ""
facebook_properties = ""
if str(project).isspace() or not str(project): #not a project name
return render(request, "welcome_categories.html", {"message": 'Project name is required'})
elif str(project).isspace() or str(twitter).isspace() or str(facebook).isspace() or str(
hashtags).isspace() or str(hashtags).isspace(): #strings with gaps
return render(request, "welcome_categories.html", {"message": 'Please remove empty spaces'})
elif not str(twitter) and not str(facebook) and not str(hashtags): #empty strings
return render(request, "welcome_categories.html",
{"message": 'Please provide at least one parameter to initialize your project'})
elif validate_social_accounts(accounts) is not True:
social_accounts = validate_social_accounts(accounts)
return render(request, "welcome_categories.html",
{"message": 'Not Valid accounts!! You should fix the following accounts: '+', '.join(social_accounts)})
else:
#create user
#create project
#create properties
user = User(username=username, email=email)
user.set_password(password)
user.save()
#print user
team = Team(name=username, created_by=user)
team.save()
current_project = Project(name=project, created_by=user, owned_by=team)
current_project.save()
newgroup = Group.objects.create(name=str(project))
newgroup.save()
project = current_project
categoryK = Category.objects.get(name="Keywords")
categoryT = Category.objects.get(name="Twitter")
categoryF = Category.objects.get(name="Facebook")
if twitter:
Category_value.objects.create(value=twitter, category=categoryT, owned_by=project).save()
twitter_properties += twitter
else:
Category_value.objects.create(value="", category=categoryT, owned_by=project).save()
if facebook:
Category_value.objects.create(value=facebook, category=categoryF, owned_by=project).save()
facebook_properties += facebook
else:
Category_value.objects.create(value="", category=categoryF, owned_by=project).save()
if hashtags:
Category_value.objects.create(value=hashtags, category=categoryK, owned_by=project).save()
twitter_properties += ",%s" % hashtags
else:
Category_value.objects.create(value="", category=categoryK, owned_by=project).save()
user2 = authenticate(username=username, password=password)
if user2 is not None:
# the password verified for the user
if user2.is_active:
login(request, user2)
print("User is valid, active and authenticated")
#set user on session property to read it from results
else:
print("The password is valid, but the account has been disabled!")
return HttpResponseRedirect("/") # Redirect after POST
else:
# the authentication system was unable to verify the username and password
#print("The username or password were incorrect.")
return HttpResponseRedirect("/signup") # Redirect after POST
request.session['signup-username'] = ""
request.session['signup-email'] = ""
request.session['signup-password'] = ""
# setup project on twitter keyword connector
error_message = "no"
# if not update_project_connector(username, project, twitter_properties):
# error_message = "Error connecting to database. Project settings were not stored. Please contact the system administrator. Error code #3."
# messages.add_message(request, messages.ERROR, error_message)
# # setup project on twitter acount connector
# if not update_twitter_connector(username,project,twitter):
# error_message = "Error connecting to database. Project settings were not stored. Please contact the system administrator. Error code #4."
# messages.add_message(request, messages.ERROR, error_message)
# # setup project on fb connector
# if not update_facebook_connector(username, project, facebook_properties):
# error_message = "Error connecting to database. Project settings were not stored. Please contact the system administrator. Error code #5."
# messages.add_message(request, messages.ERROR, error_message)
if error_message == "no":
return HttpResponseRedirect("/welcome-train")
#.........这里部分代码省略.........