Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignments #18

Open
wants to merge 80 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
d5fb7af
change travis url
ScottJohnson02 Apr 6, 2020
a40aed8
fix name
ScottJohnson02 Apr 6, 2020
e99df4b
added courses table
CodeMart10 Apr 7, 2020
41e1528
Merge pull request #1 from ScottJohnson02/courses-table
ScottJohnson02 Apr 7, 2020
cc397fa
allow user to log in and hash password
ScottJohnson02 Apr 7, 2020
2c30140
add tests for auth and users now go to the /home url
ScottJohnson02 Apr 7, 2020
241b677
Merge branch 'master' into auth
ScottJohnson02 Apr 7, 2020
3f076de
Merge pull request #2 from ScottJohnson02/auth
ScottJohnson02 Apr 7, 2020
c223324
Started on tests for course creation and editing.
Apr 7, 2020
642ee98
hot fix for schema and remove print statement along with removing red…
ScottJohnson02 Apr 8, 2020
307e5e9
Merge pull request #3 from ScottJohnson02/hotfix
CodeMart10 Apr 8, 2020
caf2be1
Finished the edit course test.
Apr 8, 2020
f3522e1
Fixed tests to use the right urls, added new baseline routes in cours…
Apr 8, 2020
4132061
added function in db.py
CodeMart10 Apr 8, 2020
f8c9fcb
Merge pull request #4 from ScottJohnson02/csv-import
ejmoyer Apr 8, 2020
717df80
I made a form to update the course name and the route to redirect if the
LeeEnck Apr 8, 2020
7f404e6
Started on adding the list of courses a teacher owns, and they can on…
Apr 8, 2020
f6757d8
Finished the teacher courses page. Fixed tests to work correctly with…
Apr 9, 2020
07c0218
Completed create new course page and view. Test for creating a course…
Apr 9, 2020
5c5a33d
added sessions and student_sessions table
CodeMart10 Apr 9, 2020
6816ba3
Made a new form for edit posts
LeeEnck Apr 9, 2020
7ce22b0
students can view the sessions they are enrolled in when they go to /…
ScottJohnson02 Apr 9, 2020
ceb6752
Completed edit courses to a usable point. Will add some extra feature…
Apr 10, 2020
6e183ca
Merge branch 'master' into create-edit-courses
ejmoyer Apr 10, 2020
1ac8b91
Fixed tests to work with Travis.
Apr 10, 2020
c3bd314
Merge branch 'create-edit-courses' of github.com:ScottJohnson02/tsct-…
Apr 10, 2020
35fb618
Fixed key pair grabbed by courses to get courses.
Apr 10, 2020
cc79860
Fixed feedback
ejmoyer Apr 10, 2020
51fb00f
Merge pull request #7 from ScottJohnson02/create-edit-courses
ScottJohnson02 Apr 10, 2020
63437a3
Merge branch 'master' of github.com:ScottJohnson02/tsct-portal into r…
CodeMart10 Apr 10, 2020
1532de1
Added comments
CodeMart10 Apr 10, 2020
19a525e
added comments to schema.sql
CodeMart10 Apr 10, 2020
52d229f
teachers can create sessions for a course
CodeMart10 Apr 10, 2020
1e832b5
Changed base.html to get stylesheet from deeper. Added view and delet…
Apr 10, 2020
b0ff055
added comments
CodeMart10 Apr 15, 2020
c28305d
added tables (sessions, student_sessions, assignments)
CodeMart10 Apr 15, 2020
2249cd2
fixed bug with mock-db
CodeMart10 Apr 15, 2020
b36df36
Merge pull request #9 from ScottJohnson02/database
ScottJohnson02 Apr 15, 2020
eec6ed9
Made a assignments template, and root to assignments page
LeeEnck Apr 15, 2020
3a1736b
Bugfixed schema.sql having course numbers unique, which can cause iss…
Apr 15, 2020
e1110fc
Added tests for new features.
Apr 15, 2020
9419410
Merge branch 'master' into courses-extrafeats
ejmoyer Apr 15, 2020
60e9337
Hotfixed issues with delete tests and Travis interaction.
Apr 15, 2020
52d3ca3
Pulled current master changes and merged with this branch for a clean…
Apr 15, 2020
d9dc937
Hotfix for Travis testing issues.
Apr 15, 2020
8d20198
Merge pull request #10 from ScottJohnson02/courses-extrafeats
ScottJohnson02 Apr 15, 2020
2bbd763
Added some changes to the template so the student can actually view t…
LeeEnck Apr 16, 2020
0fbbf26
Merge branch 'master' of github.com:ScottJohnson02/tsct-portal into a…
CodeMart10 Apr 16, 2020
1b48af6
fixed merge leftover text
CodeMart10 Apr 16, 2020
ce31c6b
fixed merge conflict in init.py
LeeEnck Apr 16, 2020
6f90dd5
Merge branch 'assignments' of github.com:ScottJohnson02/tsct-portal i…
LeeEnck Apr 16, 2020
ea4af6c
students appear when creating a session and only teachers can make se…
ScottJohnson02 Apr 16, 2020
b86bccb
added logout button
CodeMart10 Apr 16, 2020
06b57a0
teacher can add students when they make a session
ScottJohnson02 Apr 16, 2020
7667ea5
add tests to session
ScottJohnson02 Apr 16, 2020
d526f30
Merge branch 'master' of github.com:ScottJohnson02/tsct-portal into r…
ScottJohnson02 Apr 16, 2020
28ac1ba
added logout and home button
CodeMart10 Apr 17, 2020
6c7a7df
added courses and assignments button
CodeMart10 Apr 17, 2020
ae00eeb
deleted sessions.py
CodeMart10 Apr 17, 2020
93c0a08
Merge pull request #13 from ScottJohnson02/nav_buttons
CodeMart10 Apr 17, 2020
af9800a
Merge branch 'assignments' of github.com:ScottJohnson02/tsct-portal i…
LeeEnck Apr 17, 2020
94b374a
quality of life improvements
ScottJohnson02 Apr 17, 2020
b3401e3
Fixed edit bug.
Apr 17, 2020
1e697c5
Completed session viewing for teacher and student. Tests updated to t…
Apr 17, 2020
b4e3ff0
Update courses.py
ejmoyer Apr 17, 2020
8095de8
Merge pull request #14 from ScottJohnson02/roster
CodeMart10 Apr 17, 2020
42d317b
Merge branch 'master' of github.com:ScottJohnson02/tsct-portal into a…
CodeMart10 Apr 21, 2020
d382d9c
styled the nav bar only changed things on the base.html
CodeMart10 Apr 21, 2020
5ccf5d3
fixed test issues
CodeMart10 Apr 21, 2020
22ac93a
Made a test for assignments.py
LeeEnck Apr 21, 2020
16425b4
Merge branch 'assignments' of github.com:ScottJohnson02/tsct-portal i…
LeeEnck Apr 21, 2020
2bf9c77
teacher can add assignments for specific student session id's
CodeMart10 Apr 21, 2020
f4daea5
fixed assignments to show for specific section
CodeMart10 Apr 22, 2020
b1861a9
tested assignments and create assignments
CodeMart10 Apr 22, 2020
e8d78c7
logic finished for teacher creating assignments and students viewing …
CodeMart10 Apr 22, 2020
01a4b27
finished assignments user stories
CodeMart10 Apr 22, 2020
8ca7a0d
Merge branch 'assignments' of github.com:ScottJohnson02/tsct-portal i…
CodeMart10 Apr 22, 2020
a8ff625
fixed merge leftover
CodeMart10 Apr 22, 2020
140539e
cleaned up assignment logic
CodeMart10 Apr 23, 2020
bd4e711
fixed name issue
CodeMart10 Apr 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions portal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def create_app(test_config=None):
from . import auth
app.register_blueprint(auth.bp)

from . import sessions
app.register_blueprint(sessions.bp)

from . import courses
app.register_blueprint(courses.bp)

Expand Down
75 changes: 51 additions & 24 deletions portal/courses.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from flask import (
Blueprint, g, render_template, redirect, url_for, session, request
Blueprint, g, render_template, redirect, url_for, session, request, flash
)

from portal.db import get_db

bp = Blueprint('courses', __name__)

#------- Course Page -----------------------------------------------------------------
# ------- Course Page -----------------------------------------------------------------
@bp.route('/courses')
def courses():
"""View for the courses"""
if session['user'][4] == 'teacher': # only if they are a teacher
# get the id of the teacher
if session['user'][4] == 'teacher': # only if they are a teacher
# get the id of the teacher
teacher = session['user'][0]
# display the courses they own with a query
cur = get_db().cursor()
Expand All @@ -20,23 +20,27 @@ def courses():
teacher_courses = cur.fetchall()

return render_template('portal/courses.html', teacher_courses=teacher_courses)
else: # if not a teacher, return to home page
else: # if not a teacher, return to home page
return render_template('portal/home.html')


#------- Create Courses -----------------------------------------------------------------
# ------- Create Courses -----------------------------------------------------------------
@bp.route('/createcourse', methods=("GET", "POST"))
def courses_create():
"""View for creating a course"""
if session['user'][4] == 'teacher': # only if they are a teacher
if session['user'][4] == 'teacher': # only if they are a teacher
if request.method == "POST":
teacher = session['user'][0]
cour_name = request.form['cour_name']
cour_num = request.form['cour_num']
cour_maj = request.form['cour_maj']
cour_cred = request.form['cour_cred']
cour_desc = request.form['cour_desc']

# checks major name length
if len(cour_maj) > 4:
error = 'course major name can only be 4 letters'
flash(error)
return render_template('portal/createcourse.html')
# make a query that inserts into courses table with this info and teacher id
cur = get_db().cursor()

Expand All @@ -48,61 +52,84 @@ def courses_create():
return redirect(url_for('courses.courses'))

return render_template('portal/createcourse.html')
else: #if they aren't a teacher return them to home page
else: # if they aren't a teacher return them to home page
return render_template('portal/home.html')


@bp.route('/<int:cour_id>/viewcourse')
def courses_view(cour_id):
"""Shows details of a course to teacher"""
if session['user'][4] == 'teacher': # if they are a teacher
if session['user'][4] == 'teacher': # if they are a teacher
teacher = session['user'][0]
cur = get_db().cursor()

cur.execute("SELECT * FROM courses WHERE teacher_id = %s AND id = %s;", (teacher, cour_id))
cur.execute(
"SELECT * FROM courses WHERE teacher_id = %s AND id = %s;", (teacher, cour_id))

course = cur.fetchone()
return render_template('portal/viewcourse.html', course=course)
else: # if not a teacher, send to home
else: # if not a teacher, send to home
return render_template('portal/home.html')


@bp.route('/deletecourse', methods=("POST",))
def courses_delete():
"""View for deleting courses"""
if session['user'][4] == 'teacher': # if the are a teacher
if session['user'][4] == 'teacher': # if the are a teacher
if request.method == 'POST':
course_to_delete = request.form['course_to_delete']
teacher = session['user'][0]
cur = get_db().cursor()

cur.execute("DELETE FROM courses WHERE teacher_id = %s AND id = %s;", (teacher, course_to_delete))
cur.execute("DELETE FROM student_sessions WHERE course_id = %s;",
(course_to_delete,))
get_db().commit()
cur.execute("DELETE FROM sessions WHERE course_id = %s;",
(course_to_delete,))
get_db().commit()
cur.execute("DELETE FROM courses WHERE teacher_id = %s AND id = %s;",
(teacher, course_to_delete))
get_db().commit()
cur.close()
return redirect(url_for('courses.courses'))
else: # if not a teacher, send to home
return render_template('portal/home.html')


#------- Edit Courses -----------------------------------------------------------------
# ------- Edit Courses -----------------------------------------------------------------
@bp.route('/<int:cour_id>/editcourse', methods=("GET", "POST"))
def courses_edit(cour_id):
"""Edits the course name/info"""
if session['user'][4] == 'teacher': # if they are a teacher
cur = get_db().cursor()
cur = get_db().cursor()
teacher = session['user'][0]
cur.execute("SELECT * FROM courses WHERE teacher_id = %s AND id = %s;",
(teacher, cour_id))
course = cur.fetchone()

if session['user'][4] == 'teacher':

if request.method == "POST":
error = None
cour_name = request.form['cour_name']
cour_num = request.form['cour_num']
cour_maj = request.form['cour_maj']
cour_cred = request.form['cour_cred']
cour_desc = request.form['cour_desc']

# Update the course
if len(cour_maj) > 4:
error = 'course major name can only be 4 letters'
flash(error)
return render_template("portal/editcourse.html")

# Update the course
cur.execute(
"""UPDATE courses SET (major, name, num, credits, description) = (%s, %s, %s, %s, %s)
WHERE id = %s;""", (cour_maj, cour_name, cour_num, cour_cred, cour_desc , cour_id)
)
"""UPDATE courses SET (major, name, num, credits, description) = (%s, %s, %s, %s, %s)
WHERE id = %s AND teacher_id = %s ;""", (cour_maj, cour_name, cour_num, cour_cred, cour_desc, cour_id, teacher)
)
get_db().commit()
cur.close()

return redirect(url_for('courses.courses'))

return render_template("portal/editcourse.html")
else: # if not a teacher, send them to home page
return render_template("portal/editcourse.html", course=course)
else: # if not a teacher, send them to home page
return render_template('portal/home.html')
35 changes: 22 additions & 13 deletions portal/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,57 @@ DROP TABLE IF EXISTS courses;
DROP TABLE IF EXISTS users;




-- Users
CREATE TABLE users (
id bigint PRIMARY KEY,
email text UNIQUE NOT NULL,
password text NOT NULL,
name text,
name varchar(100),
role varchar(7) NOT NULL CHECK (role IN ('teacher', 'student')),
major text
major varchar(4)
);

-- Courses
CREATE TABLE courses (
id bigserial PRIMARY KEY,
major text NOT NULL,
name text UNIQUE NOT NULL,
major varchar(4) NOT NULL,
name varchar(100) UNIQUE NOT NULL,
num integer NOT NULL,
description text,
description varchar(1000),
credits integer NOT NULL,
teacher_id bigint REFERENCES users (id) -- One teacher owns many courses

);

-- Sessions


-- Session
CREATE TABLE sessions (
id bigserial PRIMARY KEY,
course_id bigint REFERENCES courses (id), -- One course owns many sessions
teacher_id bigint REFERENCES users (id), -- One teacher owns many sessions
course_id bigint REFERENCES courses (id) NOT NULL, -- One course owns many sessions
teacher_id bigint REFERENCES users (id) NOT NULL, -- One teacher owns many sessions
section varchar(1) NOT NULL,
meeting_time timestamptz NOT NULL,
location varchar(200)
meeting_time time NOT NULL,
location varchar(200) NOT NULL,
PRIMARY KEY (course_id, section)
);

-- Students sessions
CREATE TABLE student_sessions (
id bigserial PRIMARY KEY,
session_id bigint REFERENCES sessions (id), -- One session owns many student sessions
course_id bigint NOT NULL,
section varchar(1) NOT NULL,
FOREIGN KEY (course_id, section) REFERENCES sessions (course_id, section), -- One session owns many student sessions
student_id bigint REFERENCES users (id) -- One User has many student sessions
);

-- Assignments
CREATE TABLE assignments (
id bigserial PRIMARY KEY,
session_id bigint REFERENCES sessions (id), -- One session owns many assignments
course_id bigint NOT NULL,
section varchar(1) NOT NULL,
FOREIGN KEY (course_id, section) REFERENCES sessions (course_id, section), -- One session owns many assignments
name varchar(50) NOT NULL,
type varchar(50) NOT NULL,
points integer NOT NULL,
Expand Down
150 changes: 150 additions & 0 deletions portal/sessions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import os
from portal.db import get_db

from flask import (
Flask, Blueprint, flash, g, redirect, render_template, request, url_for, session
)
from werkzeug.security import check_password_hash, generate_password_hash

bp = Blueprint('sessions', __name__)


@bp.route('/sessions', methods=('GET', 'POST'))
def sessions():
cur = get_db().cursor()

# grabs course id from the one clicked on
course_id = request.args.get('course_id')

# shows student sessions
if session['user'][4] == 'student':
cur.execute('SELECT * FROM sessions AS s JOIN student_sessions AS ss ON (s.course_id = ss.course_id and s.section = ss.section) WHERE ss.student_id = %s;',
(session['user'][0],))

# shows teachers session according to which course they are looking at
if session['user'][4] == 'teacher':
if(course_id == None):
return redirect(url_for('courses.courses'))
cur.execute('SELECT * FROM sessions WHERE teacher_id = %s AND course_id = %s;',
(session['user'][0], course_id))

sessions = cur.fetchall()
classes = []
sections = []
if session['user'][4] == 'student':
course_id = []
cur.close()

for sess in sessions:

cur = get_db().cursor()

# grabbing name of the course by session's fk
cur.execute('SELECT name FROM courses WHERE id = %s;',
(sess[0],))
classname = cur.fetchall()
if session['user'][4] == 'student':
course_id.append(sess[0])
# pulling string out of nested list
classes.append(classname[0][0])
sections.append(sess[2])
if session['user'][4] == 'teacher':
return render_template('portal/sessions.html', sessions=classes, sections=sections, course_id=course_id)

if session['user'][4] == 'student':
return render_template('portal/sessions.html', sessions=classes, sections=sections, course_id=course_id)



@bp.route('/createsession', methods=("GET", "POST"))
def session_create():
"""View for creating a session"""
cur = get_db().cursor()
course_id = request.args.get('course_id')
# grabbing name of the course by session's fk

# ---join for grabbing enrolled_students---
# cur.execute('SELECT * FROM student_sessions JOIN users ON student_id =users.id WHERE session_id = %s;',
# (1,))
# enrolled_students = cur.fetchall()
cur.execute('SELECT * FROM users WHERE role = %s;', ('student',))
all_students = cur.fetchall()

if request.method == "POST":

section = request.form['section']
meeting_time = request.form['meeting']
location = request.form['location']
teacher_id = session['user'][0]
students = request.form.getlist('students')

cur = get_db().cursor()
cur.execute("""INSERT INTO sessions (course_id,section, meeting_time, location, teacher_id)
VALUES (%s, %s, %s, %s, %s);""", (course_id, section, meeting_time, location, teacher_id))
get_db().commit()

for student in students:
# find student in user db then grab it by name
cur = get_db().cursor()
cur.execute('SELECT * FROM users WHERE name = %s;', (student,))
student_info = cur.fetchone()
student_id = student_info[0]
# create a new session for each student
cur.execute("""INSERT INTO student_sessions (course_id, section, student_id)
VALUES (%s, %s, %s);""", (course_id, section, student_id))
get_db().commit()
cur.close()

return redirect(url_for('courses.courses'))

return render_template('portal/createsession.html', all_students=all_students)


@bp.route('/<int:session_id>/editsession', methods=("GET", "POST"))
def session_edit(session_id):
"""Edits the course name/info"""
cur = get_db().cursor()
teacher = session['user'][0]
cur.execute("SELECT * FROM sessions WHERE teacher_id = %s AND id = %s;",
(teacher, session_id))
selected_session = cur.fetchone()

if session['user'][4] == 'teacher':

if request.method == "POST":
section = request.form['section']
meeting_time = request.form['meeting']
location = request.form['location']
teacher_id = session['user'][0]
students = request.form.getlist('students')

cur.execute("DELETE FROM student_sessions WHERE session_id = %s;",
(session_id,))
# Update the course

cur.execute(
"""UPDATE courses SET (major, name, num, credits, description) = (%s, %s, %s, %s, %s)
WHERE id = %s AND teacher_id = %s ;""", (cour_maj, cour_name, cour_num, cour_cred, cour_desc, cour_id, teacher)
)
get_db().commit()
cur.close()

return redirect(url_for('courses.courses'))

return render_template("portal/editcourse.html", course=course)
else: # if not a teacher, send them to home page
return render_template('portal/home.html')

@bp.route('/viewsession', methods=('GET', 'POST'))
def session_view():
"""View for seeing more session details."""
cur = get_db().cursor()
course_id = request.args.get("course_id")
section = request.args.get("section")
classname = request.args.get("class")

cur.execute("SELECT * FROM sessions WHERE course_id = %s AND section = %s;", (course_id, section))
session_info = cur.fetchone()
print(session_info)

return render_template('portal/viewsession.html', course_id=course_id, section=section, classname=classname, session_info=session_info)
Loading