Exemplo n.º 1
0
def challenge(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.cc = json.dumps(request.POST.getlist('cc[]'))
        module.cc_not = json.dumps(request.POST.getlist('cc_not[]'))
        return save_form(request, module, parsed)

    context = {
        'cc': ViewHelper.load_json(module.cc),
        'cc_not': ViewHelper.load_json(module.cc_not),
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 2
0
def cheetah3_sheet(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.cc = json.dumps(request.POST.getlist('cc[]'))
        module.cc_occurred = json.dumps(request.POST.getlist('cc_occurred[]'))
        return save_form(request, module, parsed)

    context = {
        'cc': ViewHelper.load_json(module.cc),
        'cc_occurred': ViewHelper.load_json(module.cc_occurred),
        'decision': module.decision,
        'decision_as_question': module.decision_as_question,
        'cheetah_sheet': cheetah_sheet3,
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 3
0
def cheetah2_sheet(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.practice_cc1 = json.dumps(
            request.POST.getlist('practice_cc1[]'))
        module.practice_cc2 = json.dumps(
            request.POST.getlist('practice_cc2[]'))
        return save_form(request, module, parsed)

    context = {
        'practice_cc1': ViewHelper.load_json(module.practice_cc1),
        'practice_cc2': ViewHelper.load_json(module.practice_cc2),
        'cheetah_sheet': cheetah_sheet2,
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 4
0
def area(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    context = {
        'answers': ViewHelper.load_json(module.answers),
        'questions': module.game1_questions,
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 5
0
def cheetah5_report(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, 'cheetah5_apply', Module)

    context = {
        'biases_results': ViewHelper.load_json(module.biases),
        'cheetah_sheet': cheetah_sheet4,
        'module': module,
        'my_bias': ViewHelper.load_json(module.my_bias),
        'my_bias_impact': ViewHelper.load_json(module.my_bias_impact),
        'my_bias_remedy': ViewHelper.load_json(module.my_bias_remedy),
        'my_remedy': ViewHelper.load_json(module.my_remedy),
        'nav': parsed,
        'questions': Module.get_game2_questions(),
    }

    if parsed['currentStep'] == 'cheetah5_email':
        data = {}
        if request.user.is_authenticated():
            emails = [request.user.email]
            subject = "AREA Module {0}: Own it: Apply to real life!".format(
                module.display_num())
            template = 'module2/cheetah5/email.html'

            try:
                results = ViewHelper.send_html_email(emails, subject, template,
                                                     context)
                msg = "Email sent to {}. [Code {}]".format(
                    request.user.email, results)
            except Exception as e:
                if hasattr(e, 'message'):
                    print("Exception: " + e.message)
                else:
                    print("Exception: " + e)

                msg = "Unable to send email. There was an internal server error. Try again later."
        else:
            msg = "User is not authenticated. Cannot send email."

        data['message'] = msg
        print("Email: {0} to {1}".format(data['message'], request.user.email))
        return JsonResponse(data)

    return render_page(request, module, parsed, context)
Exemplo n.º 6
0
def cheetah5_sheet(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.my_bias_impact = json.dumps(
            request.POST.getlist('my_bias_impact[]'))
        module.my_bias_remedy = json.dumps(
            request.POST.getlist('my_bias_remedy[]'))
        module.my_remedy = json.dumps(request.POST.getlist('my_remedy[]'))
        return save_form(request, module, parsed)

    context = {
        'my_bias_impact': ViewHelper.load_json(module.my_bias_impact),
        'my_bias_remedy': ViewHelper.load_json(module.my_bias_remedy),
        'my_remedy': ViewHelper.load_json(module.my_remedy),
        'cheetah_sheet': cheetah_sheet5,
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 7
0
def decisions_personal(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.why = json.dumps(request.POST.getlist('why[]'))
        return save_form(request, module, parsed)

    context = {
        'why': ViewHelper.load_json(module.why),
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 8
0
def cheetah1_sheet(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.at = json.dumps(request.POST.getlist('at[]'))
        return save_form(request, module, parsed)

    context = {
        'at': ViewHelper.load_json(module.at),
        'cheetah_sheet': cheetah_sheet1,
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 9
0
def cheetah4_sheet(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)
    # Used for rendering the previous module contents
    module1 = load_previous_module(request)

    if request.method == 'POST':
        module.my_bias = json.dumps(request.POST.getlist('my_bias[]'))
        module.my_bias_impact = json.dumps(
            request.POST.getlist('my_bias_impact[]'))
        return save_form(request, module, parsed)

    context = {
        'cc': ViewHelper.load_json(module1.cc),
        'cc_occurred': ViewHelper.load_json(module1.cc_occurred),
        'decision': module1.decision,
        'decision_as_question': module1.decision_as_question,
        'my_bias': ViewHelper.load_json(module.my_bias),
        'my_bias_impact': ViewHelper.load_json(module.my_bias_impact),
        'cheetah_sheet': cheetah_sheet4,
    }
    return render_page(request, module, parsed, context)
Exemplo n.º 10
0
def game2_results(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    # Get the list of questions
    game_questions = Module.get_game2_questions()
    # Get our answers
    answers2 = ViewHelper.load_json(module.answers2)
    # Store our results
    biases = {}

    for i in range(len(game_questions)):
        title = game_questions[i]['title']
        bias = game_questions[i]['bias']
        expected = game_questions[i]['bias_answer']

        # Initialize
        if bias not in biases:
            biases[bias] = {
                'total': 0,
                'biased': 0,
                'ratio': 0,
            }

        biases[bias]['total'] += 1

        # Did we answer it?
        actual = -1
        if title in answers2:
            actual = answers2.get(title)
            if not actual:
                actual = -1
            else:
                actual = int(actual)

        if expected == actual:
            # We answered it correctly
            biases[bias]['biased'] += 1

        # Calculate the 'ratio' e.g. the total correct
        biases[bias]['ratio'] = int(
            float(biases[bias]['biased']) / float(biases[bias]['total']) * 100)

    print(biases)

    context = {
        'biases_results': biases,
    }

    return render_page(request, module, parsed, context)
Exemplo n.º 11
0
def game(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        attr = request.POST.get('attr')
        attrs = []
        answers = {}
        if module.answers:
            answers = ViewHelper.load_json(module.answers)
        for i in range(0, len(module.game1_questions().values())):
            index = str(i)
            question_i = module.game1_questions().values()[i]
            attr_i = request.POST.get('answer[' + index + ']')
            attrs.append(attr_i)
            if question_i not in answers:
                answers[question_i] = {
                    'title': module.game1_questions().keys()[i]
                }
            answers[question_i][attr] = attr_i

        module.answers = json.dumps(answers)
        module.save()
        return redirect(parsed['nextUrl'])
    else:
        print(parsed['section'])
        if parsed['section'] == 'game1':
            clear_game_answers(module)  # TODO - save old answers
            attr = 'easy'
            pageTitle = 'Is this decision EASY or HARD?'
        else:
            attr = 'confident'
            pageTitle = 'Are you CONFIDENT or UNSURE about this decision?'

    return render(
        request, parsed['prefix'] + 'game.html', {
            'module': module,
            'nav': parsed,
            'attr': attr,
            'labels': module.game_labels()[attr],
            'num_questions': len(module.game1_questions()),
            'pageTitle': pageTitle,
            'questions': module.game1_questions().values(),
        })
Exemplo n.º 12
0
def cheetah1_report(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)
    cheetah_sheet = CheetahSheet()

    context = {
        'ca': ViewHelper.load_json(module.cheetah_answers),
        'cheetah_sheet': cheetah_sheet,
        'module': module,
        'nav': parsed,
    }

    if parsed['currentStep'] == 'cheetah1_email':
        data = {}
        if request.user.is_authenticated():
            emails = [request.user.email]
            subject = "AREA Module {0}: Own it: Apply to real life!".format(
                module.display_num())
            template = 'module0/cheetah1/email.html'

            try:
                results = ViewHelper.send_html_email(emails, subject, template,
                                                     context)
                msg = "Email sent to {}. [Code {}]".format(
                    request.user.email, results)
            except Exception as e:
                if hasattr(e, 'message'):
                    print(e.message)
                else:
                    print(e)

                msg = "Unable to send email. There was a server error."
        else:
            msg = "User is not authenticated. Cannot send email."

        data['message'] = msg
        return JsonResponse(data)

    return render_page(request, module, parsed, context)