def add_season(request, league_id): league = League.objects.get(pk=league_id) comment = 'GET' if request.method == 'POST': comment = request.POST seasonname = request.POST['seasonname'] begindate = request.POST['begindate'] enddate = request.POST['enddate'] try: begindate = datetime.strptime(begindate, '%Y-%m-%d').date() except ValueError: comment = 'invalid begin date' begindate = None try: enddate = datetime.strptime(enddate, '%Y-%m-%d').date() except ValueError: comment = 'invalid end date' enddate = None if begindate and enddate and (begindate < enddate): try: s = Season.objects.get(name=seasonname) comment = 'There is already a season with that name.' except Season.DoesNotExist: s = Season( name=seasonname, begin_date=begindate, end_date=enddate, league=league ) s.save() comment = 'New season saved!' else: comment = 'Error with your chosen dates.' seasons = league.season_set.all() context = { 'league': league, 'seasons': seasons, 'comment': comment, } return render(request, 'leaguemanager/add_season.html', context)
# enroll players in league l = League.objects.get(name=leaguename) for name in playerlist: p = Player.objects.get(name=name) try: m = Membership.objects.get(player=p, league=l) except Membership.DoesNotExist: m = Membership(player=p, league=l) m.save() # create a season for the players l = League.objects.get(name=leaguename) try: s = Season.objects.get(name=seasonname, league=l) except Season.DoesNotExist: s = Season(name=seasonname, league=l) s.save() # now we will generate random games l = League.objects.get(name=leaguename) s = Season.objects.get(name=seasonname, league=l) while len(s.game_set.all()) < number_of_games: corpplayer = random.choice(playerlist) runnerplayer = corpplayer while runnerplayer == corpplayer: runnerplayer = random.choice(playerlist) corpplayer = Player.objects.get(name=corpplayer) runnerplayer = Player.objects.get(name=runnerplayer) outcome = random.choice([ 'draw', 'corp agenda victory', 'runner agenda victory', 'flatline', 'mill'
# enroll players in league l = League.objects.get(name=leaguename) for name in playerlist: p = Player.objects.get(name=name) try: m = Membership.objects.get(player=p, league=l) except Membership.DoesNotExist: m = Membership(player=p, league=l) m.save() # create a season for the players l = League.objects.get(name=leaguename) try: s = Season.objects.get(name=seasonname, league=l) except Season.DoesNotExist: s = Season(name=seasonname, league=l) s.save() # now we will generate random games l = League.objects.get(name=leaguename) s = Season.objects.get(name=seasonname, league=l) while len(s.game_set.all()) < number_of_games: corpplayer = random.choice(playerlist) runnerplayer = corpplayer while runnerplayer == corpplayer: runnerplayer = random.choice(playerlist) corpplayer = Player.objects.get(name=corpplayer) runnerplayer = Player.objects.get(name=runnerplayer) outcome = random.choice(['draw', 'corp agenda victory', 'runner agenda victory', 'flatline', 'mill']) random_number_of_days = random.choice(range(30)) gamedate = s.begin_date + datetime.timedelta(days=random_number_of_days)