-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
84 lines (61 loc) · 2.48 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
from flask_login import login_required, current_user
import models
from app import app
from flask import render_template, request, redirect, url_for
from models import Test, Question, Company, Candidate
from personality_predict import predict_personality
import random
@app.route('/')
def home():
if current_user.__class__ == models.Company:
user_class = 'company'
elif current_user.__class__ == models.Candidate:
user_class = 'candidate'
else:
user_class = 'anonymous'
print(user_class)
test = Test.query.order_by(Test.creation_date.desc()).limit(5).all()
return render_template('home.html', tests=test, user_class=user_class)
@app.route('/tests')
def tests():
all_tests = Test.query.all()
return render_template('tests.html', tests=all_tests)
@app.route('/test/<int:id>' , methods=['GET', 'POST'])
@login_required
def test_detail(id):
test = Test.query.filter_by(id=id).first()
if request.method=="POST":
return redirect(url_for('personality-test'))
return render_template('test_detail.html', test=test)
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/personality-test', methods=['GET', 'POST'])
@login_required
def personality_test():
ques_op = random.choices(Question.query.filter_by(domain_name='Openness').all(),k=2)
ques_nc = random.choices(Question.query.filter_by(domain_name='Neuroticism').all(),k=2)
ques_ev = random.choices(Question.query.filter_by(domain_name='Extraversion').all(),k=2)
ques_ac = random.choices(Question.query.filter_by(domain_name='Agreeableness').all(),k=2)
ques_cc = random.choices(Question.query.filter_by(domain_name='Conscientiousness').all(),k=2)
if request.method == 'POST':
data = request.form
return redirect(url_for('answer_page', json=json.dumps(data)), code=307)
ques_lis=[]
[ques_lis.extend(l) for l in (ques_op,ques_nc,ques_ev,ques_ac,ques_cc)]
random.shuffle(ques_lis)
return render_template('questionnaire.html', list_of_question=ques_lis)
@app.route('/answer', methods=['POST'])
def answer_page():
if request.method == 'POST':
data = request.form
prediction_data = {}
for tag, ans in data.items():
prediction_data[tag] = ans
ans = predict_personality(prediction_data)
print(ans)
return render_template('answer_page.html', results=ans)
@app.route('/company')
def company():
return render_template('company.html')