Beispiel #1
0
def create_league(request):
    gm = request.user.generalmanager_set.all()[0]
    form = LeagueForm()
    join_form = JoinLeagueForm()

    if request.method == 'POST':
        if 'create_league' in request.POST:
            form = LeagueForm(request.POST)
            if form.is_valid():
                league = form.save(commit=False)
                exists = True
                while exists:
                    lid = random.randint(0,999999)
                    try:
                        p = League.objects.get(lid=lid)
                    except ObjectDoesNotExist:
                        exists = False
                league.lid = lid
                league.commissioner=gm

                rs = RosterSettings.objects.create(num_Q=1,
                                                   num_R=2,
                                                   num_W=2,
                                                   num_T=1,
                                                   num_W_R_T=1
                                                   )
                league.roster_settings = rs
                ss = ScoringSettings.objects.create()
                league.scoring_settings = ss
                week = Week.objects.get(num=settings.CURRENT_WEEK)
                league.save()
                league_week = LeagueWeek.objects.create(league=league,
                                                        week=week,
                                                        status = LeagueWeek.PREDRAFT)
                league.current_week = league_week
                league.save()
                create_league_team(gm, league)
                return redirect('team_home', lid=league.lid)
        elif 'join_league' in request.POST:
            join_form = JoinLeagueForm(request.POST)
            if join_form.is_valid():
                lid = join_form.cleaned_data['lid']
                exists = True
                try:
                    league = League.objects.get(lid=lid)
                except ObjectDoesNotExist:
                    exists = False
                if exists:
                    create_league_team(gm, league)
                    return redirect('team_home', lid=league.lid)
                
    
    return render_to_response("league/create_league.html", 
                              {'form':form,
                               'join_form':join_form},
                              context_instance=RequestContext(request))
Beispiel #2
0
def index(request, *args, **kwargs):
    ''' Create the league page or select one '''
    data = {}
    data['leagues'] = League.objects.all()
    if request.method == 'GET':
        form = LeagueForm()
    elif request.method == 'POST':
        form = LeagueForm(request.POST)
        if form.is_valid():
            league = form.save()
            fill_league_with_players(league)
            return redirect('/league/%s/' % league.id)

    data['form'] = form
    return render(request, 'index.html', data)
Beispiel #3
0
def index(request, *args, **kwargs):
    """ Create the league page or select one """
    data = {}
    data["leagues"] = League.objects.all()
    if request.method == "GET":
        form = LeagueForm()
    elif request.method == "POST":
        form = LeagueForm(request.POST)
        if form.is_valid():
            league = form.save()
            # fill_league_with_players(league)
            league.populate_players()
            return redirect("/league/%s/" % league.id)

    data["form"] = form
    data["upload"] = UploadFileForm()
    return render(request, "index.html", data)