本文整理汇总了Python中models.Game.url方法的典型用法代码示例。如果您正苦于以下问题:Python Game.url方法的具体用法?Python Game.url怎么用?Python Game.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import url [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,
#.........这里部分代码省略.........