Ejemplo n.º 1
0
def displayForm(request,form_id):
	#Displays the required form and handles submission
	
	try:
		form_id=int(form_id)
	except ValueError:
		raise Http404	
	
	frm=Form.objects.get(id=form_id)
	questions=Question.objects.filter(form=frm).order_by('id').values()
	options=[]
	properties=[]	
	for question in questions:
		if question['ques_type']=='radio':
			ques=Question.objects.get(id=question['id'])
			for option in Option.objects.filter(question=ques).order_by('id').values():
				options.append([option['opt'],option['opt']])
		properties.append({'ques':question['question'],'ques_type':question['ques_type'],'required':question['required'],'opts':options,'id':question['id']})	
	
	form=CustomForm(request.POST or None, properties=properties)
	if form.is_valid():
		response=form.cleaned_data
		usr=MyUser.objects.create()
		for key in response:
			ques=Question.objects.get(id=int(key))
			Responses.objects.create(form=frm, question=ques, resp=response[key],myuser=usr)
		return HttpResponseRedirect('/success/'+str(form_id))
	return render_to_response('form.html',{'form':form})
Ejemplo n.º 2
0
def displayForm(request, form_id):
    # Displays the required form and handles submission

    try:
        form_id = int(form_id)
    except ValueError:
        raise Http404

    kwargs = {}

    frm = Form.objects.get(id=form_id)
    questions = Question.objects.filter(form=frm).order_by("id").values()
    options = []
    properties = []
    for question in questions:
        if question["ques_type"] == "radio":
            ques = Question.objects.get(id=question["id"])
            for option in Option.objects.filter(question=ques).order_by("id").values():
                options.append([option["opt"], option["opt"]])
        properties.append(
            {
                "ques": question["question"],
                "ques_type": question["ques_type"],
                "required": question["required"],
                "opts": options,
                "id": question["id"],
            }
        )

    form = CustomForm(request.POST or None, properties=properties)
    if form.is_valid():
        response = form.cleaned_data
        usr = MyUser.objects.create()
        for key in response:
            ques = Question.objects.get(id=int(key))
            Responses.objects.create(form=frm, question=ques, resp=response[key], myuser=usr)

            # Setting up the argument list for the dynamic model's create call
            kwargs["ques_" + key] = response[key]

            # Getting the dynamic model
        dynModel = dynamic_model(form_id)

        # Performing the create query using kwargs
        dynModel.objects.create(**kwargs)

        return HttpResponseRedirect("/success/" + str(form_id))
    return render_to_response("form.html", {"form": form}, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def custom_func():
    form = CustomForm(request.form)  #Instatiates the form created in forms.py

    if request.method == 'POST':
        if form.validate(
        ) == False:  #If any of the inputs are empty and therefore doesn't validate
            flash('All fields are required.')  #Error message flashed to user
            return render_template('custom.html',
                                   form=form)  #Resets page with error message
        else:
            #Adds user input values to custom dictionary
            #League Settings Input
            custom_settings['teams'] = int(
                request.form['teams'])  #Converts string data into\
            #integer value; Form validates whether input is a whole number value

            custom_settings['auction_budget'] = int(
                request.form['auction_budget'])
            #Roster Composition
            custom_settings['qb'] = int(request.form['qb'])
            input_rb = float(
                request.form['input_rb'])  #Also takes in float values
            input_wr = float(request.form['input_wr'])
            input_flex = float(request.form['input_flex'])
            custom_settings['rb'] = input_rb + (input_flex / 2)
            custom_settings['wr'] = input_wr + (input_flex / 2)
            custom_settings['te'] = int(request.form['te'])
            custom_settings['k'] = int(request.form['k'])
            custom_settings['defense'] = int(request.form['defense'])
            custom_settings['bench'] = int(request.form['bench'])
            #Point Values
            custom_settings['pass_yds'] = 1 / float(request.form['pass_yds'])
            custom_settings['pass_tds'] = float(request.form['pass_tds'])
            custom_settings['interceptions'] = float(
                request.form['interceptions'])
            custom_settings['rush_yds'] = 1 / float(request.form['rush_yds'])
            custom_settings['rush_tds'] = float(request.form['rush_tds'])
            custom_settings['recs'] = float(request.form['recs'])
            custom_settings['rec_yds'] = 1 / float(request.form['rec_yds'])
            custom_settings['rec_tds'] = float(request.form['rec_tds'])
            custom_settings['two_point'] = float(request.form['two_point'])
            custom_settings['fl'] = float(request.form['fl'])
            #Kickers
            custom_settings['u20'] = float(request.form['u20'])
            custom_settings['u30'] = float(request.form['u30'])
            custom_settings['u40'] = float(request.form['u40'])
            custom_settings['u50'] = float(request.form['u50'])
            custom_settings['u70'] = float(request.form['u70'])
            custom_settings['pat'] = float(request.form['pat'])
            #Defense
            custom_settings['sack'] = float(request.form['sack'])
            custom_settings['def_int'] = float(request.form['def_int'])
            custom_settings['fr'] = float(request.form['fr'])
            custom_settings['def_td'] = float(request.form['def_td'])
            custom_settings['spc_td'] = float(request.form['spc_td'])
            custom_settings['sfty'] = float(request.form['sfty'])

            custom_qb,custom_rb,custom_wr,custom_te,custom_k,custom_def =\
            custom(qb_data, rb_data,wr_data, te_data, k_data, def_data,\
                    custom_percentiles, custom_settings) #Transforms data into custom results.

            tables = list(
            )  #Creates new list for dataframes and render_template function below
            titles = list()  #Creates new list for dataframe titles

            return render_template('custom.html',
                                   tables=[
                                       custom_qb.to_html(classes='custom'),
                                       custom_rb.to_html(classes='custom'),
                                       custom_wr.to_html(classes='custom'),
                                       custom_te.to_html(classes='custom'),
                                       custom_k.to_html(classes='custom'),
                                       custom_def.to_html(classes='custom')
                                   ],
                                   titles=[
                                       'na', 'Quarterbacks', 'Running Backs',
                                       'Wide Receivers', 'Tight Ends',
                                       'Kickers', 'Defenses/Special Teams'
                                   ],
                                   success=True)

    elif request.method == 'GET':  #Loads page information into web page index /custom
        return render_template('custom.html', form=form)