Can read and write the database now!

This commit is contained in:
Jan 2024-03-15 10:12:24 +01:00
parent d023307ccd
commit 9d54ae67db
5 changed files with 38 additions and 19 deletions

View File

@ -18,7 +18,7 @@ class Response(db.Model):
id = db.Column(db.Integer, primary_key=True)
likert_result = db.Column(db.Integer, nullable=False)
notes = db.Column(db.String(200))
date_created = db.Column(db.DateTime, default=datetime.utcnow)
date_created = db.Column(db.DateTime, default=datetime.today())
def __repr__(self) -> str:
return "<Task %r>" % self.id
@ -31,18 +31,27 @@ with app.app_context():
@app.route("/", methods=["GET", "POST"])
def testpage():
global data
if request.method == "POST":
data = request.form
print(data)
return redirect(url_for("datapage"))
likert_score = request.form["likertscale"]
text_input = request.form["feedback"]
print("new response: {likert_score_1} {text_input_1}".format(likert_score_1 = likert_score, text_input_1 = text_input))
new_response = Response(likert_result = likert_score, notes = text_input)
try:
db.session.add(new_response)
db.session.commit()
return redirect("/") #url_for("datapage")
except:
return "There was a problem while adding the response to the Database"
return render_template(
"layout1.html"
)
@app.route("/data")
def datapage():
responses = Response.query.order_by(Response.id).all()
return render_template(
"data.html",
value = str(data)
responses = responses
)

View File

@ -54,6 +54,11 @@ h2,h3 {
}
}
input, label {
display: block;
margin: 0.5rem 0;
}
.likert input {
max-width: 250px;
position: fixed;

View File

@ -8,8 +8,14 @@
</head>
<body>
<h2>Task number 1</h2>
<p>The Likertscale value is: {{ value }}</p>
<h2>Task number 1 responses</h2>
{% for response in responses%}
<p>Likert score:</p>
{{response.likert_result}}
<p>Feedback:</p>
{{response.notes}}
<p>-------------------------------------------------------------------------</p>
{% endfor %}
</body>
</html>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" /> <!-- styles.css {{ url_for('static', filename='styles.css')}}-->
<title>Testform</title>
</head>
@ -38,16 +38,10 @@
<label><input name="likertscale" type="radio" value="5" /><span>I like it a lot</span></label>
</div>
</div>
<div class="likercontainer">
<div class="likert">
<label><input name="likertscale2" type="radio" value="1" /><span>I dont like it at all</span></label>
<label><input name="likertscale2" type="radio" value="2" /><span>I dont like it</span></label>
<label><input name="likertscale2" type="radio" value="3" /><span>I am indifferent</span></label>
<label><input name="likertscale2" type="radio" value="4" /><span>I like it</span></label>
<label><input name="likertscale2" type="radio" value="5" /><span>I like it a lot</span></label>
</div>
</div>
<p><input type = "submit" value = "submit";"/></p>
<label for="feedback">Additional Feedback: </label>
<textarea id="feedback" name="feedback" rows="3" cols="30" maxlength="200"></textarea>
<p><input id="submitbutton" type = "submit" value = "submit";"/></p>
</form>
</body>

View File

@ -54,6 +54,11 @@ h2,h3 {
}
}
input, label {
display: block;
margin: 0.5rem 0;
}
.likert input {
max-width: 250px;
position: fixed;