Exemplo n.º 1
0
def drag_and_drop(request):

    players = player_models.Player.objects.filter(pos__startswith='QB')
    player_list = [
        {'id': player.id,
                    'name': player.player_name,
                    'pic': player.picture,
                    'team': player.pro_team.short}
        for player in players
    ]

    return default_response(locals(), request, 'base_dragdrop.html')
Exemplo n.º 2
0
def playerpage(request, arg=None):
    """pylint """
    playerstats = []
    pos_list = ['QB', 'RB', 'WR', 'TE', 'K']
    player_list = []

    player = request.POST.get('playersearch','')
    players = simplejson.dumps([x.player_name for x in player_models.Player.objects.all()])

    if request.is_ajax():
        position = request.GET.items()[0][0]
        players = dict(
            (player.ranking, {
                'name': player.player.player_name,
                'team': player.player.pro_team.long,
                'picture': player.player.picture,
                'position': player.player.pos
            })
            for player in SeasonRanking.objects.get_position(position)
        )
        return HttpResponse(simplejson.dumps(players), content_type='application/json')

    if str(arg).upper() == 'TOP':
        top = True
        for pos in pos_list:
            player_list.append((pos, get_top_ten_for_pos(pos)))
        return base_views.default_response(locals(), request, 'base_playerpage_vars.html')

    if str(arg).upper() == 'DRAFT':
        draft = True
        player_list = [x for x in SeasonRanking.objects.all()]

    elif str(arg).upper() == 'TOPAVAIL':
        top = True
        avail = True
        for pos in pos_list:
            player_list.append((pos, get_top_ten_for_pos(pos, user=request.user)))

    elif str(arg).upper() in POS_LIST:
        pos = True
        for player in player_models.Player.objects.filter(pos__startswith=str(arg).upper):
            playerstats.append(player.SeasonTotal())
        playerstats.sort(key=lambda x: x.Allfanpts, reverse=True)

    elif not arg:
        search = True
        if player:
            playersearch = True
            search = False
            try:
                player = player_models.Player.objects.get(player_name=player)
                arg = player.id
            except player_models.Player.DoesNotExist:
                maybe_list = player_models.Player.objects.filter(player_name__icontains=player)
                return base_views.default_response(locals(), request, 'base_notfound_vars.html')
            playerobj, season_total = get_player_stats(arg, playerstats)
        pass
    else:
        playersearch = True
        playerobj, season_total = get_player_stats(arg, playerstats)
    return base_views.default_response(locals(), request, 'base_playerpage_vars.html')
Exemplo n.º 3
0
def draftpage(request, arg=None):
    """ Draft function isn't simple or small or easy to explain.
    Some of this is hackish, some of it is neat.
        Just understand that this is where the magic happens with the draft.
    """
    user = request.user
    if player_models.Team.objects.get(owner = user.userprofile.id).iscommish == 'Y':
        start = request.POST.get('start','')
        next = request.POST.get('next','')
        prev = request.POST.get('prev','')
        confirm = request.POST.get('confirm','')
        league = player_models.Team.objects.get(owner = user.userprofile.id).league
        try:
            draft_obj = draft_models.Draft.objects.get(league=league)
        except draft_models.Draft.DoesNotExist:
            draft_obj = ""
        if start:
            draft_obj.cur_round = 1
            draft_obj.save()
            order = draft_models.DraftOrder.objects.order_by('position').filter(
                draft_team__draft = draft_models.Draft.objects.get(league=league)
            )
        elif next:
            errors = validate_form(request.POST, draft_obj)
        elif prev:
            draft_obj.cur_round -= 1
            draft_obj.save()
        elif confirm:
            errors = validate_draft_and_generate_roster(draft_obj)
            #roster_exists = Roster.objects.filter(
            #   team__league = league
            # ).count > 1
        try:
            if not draft_models.Draft.objects.get(league=league).cur_round:
                instructions = True
            elif draft_models.Draft.objects.get(league=league).cur_round == 8  and confirm == '':
                confirm_list = []
                instructions = False
                confirmation = True
                teams = draft_models.DraftTeam.objects.filter(draft=draft_obj)
                for team in teams:
                    mockteam = MockDraftTeam(team)
                    confirm_list.append(mockteam)
            elif confirm:
                pass
            else:
                instructions = False
                cur_round = draft_models.Draft.objects.get(league=league).cur_round
                order = draft_models.DraftOrder.objects.order_by('position').filter(
                    draft_team__draft=draft_models.Draft.objects.get(league=league)
                )
                avail_players = simplejson.dumps(
                    [x.player_name for x in logic.draft_avail_players(league)]
                )
                pick = {}
                for team in order:
                    player = draft_models.DraftPick.objects.filter(
                        round=cur_round, draft_team=team.draft_team
                    )
                    if player:
                        player = [x.player for x in player]
                        player = player_models.Player.objects.get(pk=player[0].id)
                        pick.update({team.id:player})
        except draft_models.Draft.DoesNotExist:
            instructions = False

    return default_response(locals(), request, 'base_draft_vars.html')