INQ-37 new schema tables, paths for lecturer added

This commit is contained in:
s441471 2019-01-23 12:39:46 +01:00
parent ecebcfc0b5
commit d817689ff2
11 changed files with 125 additions and 99 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"child_modules": [], "data_mtime": 1547481119, "dep_lines": [3, 4, 6, 7, 1, 1, 1, 1, 2, 5], "dep_prios": [10, 10, 10, 10, 5, 30, 30, 30, 5, 10], "dependencies": ["os", "sqlite3", "py_ldap", "json", "builtins", "abc", "sqlite3.dbapi2", "typing"], "deps_mtime": null, "hash": "8348518379dbd26da7bba668aea7c5b2", "id": "InQuire.App", "ignore_all": false, "interface_hash": "ec3f767fde6005996e95c22de8d0695e", "mtime": 1547496361, "options": {"allow_untyped_globals": false, "always_false": [], "always_true": [], "bazel": false, "check_untyped_defs": false, "disallow_any_decorated": false, "disallow_any_explicit": false, "disallow_any_expr": false, "disallow_any_generics": false, "disallow_any_unimported": false, "disallow_incomplete_defs": false, "disallow_subclassing_any": false, "disallow_untyped_calls": false, "disallow_untyped_decorators": false, "disallow_untyped_defs": false, "follow_imports": "silent", "follow_imports_for_stubs": false, "ignore_errors": false, "ignore_missing_imports": true, "local_partial_types": false, "mypyc": false, "no_implicit_optional": false, "platform": "linux", "plugins": [], "quick_and_dirty": false, "show_none_errors": true, "strict_optional": true, "strict_optional_whitelist": null, "warn_no_return": true, "warn_return_any": false, "warn_unused_ignores": false}, "path": "/home/pete/Desktop/TSI/InQuire/App.py", "size": 4216, "suppressed": ["flask", "ldap"], "version_id": "0.650"}
{"child_modules": [], "data_mtime": 1548242036, "dep_lines": [3, 4, 6, 7, 1, 1, 1, 1, 2, 5], "dep_prios": [10, 10, 10, 10, 5, 30, 30, 30, 5, 10], "dependencies": ["os", "sqlite3", "py_ldap", "json", "builtins", "abc", "sqlite3.dbapi2", "typing"], "deps_mtime": null, "hash": "05cd6568784fd7e444398598495b9d6a", "id": "InQuire.App", "ignore_all": false, "interface_hash": "c5a88d4554f651329fdcbd3acad9110d", "mtime": 1548242996, "options": {"allow_untyped_globals": false, "always_false": [], "always_true": [], "bazel": false, "check_untyped_defs": false, "disallow_any_decorated": false, "disallow_any_explicit": false, "disallow_any_expr": false, "disallow_any_generics": false, "disallow_any_unimported": false, "disallow_incomplete_defs": false, "disallow_subclassing_any": false, "disallow_untyped_calls": false, "disallow_untyped_decorators": false, "disallow_untyped_defs": false, "follow_imports": "silent", "follow_imports_for_stubs": false, "ignore_errors": false, "ignore_missing_imports": true, "local_partial_types": false, "mypyc": false, "no_implicit_optional": false, "platform": "linux", "plugins": [], "quick_and_dirty": false, "show_none_errors": true, "strict_optional": true, "strict_optional_whitelist": null, "warn_no_return": true, "warn_return_any": false, "warn_unused_ignores": false}, "path": "/home/pete/Desktop/TSI/InQuire/App.py", "size": 5403, "suppressed": ["flask", "ldap"], "version_id": "0.650"}

View File

@ -1 +1 @@
{"id": "py_ldap", "path": "/home/pete/Desktop/TSI/InQuire/py_ldap.py", "mtime": 1547422064, "size": 1104, "hash": "e5f0cb589b490273e2e64e70c2d78291", "data_mtime": 1547330771, "deps_mtime": null, "dependencies": ["builtins", "abc", "typing"], "suppressed": ["ldap"], "child_modules": [], "options": {"disallow_incomplete_defs": false, "quick_and_dirty": false, "no_implicit_optional": false, "disallow_any_decorated": false, "disallow_untyped_decorators": false, "show_none_errors": true, "always_true": [], "ignore_missing_imports": true, "warn_return_any": false, "disallow_subclassing_any": false, "allow_untyped_globals": false, "disallow_any_expr": false, "disallow_any_unimported": false, "disallow_untyped_defs": false, "always_false": [], "platform": "linux", "mypyc": false, "strict_optional": true, "strict_optional_whitelist": null, "bazel": false, "warn_no_return": true, "plugins": [], "local_partial_types": false, "ignore_errors": false, "warn_unused_ignores": false, "disallow_untyped_calls": false, "disallow_any_generics": false, "follow_imports_for_stubs": false, "follow_imports": "silent", "disallow_any_explicit": false, "check_untyped_defs": false}, "dep_prios": [5, 30, 30, 10], "dep_lines": [1, 1, 1, 1], "interface_hash": "58094464f005d9774c76e319279d5d35", "version_id": "0.650", "ignore_all": true}
{"child_modules": [], "data_mtime": 1547330771, "dep_lines": [1, 1, 1, 1], "dep_prios": [5, 30, 30, 10], "dependencies": ["builtins", "abc", "typing"], "deps_mtime": null, "hash": "c018d27c090e87f2a83c37f16a6a3d59", "id": "py_ldap", "ignore_all": true, "interface_hash": "58094464f005d9774c76e319279d5d35", "mtime": 1548232541, "options": {"allow_untyped_globals": false, "always_false": [], "always_true": [], "bazel": false, "check_untyped_defs": false, "disallow_any_decorated": false, "disallow_any_explicit": false, "disallow_any_expr": false, "disallow_any_generics": false, "disallow_any_unimported": false, "disallow_incomplete_defs": false, "disallow_subclassing_any": false, "disallow_untyped_calls": false, "disallow_untyped_decorators": false, "disallow_untyped_defs": false, "follow_imports": "silent", "follow_imports_for_stubs": false, "ignore_errors": false, "ignore_missing_imports": true, "local_partial_types": false, "mypyc": false, "no_implicit_optional": false, "platform": "linux", "plugins": [], "quick_and_dirty": false, "show_none_errors": true, "strict_optional": true, "strict_optional_whitelist": null, "warn_no_return": true, "warn_return_any": false, "warn_unused_ignores": false}, "path": "/home/pete/Desktop/TSI/InQuire/py_ldap.py", "size": 1113, "suppressed": ["ldap"], "version_id": "0.650"}

48
App.py
View File

@ -25,37 +25,40 @@ def home():
if not session.get('logged_in'):
return render_template('login.html')
else:
return redirect('/courses')
'''
if session['user_type'] == 'lecturer':
return redirect('/lecturer')
elif session['user_type'] == 'student':
return redirect('/courses')
'''
@app.route('/student',methods=['GET', 'POST'])
def student():
@app.route('/student/<lect_id>',methods=['GET', 'POST'])
def student(lect_id):
db = sqlite3.connect(DATABASE)
#db.row_factory = sql.Row
db_conn = db.cursor()
db_conn.execute("select * from question;")
db_conn.execute("select * from question where lecture_id = ?;",(lect_id,))
questions = db_conn.fetchall()
return render_template('student.html', questions=questions)
@app.route('/ask', methods=['POST'])
def ask():
@app.route('/ask/<lect_id>', methods=['POST'])
def ask(lect_id):
if request.method == 'POST':
question = request.get_data().decode("utf-8")
db = sqlite3.connect(DATABASE)
db_conn = db.cursor()
db_conn.execute("INSERT INTO question (subject_id, question_text, upvotes) VALUES (?, ?,?);",(1,question,0))
db_conn.execute("INSERT INTO question (lecture_id, question_text, upvotes) VALUES (?, ?,?);",(lect_id,question,0))
db.commit()
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
@app.route('/lecturer')
def lecturer():
@app.route('/lecturer/<lect_id>')
def lecturer(lect_id):
db = sqlite3.connect(DATABASE)
#db.row_factory = sql.Row
db_conn = db.cursor()
db_conn.execute("select * from question;")
db_conn.execute("select * from question where lecture_id = ?;",(lect_id,))
questions = db_conn.fetchall()
return render_template('lecturer.html', questions=questions)
@ -66,7 +69,7 @@ def do_login():
ldapquery = py_ldap.LdapQuery(servers, port, root)
auth=ldapquery.authenticate(login+suffix, password)
searchstring=ldapquery.search_user(login);
if auth==True and (searchstring[0][0].lower().find('ou=faculty')!=-1 or login == 's396355'):
if auth==True and (searchstring[0][0].lower().find('ou=faculty')!=-1 or login == 's396355' or login == 's441471'):
session['logged_in'] = True
session['user_type'] = 'lecturer'
elif auth==True and searchstring[0][0].lower().find('ou=students')!=-1:
@ -115,11 +118,21 @@ def do_delete():
############################################################
@app.route('/courses') #
def courses(): #
return render_template('courses.html')
db = sqlite3.connect(DATABASE)
#db.row_factory = sql.Row
db_conn = db.cursor()
db_conn.execute("select * from course;")
courses = db_conn.fetchall()
return render_template('courses.html', courses=courses)
@app.route('/lectures/<lect_id>', methods=['POST', 'GET'])
def lectures(lect_id):
return render_template('lectures.html')
def lectures(lect_id):
db = sqlite3.connect(DATABASE)
#db.row_factory = sql.Row
db_conn = db.cursor()
db_conn.execute("select * from lecture where course_id = ?;",(lect_id,))
lectures = db_conn.fetchall()
return render_template('lectures.html', lectures = lectures)
@app.route('/account', methods=['GET', 'POST'])
def account():
@ -129,6 +142,15 @@ def account():
return redirect(url_for('student')) #
############################################################
@app.route('/questions/<lect_id>')
def goto_questions(lect_id):
if session.get('user_type') == 'lecturer':
return redirect('lecturer/{}'.format(lect_id))
else: #
return redirect('student/{}'.format(lect_id))

Binary file not shown.

View File

@ -1,6 +1,7 @@
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS question;
DROP TABLE IF EXISTS subject;
DROP TABLE IF EXISTS course;
DROP TABLE IF EXISTS lecture;
CREATE TABLE user (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -11,47 +12,57 @@ CREATE TABLE user (
CREATE TABLE question (
question_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_id INTEGER NOT NULL,
lecture_id INTEGER NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
question_text TEXT NOT NULL,
upvotes INTEGER NOT NULL,
has_answer BOOLEAN DEFAULT 0,
answer TEXT,
user_id INTEGER,
FOREIGN KEY (subject_id) REFERENCES subject (subject_id),
FOREIGN KEY (lecture_id) REFERENCES lecture (lecture_id),
FOREIGN KEY (user_id) REFERENCES user (user_id)
);
CREATE TABLE subject (
subject_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_name TEXT UNIQUE NOT NULL,
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (user_id)
CREATE TABLE course (
course_id INTEGER PRIMARY KEY AUTOINCREMENT,
course_name TEXT UNIQUE NOT NULL
/*user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (user_id)*/
);
CREATE TABLE subject_day (
subject_day_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_id INTEGER,
CREATE TABLE lecture (
lecture_id INTEGER PRIMARY KEY AUTOINCREMENT,
lecture_date DATE,
course_id INTEGER,
topic TEXT NOT NULL,
FOREIGN KEY (subject_id) REFERENCES subject(subject_id)
FOREIGN KEY (course_id) REFERENCES course(course_id)
);
/*
INSERT INTO user (username, password, lecturer) VALUES ('admin','admin',1);
INSERT INTO user (username, password, lecturer) VALUES ('jassem','jassem',1);
INSERT INTO user (username, password, lecturer) VALUES ('user','user',0);
INSERT INTO user (username, password, lecturer) VALUES ('max','max',0);
INSERT INTO user (username, password, lecturer) VALUES ('leniwy_student31','password',0);
*/
INSERT INTO course (course_name) VALUES ('Tworzenie systemów informatycznych');
INSERT INTO course (course_name) VALUES ('Optymalizacja kombinatoryczna');
INSERT INTO course (course_name) VALUES ('Podstawy JavaScriptu dla programistów C#');
INSERT INTO question (lecture_id, question_text, upvotes) VALUES (1, 'Nudne pytanie',0);
INSERT INTO question (lecture_id, question_text, upvotes) VALUES (2, 'Czy pytania będą proste?',78);
INSERT INTO question (lecture_id, question_text, upvotes) VALUES (2, 'Czy to będzie na egzaminie?',111);
INSERT INTO question (lecture_id, question_text, upvotes) VALUES (2, 'Nic nie rozumiem.',6);
INSERT INTO question (lecture_id, question_text, upvotes) VALUES (2, 'Chcę zdaaaaać',9);
INSERT INTO lecture (lecture_date,course_id,topic) VALUES('2019-01-16',1,'Peopleware');
INSERT INTO lecture (lecture_date,course_id,topic) VALUES('2019-01-09',1,'Jak zostać komputerowym geniuszem?');
INSERT INTO lecture (lecture_date,course_id,topic) VALUES('2018-12-01',1,'Jak zaplanować projekt informatyczny?');
INSERT INTO lecture (lecture_date,course_id,topic) VALUES('2019-01-18',2,'Zaawansowane algorytmy znajdujące skojarzenia w grafach');
INSERT INTO lecture (lecture_date,course_id,topic) VALUES('2019-01-07',3,'Wprowadzenie do Ajaxa');
INSERT INTO lecture (lecture_date,course_id,topic) VALUES('2019-01-14',3,'Wysyłanie i ściąganie danych przy pomocy Ajaxa');
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, 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;
select * from subject;
select * from question;

View File

@ -3,6 +3,7 @@
{% block content %}
<div class="container header__container">
<a href="/logout" id="btn--logout" class="btn-floating color--primary btn-small waves-effect waves-light" title="Wyloguj się"><i class="material-icons">power_settings_new</i></a>
<div class="row">
<div class="col s12">
<div class="card color--primary white-text">
@ -18,24 +19,14 @@
<div class="card-content">
<span class="card-title card-title__body"></span>
<ul id="questions-list">
{% for course in courses %}
<li class="row">
<span class="col s7" style="display:flex; align-items:center; text-align: left">
Tworzenie systemów informatycznych
{{course[1]}}
</span>
<a id="1" name="Tworzenie systemów informatycznych" class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
<li class="row">
<span class="col s7" style="display:flex; align-items:center; text-align: left">
Optymalizacja kombinatoryczna
</span>
<a id="2" name="Optymalizacja kombinatoryczna" class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
<li class="row" style="margin-bottom: 0">
<span class="col s7" style="display:flex; align-items:center; text-align: left">
Podstawy JavaScriptu dla programistów C#
</span>
<a id="3" name="Podstawy JavaScriptu dla programistów C#" class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
<a id="{{course[0]}}" name="Tworzenie systemów informatycznych" class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
{% endfor %}
</ul>
</div>
</div>

View File

@ -102,14 +102,16 @@
$('.collapsible').collapsible();
});
$('.btn-cancel').on('click', () => {
$('.btn-cancel').on('click', function(event) {
event.preventDefault();
var clpsID = $("li.active").attr("id");
var close = '#clpbtn' + clpsID;
//alert(close);
$(close).click();
});
$('.btn-send-answer').on('click', () => {
$('.btn-send-answer').on('click', function(event) {
event.preventDefault();
//alert(event.target.id);
//var question = $('#textarea1').val();
var url = 'answer/' + event.target.id;
@ -128,16 +130,20 @@
});
$('.question--mark').on('click', () => {
$('.question--mark').on('click', function(event) {
event.preventDefault();
alertify.notify('Pytanie oznaczone, jako szczególnie ważne.', 'success', 3);
});
$('.question--respond').on('click', () => {
$('.question--respond').on('click', function(event) {
event.preventDefault();
alertify.notify('Odpowiedź została udzielona.', 'success', 3);
});
$('.question--add').on('click', () => {
$('.question--add').on('click', function(event) {
event.preventDefault();
alertify.notify('Odpowiedź została udzielona. Pytanie zostało dodane do wykładu.', 'success', 3);
});
$('.question--remove').on('click', () => {
$('.question--remove').on('click', function(event) {
event.preventDefault();
var delID = $("li[class='active']").attr('id');
alertify.confirm("Czy napewno usunąć pytanie?",function(){
$.ajax({

View File

@ -3,6 +3,7 @@
{% block content %}
<div class="container header__container">
<a href="/logout" id="btn--logout" class="btn-floating color--primary btn-small waves-effect waves-light" title="Wyloguj się"><i class="material-icons">power_settings_new</i></a>
<div class="row">
<div class="col s12">
<div class="card color--primary white-text">
@ -18,33 +19,17 @@
<div class="card-content">
<span class="card-title card-title__body">Pytania studentów</span>
<ul id="questions-list">
<li class="row">
<span class="date">
16.01.2019
</span>
<span class="col s7" style="display:flex; align-items:center; text-align: left">
Peopleware
</span>
<a class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
<li class="row">
<span class="date">
9.01.2019
</span>
<span class="col s7" style="display:flex; align-items:center; text-align: left">
Jak zostać komputerowym geniuszem?
</span>
<a class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
<li class="row" style="margin-bottom: 0">
<span class="date">
19.01.2019
</span>
<span class="col s7" style="display:flex; align-items:center; text-align: left">
Jak zaplanować projekt informatyczny?
</span>
<a class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
{% for lecture in lectures %}
<li class="row">
<span class="col s2" style="display:flex; align-items:center; text-align: left">
{{ lecture[1] }}
</span>
<span class="col s5" style="display:flex; align-items:center; text-align: left">
{{ lecture[3] }}
</span>
<a id="{{ lecture[0] }}" class="col s5 btn--answer waves-effect waves-light btn-large red">OTWÓRZ</a>
</li>
{% endfor %}
</ul>
</div>
</div>
@ -58,18 +43,22 @@
<script>
/////////// DO OGARNIĘCIA /////////////
$('.btn--answer').on('click', () => {
window.location.href = "/student"
$('.btn--answer').on('click', function(event) {
event.preventDefault();
var link = '/questions/' + event.target.id;
window.location.href = link;
/*
$.ajax({
url: '/account',
type: 'POST',
succes: function(response) {
conosle.log(response)
url: link,
type: 'POST',
succes: function(response) {
location.reload();
}
});
alertify.notify('Pomyślnie oceniono pytanie', 'success', 3);
location.reload();
*/
})
});
</script>
{% endblock %}

View File

@ -48,12 +48,14 @@
{% endwith %}
</div>
</div>
<!--
<div class="row">
<div class="col s12">
<p class="forgot__text">Zapomniałeś hasła?</p>
<p class="forgot__text">Załóż konto!</p>
</div>
</div>
-->
</form>
</div>
</div>

View File

@ -73,7 +73,7 @@
<div class="col s12">
<div class="card color--primary white-text">
<div class="card-content footer__container--content">
<div class="col s6">Powrót</div>
<div class="col s6" href="/courses" >Powrót</div>
<!--<div class="col s4 modal-trigger" href="#modalAsk">Zadaj pytanie</div>-->
<div class="col s6">Informacje</div>
</div>
@ -112,15 +112,20 @@
$('.collapsible').collapsible();
});
$('#btn-cancel-ask').on('click', () => {
$('#btn-cancel-ask').on('click', function(event) {
event.preventDefault();
$('#ask-question').click();
});
$('#btn-send').on('click', () => {
$('#btn-send').on('click', function(event) {
event.preventDefault();
var question = $('#textarea1').val();
var pathloc = window.location.pathname;
var splpath = pathloc.split('/');
var askUrl = '/ask/' + splpath.pop();
$.ajax({
url: '/ask',
url: askUrl,
type: 'POST',
data: question,
complete: function() {
@ -134,8 +139,8 @@
});
$('.btn-thumb-up').on('click', () => {
//alert(event.target.id)
$('.btn-thumb-up').on('click', function(event) {
event.preventDefault();
var link = '/upvote/' + event.target.id;
$.ajax({
url: link,