def quiz_form(request):
    """
	View function for the quiz form page. Generates an 11 question quiz \
	with charfield and choicefield values, then passes the responses to \
	survey.py for scoring, the profile returned by the survey function \
	is passed to portfolio_return.py for graph and text generation. 

	"""
    context = {}
    res = None
    # generate web form
    if request.method == "GET":
        # links back to homepage to start over
        if "home" in request.GET:
            return HttpResponseRedirect("/quiz")
            # check to see if the form has been filled out
            # clean values and create args dict
        form = QuizForm(request.GET)
        if form.is_valid():

            args = {}
            args["q1"] = form.cleaned_data["how_old"]
            args["q2"] = form.cleaned_data["when_retire"]
            args["q3"] = form.cleaned_data["marital_status"]

            args["q4"] = form.cleaned_data["annual_income"].replace(",", "")
            args["q4"] = re.findall("[0-9]+", args["q4"])
            args["q4"] = args["q4"][0]

            args["q5"] = form.cleaned_data["income_stability"]
            args["q6"] = form.cleaned_data["main_goal"]
            args["q7"] = form.cleaned_data["most_important"]
            args["q8"] = form.cleaned_data["divest_in"]
            args["q9"] = form.cleaned_data["game_show"]
            args["q10"] = form.cleaned_data["stock_panic"]

            args["q11"] = form.cleaned_data["principal"].replace(",", "")
            args["q11"] = re.findall("[0-9]+", args["q11"])
            args["q11"] = int(args["q11"][0])

            # pass args dict to survey.py for scoring
            try:
                profile = survey.risk_tolerance(args)
            except Exception as e:

                print(e)
                # pass profile from survey.py to portfolio_return.py for \
                # text and graph generation
            try:
                portfolio_return.create_graphs_and_text(profile, args["q11"])
            except Exception as e:
                print(e)
                # load results page
            return HttpResponseRedirect("results")
            # if the form was not filled out/not properly filled out, reject the \
            # submission and re-load the page
    context["form"] = form
    return render(request, "index.html", context)
def quiz_form(request):
	"""
	View function for the quiz form page. Generates an 11 question quiz \
	with charfield and choicefield values, then passes the responses to \
	survey.py for scoring, the profile returned by the survey function \
	is passed to portfolio_return.py for graph and text generation. 

	"""
	context = {}
	res = None
	#generate web form
	if request.method == 'GET':
		#links back to homepage to start over
		if 'home' in request.GET:
				return HttpResponseRedirect('/quiz')
		#check to see if the form has been filled out
		#clean values and create args dict
		form = QuizForm(request.GET)
		if form.is_valid():

			args = {}
			args['q1'] = form.cleaned_data['how_old']
			args['q2'] = form.cleaned_data['when_retire']
			args['q3'] = form.cleaned_data['marital_status']

			args['q4'] = form.cleaned_data['annual_income'].replace(',', '')
			args['q4'] = re.findall('[0-9]+', args['q4'])
			args['q4'] = args['q4'][0]

			args['q5'] = form.cleaned_data['income_stability']
			args['q6'] = form.cleaned_data['main_goal']
			args['q7'] = form.cleaned_data['most_important']
			args['q8'] = form.cleaned_data['divest_in']
			args['q9'] = form.cleaned_data['game_show']
			args['q10'] = form.cleaned_data['stock_panic']

			args['q11'] = form.cleaned_data['principal'].replace(',', '')
			args['q11'] = re.findall('[0-9]+', args['q11'])
			args['q11'] = int(args['q11'][0])

			#pass args dict to survey.py for scoring 
			try:
				profile = survey.risk_tolerance(args)
			except Exception as e:

				print (e)
			#pass profile from survey.py to portfolio_return.py for \
			#text and graph generation
			try:
				portfolio_return.create_graphs_and_text(profile, args['q11'])
			except Exception as e:
				print (e)
			#load results page
			return HttpResponseRedirect('results')
	#if the form was not filled out/not properly filled out, reject the \
	#submission and re-load the page
	context['form'] = form
	return render(request, 'index.html', context)
def results(request):
	"""
	Generates the page to display the information and graphs for\
	a given investment portfolio. calls information from saved json files \
	and fixed urls using helper(), and provides the option to go to more or \
	less agressive profiles. Generates the page from results.html

	"""
	
	context = helper()
	profile = context['profile']
	allocations = ['Very_Conservative', 'Conservative', 'Balanced', 'Aggressive', 'Very_Aggressive']
	x = allocations.index(profile)
	if request.method == 'GET':
		if 'home' in request.GET:
				return HttpResponseRedirect('/quiz')
	#loads the results page for the next most agressive profile
	if 'more' in request.GET:
		if x != len(allocations)-1:
			x = x + 1
			print(x)
			profile = allocations[x]
			shit = portfolio_return.create_graphs_and_text(profile, 10000)
			context = helper()
			return render(request, 'results.html', context)
		else:
			return HttpResponse("Can't get more Agressive!")
	#loads the results page for the next least agressive profile
	if 'less' in request.GET:
		if x != 0:
			x = x - 1
			print (x)
			profile = allocations[x]
			print (profile)
			shit = portfolio_return.create_graphs_and_text(profile, 10000)
			context = helper()
			return render(request, 'results.html', context)
		else:
			return HttpResponse("Can't get less Agressive!")
	

	return render(request, 'results.html', context)
def results(request):
    """
	Generates the page to display the information and graphs for\
	a given investment portfolio. calls information from saved json files \
	and fixed urls using helper(), and provides the option to go to more or \
	less agressive profiles. Generates the page from results.html

	"""

    context = helper()
    profile = context["profile"]
    allocations = ["Very_Conservative", "Conservative", "Balanced", "Aggressive", "Very_Aggressive"]
    x = allocations.index(profile)
    if request.method == "GET":
        if "home" in request.GET:
            return HttpResponseRedirect("/quiz")
            # loads the results page for the next most agressive profile
    if "more" in request.GET:
        if x != len(allocations) - 1:
            x = x + 1
            print(x)
            profile = allocations[x]
            shit = portfolio_return.create_graphs_and_text(profile, 10000)
            context = helper()
            return render(request, "results.html", context)
        else:
            return HttpResponse("Can't get more Agressive!")
            # loads the results page for the next least agressive profile
    if "less" in request.GET:
        if x != 0:
            x = x - 1
            print(x)
            profile = allocations[x]
            print(profile)
            shit = portfolio_return.create_graphs_and_text(profile, 10000)
            context = helper()
            return render(request, "results.html", context)
        else:
            return HttpResponse("Can't get less Agressive!")

    return render(request, "results.html", context)