diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..c296a561f Binary files /dev/null and b/.DS_Store differ diff --git a/app.py b/app.py index 3d1808cf6..bbbc8ee41 100644 --- a/app.py +++ b/app.py @@ -1,32 +1,418 @@ import os +from flask import Flask, redirect, render_template, request, url_for, session, flash +import psycopg2 +from psycopg2 import pool -from flask import (Flask, redirect, render_template, request, - send_from_directory, url_for) app = Flask(__name__) +app.secret_key = 'your secret key2' +#Database connection +minconn = 3 +maxconn = 10 +conn_pool = psycopg2.pool.SimpleConnectionPool(minconn, maxconn, + user = "postgres", + password = "postgres", + host = "20.203.212.232", + port = "5435", + database = "internprj") -@app.route('/') + +#Function for login page +@app.route('/', methods=['GET', 'POST']) def index(): - print('Request for index page received') - return render_template('index.html') -@app.route('/favicon.ico') -def favicon(): - return send_from_directory(os.path.join(app.root_path, 'static'), - 'favicon.ico', mimetype='image/vnd.microsoft.icon') + conn = conn_pool.getconn() # connect to database + cur = conn.cursor() # prepare query + cur.execute('SELECT * FROM engineer') #get engineer list + engineers_li = cur.fetchall() + + if request.method == 'POST': + engineer_id= request.form.get('engineerID') # Get engineer_id + + conn = conn_pool.getconn() + try: + cur = conn.cursor() + cur.execute('SELECT * FROM engineer WHERE engineer_id = %s', (engineer_id,)) #get engineer with given id + result = cur.fetchone() + if result: + session['engineer'] = result # load given engineer + return redirect(url_for('dashboard')) # open dashboard.html + + else: + return redirect(url_for('index')) # redirect to index.html + finally: + conn_pool.putconn(conn) # end connection to database + return render_template('login.html', list_engineers=engineers_li) + +#function to save new engineer +@app.route('/save', methods=['POST']) +def save(): + conn = conn_pool.getconn() + cur = conn.cursor() + + if request.method == 'POST': + engineer_name_new = request.form.get('engineerNameNew') # take inputted engineer name + cur.execute("INSERT INTO public.engineer(engineer_id, engineer_name) VALUES (DEFAULT, %s)", (engineer_name_new,)) + #inserts engineer with given values taken from params engineer_name_new + conn.commit() + flash('Added Successfully') + return redirect(url_for('index')) + +#function to load dashboard with list of engineers +@app.route('/engineers', methods=['GET']) +def engineers(): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM engineer') + engineers_li = cur.fetchall() + conn_pool.putconn(conn) + return render_template('dashboard.html', list_engineer=engineers_li) + +#functino for dashbaord page +@app.route('/dashboard', methods=['GET', 'POST']) +def dashboard(): + engineer = session.get('engineer') #get taken engineer + + if engineer is None: + return redirect(url_for('index')) + + conn = conn_pool.getconn() + + try: + cur = conn.cursor() # prepare query + cur.execute('SELECT * FROM mip') + mips = cur.fetchall() # take all MIPs + #take the engineer, steps completed, steps completion + cur.execute(""" + SELECT E.ENGINEER_NAME, LP.NAME, LPS.LP_STEP_NAME,T.ISCOMPLETE FROM ENGLPSTEPCOMPLETION T + LEFT JOIN ENGINEER E ON E.ENGINEER_ID = T.ENGINEER_ID + LEFT JOIN LEARNINGPATHSTEPS LPS ON LPS.LP_STEP_ID = T.LP_STEP_ID + LEFT JOIN LEARNINGPATH LP ON LP.LEARNINGPATH_ID = LPS.LP_ID + WHERE E.ENGINEER_ID=%s + ORDER BY 2 ASC + """, (engineer[0],) ) + par = cur.fetchall() + + #take the learningpath, number of steps completed, learningpath completion + cur.execute(""" + WITH KOD AS ( + SELECT E.ENGINEER_NAME AS NAME, + LP.NAME AS LPNAME, + LPS.LP_STEP_NAME AS LPSNAME, + T.ISCOMPLETE AS RESULT + FROM ENGLPSTEPCOMPLETION T + LEFT JOIN ENGINEER E ON E.ENGINEER_ID = T.ENGINEER_ID + LEFT JOIN LEARNINGPATHSTEPS LPS ON LPS.LP_STEP_ID = T.LP_STEP_ID + LEFT JOIN LEARNINGPATH LP ON LP.LEARNINGPATH_ID = LPS.LP_ID + WHERE E.ENGINEER_ID = %s + ORDER BY 2 ASC + ) + SELECT KOD.LPNAME, + COUNT(CASE WHEN KOD.RESULT = 'False' THEN 1 END) AS FalseR, + COUNT(CASE WHEN KOD.RESULT = 'True' THEN 1 END) AS TrueR, + CASE WHEN COUNT(CASE WHEN KOD.RESULT = 'False' THEN 1 END) = 0 THEN 'LP Completed' + ELSE 'LP Not Completed' + END AS LP_STATUS + FROM KOD + GROUP BY KOD.LPNAME + ORDER BY KOD.LPNAME; + """, (engineer[0],)) + parComplete = cur.fetchall() + + finally: + conn_pool.putconn(conn) # database bağlantısını kes + + return render_template('dashboard.html', engineer=engineer, mips=mips, list_par=par, list_complete=parComplete) # dashboard.htmli yükle ve ona engineer(mevcut oturum) ve databaseden elde ettiğimiz mips listesini yükle. + +#Function for opening dashboard from login page list +@app.route('/dashboardd/', methods=['GET']) +def engdash(engineer_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM engineer WHERE engineer_id = %s', (engineer_id,)) + result = cur.fetchone() + + if result is None: + return redirect(url_for('index')) + + conn = conn_pool.getconn() + + try: + cur = conn.cursor() + cur.execute('SELECT * FROM mip') + mips = cur.fetchall() + cur.execute(""" + SELECT E.ENGINEER_NAME, LP.NAME, LPS.LP_STEP_NAME,T.ISCOMPLETE FROM ENGLPSTEPCOMPLETION T + LEFT JOIN ENGINEER E ON E.ENGINEER_ID = T.ENGINEER_ID + LEFT JOIN LEARNINGPATHSTEPS LPS ON LPS.LP_STEP_ID = T.LP_STEP_ID + LEFT JOIN LEARNINGPATH LP ON LP.LEARNINGPATH_ID = LPS.LP_ID + WHERE E.ENGINEER_ID=%s + ORDER BY 2 ASC + """, (engineer_id,) ) + par = cur.fetchall() + + cur.execute(""" + WITH KOD AS ( + SELECT E.ENGINEER_NAME AS NAME, + LP.NAME AS LPNAME, + LPS.LP_STEP_NAME AS LPSNAME, + T.ISCOMPLETE AS RESULT + FROM ENGLPSTEPCOMPLETION T + LEFT JOIN ENGINEER E ON E.ENGINEER_ID = T.ENGINEER_ID + LEFT JOIN LEARNINGPATHSTEPS LPS ON LPS.LP_STEP_ID = T.LP_STEP_ID + LEFT JOIN LEARNINGPATH LP ON LP.LEARNINGPATH_ID = LPS.LP_ID + WHERE E.ENGINEER_ID = %s + ORDER BY 2 ASC + ) + SELECT KOD.LPNAME, + COUNT(CASE WHEN KOD.RESULT = 'False' THEN 1 END) AS FalseR, + COUNT(CASE WHEN KOD.RESULT = 'True' THEN 1 END) AS TrueR, + CASE WHEN COUNT(CASE WHEN KOD.RESULT = 'False' THEN 1 END) = 0 THEN 'LP Completed' + ELSE 'LP Not Completed' + END AS LP_STATUS + FROM KOD + GROUP BY KOD.LPNAME + ORDER BY KOD.LPNAME; + """, (engineer_id,)) + parComplete = cur.fetchall() + + finally: + conn_pool.putconn(conn) + + return render_template('dashboard.html', engineer=result, mips=mips, list_par=par, list_complete=parComplete) + +#Function to open mips.html +@app.route('/mips', methods=['GET']) +def mip_list_link(): + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM mip') + mips = cur.fetchall() + return render_template('mips.html', list_mips=mips) + + +#Function to open paths.html +@app.route('/paths/', methods=['GET']) +def paths(mip_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM learningpath WHERE mip_id = %s', (mip_id,)) + result = cur.fetchall() + print(result) + conn_pool.putconn(conn) + return render_template('paths.html', list_mips=result) + +#function for pathsteps.html +@app.route('/pathsteps/', methods=['GET']) +def pathsteps(learningpath_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM learningpathsteps WHERE lp_id = %s', (learningpath_id,)) + result = cur.fetchall() + print(result) + conn_pool.putconn(conn) + return render_template('pathsteps.html', list_steps=result) + +#function to update an engineer +@app.route('/update/', methods=['POST']) +def update_engineer(engineer_id): + if request.method == 'POST': + engineer_name = request.form['engineer_name'] + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute(""" + UPDATE engineer + SET engineer_name = %s + WHERE engineer_id = %s + """, (engineer_name, engineer_id)) + + flash('Engineer Updated Successfully') + conn.commit() + return redirect(url_for('index')) + +#function to edit an engineer +@app.route('/edit/', methods = ['POST', 'GET']) +def edit(engineer_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM engineer WHERE engineer_id = {0}'.format(engineer_id)) + data = cur.fetchall() + cur.close() + print(data[0]) + return render_template('edit.html', engineer = data[0]) + +#function to edit a MIP +@app.route('/edit_mip/', methods = ['POST', 'GET']) +def edit_mip(mip_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM mip WHERE mip_id = {0}'.format(mip_id)) + data = cur.fetchall() + cur.execute('SELECT * FROM learningpath WHERE mip_id = {0}'.format(mip_id)) + path = cur.fetchall() + cur.close() + print(data[0]) + return render_template('editMIP.html', mip = data[0], learningpath=path) + +#function to add a MIP +@app.route('/add_mip/', methods = ['POST', 'GET']) +def add_mip(mip_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM mip WHERE mip_id = {0}'.format(mip_id)) + data = cur.fetchall() + cur.close() + print(data[0]) + return render_template('mipADD.html', mip = data[0]) + +#Function to update MIP +@app.route('/update_mip/', methods=['POST']) +def update_mip(mip_id): + if request.method == 'POST': + mip_name = request.form['mip_name'] + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute(""" + UPDATE mip + SET mip_name = %s + WHERE mip_id = %s + """, (mip_name, mip_id)) + + flash('MIP Updated Successfully') + conn.commit() + return redirect(url_for('dashboard')) + +#Function to save MIP +@app.route('/save_mip', methods=['POST']) +def save_mip(): + conn = conn_pool.getconn() + cur = conn.cursor() + + if request.method == 'POST': + engineer_mip_new = request.form.get('mipNameNew') #take inputted MIP name + cur.execute("INSERT INTO public.mip(mip_id, mip_name) VALUES (DEFAULT, %s)", (engineer_mip_new,)) + #inserts mip with given values taken from params new mip ... + conn.commit() + flash('Added Successfully') + return redirect(url_for('dashboard')) + +#Function to save a mip +@app.route('/save_mip_list', methods=['POST']) +def save_mip_list(): + conn = conn_pool.getconn() + cur = conn.cursor() + + if request.method == 'POST': + engineer_mip_new = request.form.get('mipNameNew') + cur.execute("INSERT INTO public.mip(mip_id, mip_name) VALUES (DEFAULT, %s)", (engineer_mip_new,)) + conn.commit() + flash('Added Succesfully') + return redirect(url_for('mip_list_link')) + +#Function to delete engineer +@app.route('/delete/', methods = ['POST','GET']) +def delete(engineer_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('DELETE FROM engineer WHERE engineer_id = {0}'.format(engineer_id)) + conn.commit() + flash('Engineer Removed Successfully') + return redirect(url_for('index')) + +#Function to delete a mip +@app.route('/delete_mip/', methods = ['POST','GET']) +def delete_mip(mip_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('DELETE FROM mip WHERE mip_id = {0}'.format(mip_id)) + conn.commit() + + return redirect(url_for('dashboard')) + +#Funtion to delete a mip +@app.route('/delete_mip_list/', methods = ['POST','GET']) +def delete_mip_list(mip_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('DELETE FROM mip WHERE mip_id = {0}'.format(mip_id)) + conn.commit() + + return redirect(url_for('mip_list_link')) + + + + +#function to edit a LP +@app.route('/edit_lp/', methods = ['POST', 'GET']) +def edit_lp(learningpath_id): + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM learningpath WHERE learningpath_id = {0}'.format(learningpath_id)) + data = cur.fetchall() + cur.close() + return render_template('editlp.html', learningpath = data[0]) + +#function to update a Learningpath +@app.route('/update_lp/', methods=['POST']) +def update_lp(learningpath_id): + if request.method == 'POST': + lp_name = request.form['name'] + + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute(""" + UPDATE learningpath + SET name = %s + WHERE learningpath_id = %s + """, (lp_name, learningpath_id)) + + flash('LP Updated Successfully') + conn.commit() + return redirect(url_for('dashboard')) + +#function to save new learningpath +@app.route('/save_lp/', methods=['POST']) +def save_lp(mip_id): + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('SELECT * FROM learningpath WHERE mip_id = {0}'.format(mip_id)) + data = cur.fetchall() + cur.execute('SELECT * FROM mip WHERE mip_id = {0}'.format(mip_id)) + mip = cur.fetchall() + + if request.method == 'POST': + lp_name_new = request.form.get('name') # take inputted engineer name + cur.execute("INSERT INTO public.learningpath(learningpath_id, mip_id, name) VALUES (DEFAULT, %s, %s)", (mip_id, lp_name_new,)) + #inserts engineer with given values taken from params engineer_name_new + conn.commit() + flash('Added Successfully') + return redirect(url_for('dashboard')) -@app.route('/hello', methods=['POST']) -def hello(): - name = request.form.get('name') +#Function to delete a learningpath +@app.route('/delete_lp/', methods = ['POST','GET']) +def delete_lp(learningpath_id): - if name: - print('Request for hello page received with name=%s' % name) - return render_template('hello.html', name = name) - else: - print('Request for hello page received with no name or blank name -- redirecting') - return redirect(url_for('index')) + conn = conn_pool.getconn() + cur = conn.cursor() + cur.execute('DELETE FROM learningpath WHERE learningpath_id = {0}'.format(learningpath_id)) + conn.commit() + return render_template('paths.html') +# MAIN FONKSİYONUMUZ (ÖNEMSİZ) OLDUĞU GİBİ BIRAKABİLİRSİNİZ if __name__ == '__main__': - app.run() + app.run() \ No newline at end of file diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 000000000..73abeeeb7 Binary files /dev/null and b/static/.DS_Store differ diff --git a/static/bootstrap/.DS_Store b/static/bootstrap/.DS_Store new file mode 100644 index 000000000..8e0be807d Binary files /dev/null and b/static/bootstrap/.DS_Store differ diff --git a/templates/dashboard.html b/templates/dashboard.html new file mode 100644 index 000000000..a71d5f0ab --- /dev/null +++ b/templates/dashboard.html @@ -0,0 +1,137 @@ + + + + + Dashboard + + + + + + +
+
+ Home + Mip List +
+
+ + + +
+
+
+ + +
+
+

Engineering Dashboard

+
+
+

Welcome, {{ engineer[1] }}!

+
+
+ +
+ edit + delete +
+ + + +
+
+

MIP List

+
+
+
    + {% for mip in mips %} +
  • + {{ mip[1] }} +
    + edit + delete + add +
    +
  • + {% endfor %} +
+
+
+ +
+
+

{{engineer[1]}}'s Learning Paths

+
+
+
    +
    + + + + + + + + + + + {% for row in list_par %} + + + + + + + {% endfor %} + +
    Engineer NameLearning Path NameLearning Path Step NameIs Complete
    {{row[0]}}{{row[1]}}{{row[2]}}{{row[3]}}
    +
    +
+
+
+ + +
+
+

{{engineer[1]}} Number of Completed Paths

+
+
+
    +
    + + + + + + + + + + + {% for row in list_complete %} + + + + + + + {% endfor %} + +
    Learning Path NameNumber of uncompleted LPNumber of completed LPPath Completion
    {{row[0]}}{{row[1]}}{{row[2]}}{{row[3]}}
    +
    +
+
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/templates/edit.html b/templates/edit.html new file mode 100644 index 000000000..0f2b6ad55 --- /dev/null +++ b/templates/edit.html @@ -0,0 +1,32 @@ +
+
+ Home + Mip List +
+
+ + +{% extends "layout.html" %} +{% block body %} +
+
+
+

Update {{ engineer[1] }}

+
+
+
+
+ +
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/editMIP.html b/templates/editMIP.html new file mode 100644 index 000000000..c5a466785 --- /dev/null +++ b/templates/editMIP.html @@ -0,0 +1,51 @@ +
+
+ Home + Mip List +
+
+ +{% extends "layout.html" %} +{% block body %} +
+
+
+

Update Mip {{ mip[0] }}

+
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+
+

Add Learningpath to MIP {{mip[0]}}

+
+
+
+
+ +
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/editlp.html b/templates/editlp.html new file mode 100644 index 000000000..8a3990d7f --- /dev/null +++ b/templates/editlp.html @@ -0,0 +1,33 @@ + +
+
+ Home + Mip List +
+
+ + + {% extends "layout.html" %} + {% block body %} +
+
+
+

Update Learningpath {{ learningpath[0] }}

+
+
+
+
+ +
+
+ +
+
+
+
+
+ {% endblock %} \ No newline at end of file diff --git a/templates/hello.html b/templates/hello.html deleted file mode 100644 index c277e7740..000000000 --- a/templates/hello.html +++ /dev/null @@ -1,21 +0,0 @@ - - - Hello Azure - Python Quickstart - - - - - -
-
- Azure Logo - -

Hello {{name}}

-

- It is nice to meet you! -

- Back home -
-
- - \ No newline at end of file diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 9cdba30cd..000000000 --- a/templates/index.html +++ /dev/null @@ -1,30 +0,0 @@ - - - Hello Azure - Python Quickstart - - - - - -
-
- Azure Logo - -

Welcome to Azure

-
-
-
- - - -
- -
-
- -
-
-
-
- - \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 000000000..2512bef12 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + +
+ {% block body %} + {% endblock %} +
+ + + + + \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 000000000..2c2668373 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,111 @@ + + + + Login + + + + + +
+
+ Home + Mip List +
+
+ + + + +
+ +
+
+

New Engineer

+
+
+
+ + +
+ +
+
+ +
+
+
+
+ +
+
+

Engineer Login

+
+ +
+
+ +
+ +
+
+ +
+
+
+ + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} + {% endwith %} + +
+ +
+
+
+

Engineer List

+
+ +
+
    + {% for engineer in list_engineers %} +
  • + + +
      + {{engineer[0]}} : + {{engineer[1]}} +
    + + +
  • + {% endfor %} +
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/templates/mipADD.html b/templates/mipADD.html new file mode 100644 index 000000000..abccf8b38 --- /dev/null +++ b/templates/mipADD.html @@ -0,0 +1,38 @@ + + + + + Dashboard + + + + + + +
+ +
+ +
+
+

Add New MIP

+
+
+
+ +
+ +
+
+ +
+
+
+ \ No newline at end of file diff --git a/templates/mips.html b/templates/mips.html new file mode 100644 index 000000000..a894b634a --- /dev/null +++ b/templates/mips.html @@ -0,0 +1,46 @@ + + + + + Dashboard + + + +
+ +
+ + +
+
+
+ +
+
+

MIP List

+
+ +
+
    + {% for mip in list_mips %} +
  • + {{ mip[1] }} + +
  • + {% endfor %} +
+
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/templates/paths.html b/templates/paths.html new file mode 100644 index 000000000..f39f18d8c --- /dev/null +++ b/templates/paths.html @@ -0,0 +1,65 @@ + + + + + Learning Paths + + + + + + +
+ +
+ + + +
+
+
+
+
+

+
+
+

Learning Paths

+

Here you can view the learning paths of the selected MIP.

+
+ + +
+
+

Path List

+
+
+
    + {% for learningpath in list_mips %} +
  • + {{ learningpath[0] }} + : + {{ learningpath[2] }} +
    + edit + delete +
    +
  • + {% endfor %} +
+
+
+
+
+
+
+ + diff --git a/templates/pathsteps.html b/templates/pathsteps.html new file mode 100644 index 000000000..3e8e4769c --- /dev/null +++ b/templates/pathsteps.html @@ -0,0 +1,57 @@ + + + + + Learning Paths + + + + + +
+
+ Home + Mip List +
+
+ + + +
+
+
+
+
+

+
+
+

Steps for Learning PATH

+

Here you can view the steps for the selected Learning Path.

+
+ + + + + + + + + + {% for row in list_steps %} + + + + + {% endfor %} + +
learningpathsteps_idname
{{row[0]}}{{row[1]}}
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/templates/update.html b/templates/update.html new file mode 100644 index 000000000..25af0b255 --- /dev/null +++ b/templates/update.html @@ -0,0 +1,61 @@ + + + + Update + + + + + +
+ +
+ + + +
+
+ +
+
+

Engineering Dashboard

+
+
+

Update, {{ engineer[1] }}!

+
+
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+
+ +
+ + + \ No newline at end of file diff --git a/test_first.py b/test_first.py new file mode 100644 index 000000000..147391a2a --- /dev/null +++ b/test_first.py @@ -0,0 +1,6 @@ +def func(a): + return a -1 + +#test +def test_testmethod(): + assert func(6) == 5 \ No newline at end of file