INQ-7 lecturer can add answer

This commit is contained in:
DarkPete 2018-12-18 16:58:01 +01:00
parent 08bd7879e9
commit e8279a4315
4 changed files with 40 additions and 11 deletions

10
App.py
View File

@ -76,6 +76,16 @@ def upvote(quest_id):
db.commit()
return '200'
@app.route('/answer/<quest_id>', methods=['POST'])
def answer(quest_id):
answer = request.get_data().decode("utf-8")
db = sqlite3.connect(DATABASE)
db_conn = db.cursor()
db_conn.execute("UPDATE question SET has_answer = 1 , answer = ? WHERE question_id = ?;",(answer,quest_id))
db.commit()
return redirect(url_for('student'))
############################################################
@app.route('/courses') #
def courses(): #

Binary file not shown.

View File

@ -1,6 +1,6 @@
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS question;
DROP TABLE IF EXISTS subjects;
DROP TABLE IF EXISTS subject;
CREATE TABLE user (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -17,6 +17,7 @@ CREATE TABLE question (
upvotes INTEGER NOT NULL,
has_answer BOOLEAN DEFAULT 0,
answer TEXT,
user_id INTEGER,
FOREIGN KEY (subject_id) REFERENCES subject (subject_id),
FOREIGN KEY (user_id) REFERENCES user (user_id)
);
@ -31,7 +32,7 @@ CREATE TABLE subject (
CREATE TABLE subject_day (
subject_day_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_id INTEGER,
topic TEXT NOT NULL
topic TEXT NOT NULL,
FOREIGN KEY (subject_id) REFERENCES subject(subject_id)
);
@ -45,11 +46,11 @@ INSERT INTO user (username, password, lecturer) VALUES ('leniwy_student31','pass
INSERT INTO subject (subject_name, user_id) VALUES ('Nudny przedmiot',1);
INSERT INTO subject (subject_name, user_id) VALUES ('TPI - najlepszy przedmiot',2);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (1, 'Nudne pytanie',0);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Czy pytania będą proste?',78);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Czy to będzie na egzaminie?',111);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Nic nie rozumiem.',6);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Chcę zdaaaaać',9);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (1, 'Nudne pytanie',0, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Czy pytania będą proste?',78, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Czy to będzie na egzaminie?',111, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Nic nie rozumiem.',6, 1);
INSERT INTO question (subject_id, question_text, upvotes, user_id) VALUES (2, 'Chcę zdaaaaać',9, 1);
select * from user;
select * from question;

View File

@ -34,14 +34,14 @@
<form class="col s12">
<div class="row">
<div class="input-field col s12">
<textarea id="textarea1" style="color:#fff" class="materialize-textarea" name ="questionText"></textarea>
<textarea id="{{question[0]}}" style="color:#fff" class="materialize-textarea" name ="questionText"> {{question[6]}}</textarea>
<label for="textarea1">Tutaj wpisz opdowiedź</label>
</div>
</div>
</form>
<div class="modal-footer">
<a href="#!" id="btn-cancel" class="modal-close waves-effect red btn" >Anuluj</a>
<a href="#!" id="btn-send" class="modal-close waves-effect waves-primary btn" >Wyślij</a>
<a href="#!" id="{{question[0]}}" name="btn-answer" class="modal-close waves-effect waves-primary btn btn-send-answer" >Wyślij</a>
</div>
</div>
</li>
@ -70,7 +70,7 @@
</div>
</div>
</div>
<!--
<div id="modalAsk" class="modal">
<div class="modal-content">
<h4>Odpowiedz na pytanie</h4>
@ -88,7 +88,7 @@
<a href="" id="btn-send" class="modal-close waves-effect waves-primary btn">Wyślij</a>
</div>
</div>
-->
{% endblock %}
{%block script%}
@ -106,6 +106,24 @@
instance.close();
});
$('.btn-send-answer').on('click', () => {
//alert(event.target.id);
//var question = $('#textarea1').val();
var url = 'answer/' + event.target.id;
var answerSelector = 'textarea[id=' + event.target.id + ']'
var answer = $(answerSelector).val()
$.ajax({
url: url,
type: 'POST',
data: answer,
succes: function(response) {
// location.reload();
}
});
//location.reload();
alertify.notify('Pomyślnie wysłano odpowiedź', 'success', 3);
});
$('.question--mark').on('click', () => {
alertify.notify('Pytanie oznaczone, jako szczególnie ważne.', 'success', 3);
});