コード例 #1
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def game1_results(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    context = {
        'answers': module.answers_json,
        'biases_results': load_json(module.biases),
        'questions': module.get_game_questions(),
    }

    return render_page(request, module, parsed, context)
コード例 #2
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def decisions_sample(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

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

    context = {
        'sample_cc': ViewHelper.load_json(module.sample_cc),
    }
    return render_page(request, module, parsed, context)
コード例 #3
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)
コード例 #4
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def summary(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        module.completed_on = datetime.datetime.now()
        module.save()
        # Increment the access counter
        ViewHelper.update_view_counter(request.user)
        return redirect(reverse('decisions_home'))

    context = {}
    return render_page(request, module, parsed, context)
コード例 #5
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def cc_exploring(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

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

    context = {
        'practice_cc2': ViewHelper.load_json(module.practice_cc2),
    }
    return render_page(request, module, parsed, context)
コード例 #6
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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)
コード例 #7
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def bias_remedies_practice(request):
    """
    Module Specific Controllers
    """
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        return redirect(parsed['nextUrl'])

    context = {
        'questions': Module.get_bias_remedy_questions(),
    }

    return render_page(request, module, parsed, context)
コード例 #8
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def game1_game(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module0 = ViewHelper.load_module(request, parsed['currentStep'], Module)
    questions_yes = None

    if request.method == 'POST':
        # Save any questions that were answered 'Yes'
        questions_yes = request.POST.getlist('question[]')
        request.session['questions_yes'] = questions_yes
        module0.answers = questions_yes
        print("In view: module0.answers {}".format(module0.answers))
        top_archetype = compute_archetype(request)
        print("In view: top_archetype {}".format(top_archetype))
        request.session['arch'] = top_archetype
        module0.archetype = top_archetype

        # compute_archetype calculates all of the scores but only returns the first one
        # the rest are stored in a session var called 'archetypes'
        if 'archetypes' in request.session:
            # extract everything but the first element
            archetypes = request.session['archetypes']
            print(archetypes)
            module0.other_archetypes = archetypes[1:]

        module0.save()
        return redirect(parsed['nextUrl'])
    else:
        # Retrieve any previously stored questions for this user
        # However, this is stored as a unicode array e.g.
        # [u'Ans1', u'Ans2'], so convert it first to a list
        # before passing it to the view
        if questions_yes is None:
            questions_yes = []

        asciidata = Module.to_ascii(module0.answers)
        questions_yes = asciidata.split(",")
        questions_yes = [x.strip() for x in questions_yes]
        request.session['questions_yes'] = questions_yes

    return render(
        request, parsed['templatePath'], {
            'questions': get_randomized_questions(),
            'questions_yes': questions_yes,
            'module': module0,
            'nav': parsed,
        })
コード例 #9
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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)
コード例 #10
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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)
コード例 #11
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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(),
        })
コード例 #12
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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)
コード例 #13
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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)
コード例 #14
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
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)
コード例 #15
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def bias_authority_practice(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    return bias_yesno(request, parsed, module,
                      Module.get_bias_authority_questions())
コード例 #16
0
ファイル: views.py プロジェクト: shubagoobadesigns/area
def restart(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    return base_restart(request, Module, parsed['prefix'])