Exemplo n.º 1
0
def show_game(request, contest_permalink=None, game_permalink=None, ajax=None):
    """
        Simple view that show a single game with options to
                vote for the characters
    """

    the_contest = None
    the_game_vote = None
    contest_helper = ContestHelper()

    if request.POST:
        if (not request.user.is_authenticated()):
            if ajax==None:
                return HttpResponseRedirect(full_url('LOGIN') + '?next=%s' % request.path)
            elif ajax=='json':
                return json_error("LOGIN")
        voting_form = VotingForm(request.POST)
        if voting_form is not None:
            logger.debug("Voting form submitted.")
            if voting_form.is_valid():
                logger.debug("Voting form valid.")
                contest_helper.vote(voting_form.the_game, voting_form.the_character, request.user)
                if ajax == "json":
                    context = {
                            'success': True,
                            'data': request.user.id,
                        }
                    logger.debug("Sending ajax response.")
                    return json_return(context)
            else:
                logger.debug("Voting form invalid.")
        else:
            logger.debug("Voting form not submitted.")

    try:
        if contest_permalink is None:
            the_contest = contest_helper.get_current_contest()
        else:
            the_contest = contest_helper.get_contest_by_permalink(contest_permalink)

        if game_permalink is None:
            the_game = contest_helper.get_game_for_date(the_contest, datetime.today())
        else:
            the_game = contest_helper.get_game_by_permalink(game_permalink)
        if request.user.is_authenticated():
            the_game_vote = contest_helper.get_vote_for_game(the_game, request.user)
        votes_for_character1 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character1)
        votes_for_character2 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character2)
        if the_game_vote is None:
            voting_form1 = contest_helper.prepare_voting_form1(the_game)
            voting_form2 = contest_helper.prepare_voting_form2(the_game)
        else:
            # no need for forms if already voted
            voting_form1 = None
            voting_form2 = None
    except NoOpenContestException, e:
        raise Http404
Exemplo n.º 2
0
def show_contest(request, contest_permalink=None):
    """
      Schedule for character contest
    """
    the_contest = None
    the_games = None
    contest_helper = ContestHelper()
    try:
        if contest_permalink is None:
            the_contest = contest_helper.get_current_contest()
        else:
            the_contest = contest_helper.get_contest_by_permalink(contest_permalink)

        the_games = contest_helper.get_all_games_for_contest(the_contest.permalink)
        level32, level16, level8, quarter_final, semi_final, final = contest_helper.get_games_by_level(the_games)
    except NoOpenContestException, e:
        raise Http404