Пример #1
0
def createNewGame(request):
    """ Creates a new 'GameStatus'. Supply the id of the 'game' you wish to use using 'game' as form data."""
    if request.method == 'POST':
        print(request.POST['cooperativeFM'])
        data_response = data_handler.createNewGame(
            request.POST['game'], request.POST['team1Name'],
            request.POST['team2Name'], request.POST['cooperativeFM'])
        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())

        current_game_status = data_handler.getCurrentGameStatus()
        fast_money_answers = {}
        fast_money_questions = list(
            Question.objects.filter(
                Q(game=current_game_status.current_game)
                & Q(is_fast_money=True)).values().order_by('question_order'))
        for question in fast_money_questions:
            fast_money_answers[question['id']] = list(
                Answer.objects.filter(question_id=question['id']).order_by(
                    '-point_value').values())

        json_response = {
            'isSuccessful': True,
            'state': data_handler.get_current_game_state_as_dict(),
            'fastMoneyAnswers': fast_money_answers
        }
        return JsonResponse(json_response)
Пример #2
0
def hideBoard(request):
    if request.method == 'POST':
        data_response = data_handler.toggleLogo(display_logo=True)
        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #3
0
def nextQuestion(request):
    """ Finds the next question and makes it the current_question. Also resets values such as question_total and total_wrong. """
    if request.method == 'POST':
        data_response = data_handler.setNextQuestion()
        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #4
0
def hideAnswer(request):
    """ Pass in an 'answerId' as formdata to add it to the 'currently_displayed' array and add it's value to the question_total. """
    if request.method == 'POST':
        answer_id = request.POST['answerId']
        data_response = data_handler.hideAnswer(answer_id)
        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #5
0
def unlockQuestion(request):
    """ Inserts the text of a fast money answer. """
    if request.method == 'POST':
        data_response = data_handler.unlockQuestion()

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #6
0
def togglePlayer1Answers(request):
    if request.method == 'POST':
        display_it = request.POST['displayIt']

        data_response = data_handler.togglePlayer1Answers(display_it)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #7
0
def awardPoints(request):
    """ Award points of question_total to a given team. Pass in 'teamToReward' as either 'one' or 'two' to award the points. """
    if request.method == 'POST':
        team_to_reward = request.POST['teamToReward']
        data_response = data_handler.awardPoints(team_to_reward)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #8
0
def editPoints(request):
    """ Used to manually update points. """
    if request.method == 'POST':
        team_one_points = request.POST['teamOnePoints']
        team_two_points = request.POST['teamTwoPoints']
        data_response = data_handler.editTeamPoints(team_one_points,
                                                    team_two_points)
        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #9
0
def addWrong(request):
    """ Adds a single one to the current question_total_wrong, setting it back to 0 if it reaches 4. """
    if request.method == 'POST':
        data_response = data_handler.addToWrongAnswerCount()

        if data_response['isSuccessful']:
            game_state = data_handler.get_current_game_state_as_dict()
            game_state['show_total_wrong'] = True
            data_handler.send_current_game_state(game_state)

        return setJsonResponse(data_response)
Пример #10
0
def displayWinnerScreen(request):
    """ Inserts the text of a fast money answer. """
    if request.method == 'POST':
        winner = request.POST['winner']

        data_response = data_handler.displayWinnerScreen(winner)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #11
0
def toggleFastMoney(request):
    """ Assigns a point value to a given fast money answer using the answer ID . """
    if request.method == 'POST':
        start_fast_money = request.POST['startFastMoney']

        data_response = data_handler.toggleFastMoney(start_fast_money)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #12
0
def toggleDisplayTimer(request):
    """ Assigns a point value to a given fast money answer using the answer ID . """
    if request.method == 'POST':
        display_timer = request.POST['displayTimer']

        data_response = data_handler.toggleDisplayTimer(display_timer)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #13
0
def toggleTimer(request):
    """ Assigns a point value to a given fast money answer using the answer ID . """
    if request.method == 'POST':
        startTimer = request.POST['startTimer']
        try:
            game_state = data_handler.get_current_game_state_as_dict()
            if startTimer == '1':
                game_state['fast_money']['start_timer'] = True
                game_state['fast_money']['stop_timer'] = False
            else:
                game_state['fast_money']['start_timer'] = False
                game_state['fast_money']['stop_timer'] = True
        except Exception as e:
            print(e)
            return JsonResponse({'isSuccessful': False})
        data_handler.send_current_game_state(game_state)
        return JsonResponse({
            'isSuccessful':
            True,
            'state':
            data_handler.get_current_game_state_as_dict()
        })
Пример #14
0
def togglePicture(request):
    if request.method == 'POST':
        if request.POST['display_picture'] == '1':
            display_picture = True
        else:
            display_picture = False

        data_response = data_handler.togglePicture(display_picture)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #15
0
def answerFastMoney(request):
    """ Inserts the text of a fast money answer. """
    if request.method == 'POST':
        answer_text = request.POST['answer']
        question = request.POST['question']
        player = request.POST['player']

        data_response = data_handler.updateFastMoneyAnswer(
            answer_text, question, player)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #16
0
def toggleFastMoneyValue(request):
    """ Assigns a point value to a given fast money answer using the answer ID . """
    if request.method == 'POST':
        question_id = request.POST['question']
        player = request.POST['player']
        display_it = request.POST['displayIt']

        data_response = data_handler.toggleFastMoneyValueDisplay(
            question_id, player, display_it)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #17
0
def assignPointValue(request):
    """ Assigns a point value to a given fast money answer using the answer ID . """
    if request.method == 'POST':
        answer_id = request.POST['answer_id']
        question = request.POST['question']
        player = request.POST['player']

        data_response = data_handler.assignFastMoneyAnswerPointValue(
            answer_id, question, player)

        if data_response['isSuccessful']:
            data_handler.send_current_game_state(
                data_handler.get_current_game_state_as_dict())
        return setJsonResponse(data_response)
Пример #18
0
def editTotalWrong(request):
    """ Manually updates the total wrong for the current question. """
    if request.method == 'POST':
        total_wrong = request.POST['totalWrong']
        show_buzzer = request.POST['showBuzzer']

        data_response = data_handler.editTotalWrong(total_wrong)

        if data_response['isSuccessful']:
            game_state = data_handler.get_current_game_state_as_dict()
            if show_buzzer == '1':
                game_state['show_total_wrong'] = True
            data_handler.send_current_game_state(game_state)

        return setJsonResponse(data_response)
Пример #19
0
def setJsonResponse(data_response):
    if data_response['isSuccessful']:
        return JsonResponse({
            'isSuccessful':
            True,
            'state':
            data_handler.get_current_game_state_as_dict()
        })
    else:
        if 'error' in data_response:
            return JsonResponse({
                'isSuccessful': False,
                'error_message': data_response['error']
            })
        else:
            return JsonResponse({'isSuccessful': False})
Пример #20
0
def adminquestions(request):
    """ Display the admin dashboard """
    question_set_list = list(QuestionSet.objects.values())
    game_state = data_handler.get_current_game_state_as_dict()
    current_game_status = data_handler.getCurrentGameStatus()
    fast_money_answers = {}
    if not game_state['no_active_game']:
        fast_money_questions = list(
            Question.objects.filter(
                Q(game=current_game_status.current_game)
                & Q(is_fast_money=True)).values().order_by('question_order'))
        for question in fast_money_questions:
            fast_money_answers[question['id']] = list(
                Answer.objects.filter(question_id=question['id']).order_by(
                    '-point_value').values())

    return render(
        request, 'base/admin-questions.html', {
            'question_sets': mark_safe(json.dumps(question_set_list)),
            'state': mark_safe(json.dumps(game_state)),
            'fast_money_answers': mark_safe(json.dumps(fast_money_answers))
        })
Пример #21
0
def game(request):
    game_state = data_handler.get_current_game_state_as_dict()

    return render(request, 'base/game_board.html',
                  {'state': mark_safe(json.dumps(game_state))})
Пример #22
0
def showSingleX(request):
    if request.method == 'POST':
        game_state = data_handler.get_current_game_state_as_dict()
        game_state['show_single_x'] = True
        data_handler.send_current_game_state(game_state)
        return JsonResponse({'isSuccessful': True})
Пример #23
0
def signalRepeatedAnswer(request):
    if request.method == 'POST':
        game_state = data_handler.get_current_game_state_as_dict()
        game_state['fast_money']['repeated_answer'] = True
        data_handler.send_current_game_state(game_state)
        return JsonResponse({'isSuccessful': True})