Пример #1
0
def bias_yesno(request, parsed, module, game_questions):
    for title in game_questions.keys():
        game_questions[title]['title'] = title

    if request.method == 'POST':
        answers = {}
        if module.answers:
            answers = load_json(module.answers)
        for i in range(0, len(game_questions.values())):
            index = str(i)
            question_i = game_questions.values()[i]
            attr_i = request.POST.get('answer[' + index + ']')
            answers[question_i['title']] = attr_i
        module.answers = json.dumps(answers)
        module.biases = json.dumps(calculate_biases(game_questions, answers))
        module.save()
        return redirect(parsed['nextUrl'])
    else:
        ViewHelper.clear_game_answers(module)

    context = {
        'num_questions': len(game_questions),
        'questions': game_questions.values(),
    }

    return render_page(request, module, parsed, context)
Пример #2
0
def game2_game(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    game_questions = Module.get_game2_questions()

    if request.method == 'POST':
        answers = {}
        for i in range(len(game_questions)):
            index = str(i)
            ans = request.POST.get('answer[' + index + ']')
            title = game_questions[i]['title']

            # Store their answers
            answers[title] = ans

        module.answers2 = json.dumps(answers)
        module.save()

        return redirect(parsed['nextUrl'])
    else:
        ViewHelper.clear_game_answers(module)

    context = {
        'biases': Module.get_biases(),
        'display_mode': 'game2',
        'questions': game_questions,
    }

    return render_page(request, module, parsed, context)
Пример #3
0
def game(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    # Add title to each question
    game_questions = Module.get_game_questions()
    for title in game_questions.keys():
        game_questions[title]['title'] = title

    if request.method == 'POST':
        answers = {}
        if module.answers:
            answers = load_json(module.answers)
        for i in range(0, len(game_questions.values())):
            index = str(i)
            question_i = game_questions.values()[i]
            attr_i = request.POST.get('answer[' + index + ']')
            answers[question_i['title']] = attr_i
        module.answers = json.dumps(answers)
        module.biases = json.dumps(calculate_biases(game_questions, answers))
        module.save()

        #print("Redirecting to: " + parsed['nextUrl'])
        # TODO: figure out why we cannot calculate the nextUrl
        return redirect(reverse('backpocket_explain'))
        #return redirect(parsed['nextUrl'])
    else:
        ViewHelper.clear_game_answers(module)

    context = {
        'num_questions': len(game_questions),
        'questions': game_questions.values(),
    }

    return render_page(request, module, parsed, context)
Пример #4
0
def generic_page_controller(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    if request.method == 'POST':
        return save_form(request, module, parsed)

    return render_page(request, module, parsed, {})
Пример #5
0
def at_results(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    context = {
        'at_results': "green",
    }
    return render_page(request, module, parsed, context)
Пример #6
0
def home(request):
    request.session['start'] = '/decisions'
    request.session['partner'] = 'fp'
    course = Course.load_course(request)

    module0 = ViewHelper.load_module(request, '', Module0)
    module1 = ViewHelper.load_module(request, '', Module1)
    module2 = ViewHelper.load_module(request, '', Module2)
    #module3 = ViewHelper.load_module(request, '', Module3)

    student_classes = None
    if request.user.is_staff:
        student_classes = StudentClass.objects.filter(instructor=request.user)
    # Prior to 2019-03-17, the behavior was to take them to the tour page
    # Now, we just load the course info and redirect them to the decisions page
    if not course.intro_on:
        course = Course.load_course(request)
        course.intro_on = datetime.now()
        course.save()
        return redirect('/decisions/')

    if request.method == 'POST':
        request.user.has_tou = True
        request.user.save()
        print(request.user.email + " accepted terms of use")
        # 2021-07-23 - remove redirect to survey per cheryl
        #return redirect(reverse('take_survey'))

        #token = request.POST.get('stripeToken')
        #print("token: " + token)
        #stripe.api_key = settings.STRIPE_SECRET_KEY

        #try:
        #    charge = stripe.Charge.create(
        #        amount = 999,
        #        currency = "usd",
        #        source = token,
        #        description = "Subscription for Module 2"
        #    )
        #    print("Stripe charge id: " + charge.id)
        #except stripe.error.CardError as ce:
        #    print("Exception")
        #    print(ce)

    return render(
        request,
        'decisions/intro.html',
        {
            'form': forms.SignupWithNameForm,
            'module0': module0,
            'module1': module1,
            'module2': module2,
            #'module3': module3,
            'student_classes': student_classes,
            'my_classes': StudentClass.my_classes(course),
            'open_classes': StudentClass.open_classes(course),
            'stripe_public_key': settings.STRIPE_PUBLIC_KEY,
        })
Пример #7
0
def map(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    context = {
        'display_mode': 'all',
        'btn_label': 'Shall We Play A Game?',
    }
    return render_page(request, module, parsed, context)
Пример #8
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)
Пример #9
0
def show_map(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)

    context = {
        'display_mode': 'all',
        'btn_label': 'Ready to make better decisions?',
    }
    return render_page(request, module, parsed, context)
Пример #10
0
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)
Пример #11
0
def review(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    module = ViewHelper.load_module(request, parsed['currentStep'], Module)
    # TODO: move to ViewHelper
    module1 = load_previous_module(request)

    context = {
        'decision_buddy': module1.decision_buddy,
    }

    return render_page(request, module, parsed, context)
Пример #12
0
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)
Пример #13
0
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)
Пример #14
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)
Пример #15
0
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)
Пример #16
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)
Пример #17
0
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)
Пример #18
0
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,
        })
Пример #19
0
def render_page(request, module, parsed, context={}):
    context['is_mobile'] = ViewHelper.is_mobile(request)
    context['module'] = module
    context['nav'] = parsed
    context['sample_student'] = nylah
    context['mod_description'] = Module.get_description()

    return render(request, parsed['templatePath'], context)
Пример #20
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)
Пример #21
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(),
        })
Пример #22
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)
Пример #23
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)
Пример #24
0
    def send_welcome_email(self, user):
        emails = [user.email]
        subject = "Welcome to Decisive!"
        template = 'account/email/welcome_email.html'
        context = None

        try:
            results = ViewHelper.send_html_email(emails, subject, template,
                                                 context)
            msg = "Email sent to {}. [Code {}]".format(user.email, results)
            print(msg)
        except Exception as e:
            if hasattr(e, 'message'):
                print(e.message)
            else:
                print(e)
Пример #25
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)
Пример #26
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)
Пример #27
0
def journal(request):
    """
    Journal to keep track of old decisions
    """
    module1 = ViewHelper.load_module(request, '', Module1)
    return render(request, 'decisions/journal.html', {})
Пример #28
0
def render_page(request, module, parsed, context={}):
    context['is_mobile'] = ViewHelper.is_mobile(request)
    context['module'] = module
    context['nav'] = parsed

    return render(request, parsed['templatePath'], context)
Пример #29
0
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())
Пример #30
0
def restart(request):
    parsed = ViewHelper.parse_request_path(request, navigation())
    return base_restart(request, Module, parsed['prefix'])