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 13 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.
4 changes: 2 additions & 2 deletions portal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_app(test_config=None):
# -------------
# Default configuration, can be overwritten by specific environment
app.config.from_mapping(
SECRET_KEY='dev',
SECRET_KEY= b'y3?g?f??|???e',
DB_URL="postgresql://portal_user@localhost/portal",
DB_SSLMODE="allow",
)
Expand Down Expand Up @@ -55,6 +55,6 @@ def create_app(test_config=None):

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

# Return application object to be used by a WSGI server, like gunicorn
return app
3 changes: 2 additions & 1 deletion portal/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

bp = Blueprint('auth', __name__)


#------- Index -----------------------------------------------------------------
@bp.route('/', methods=('GET', 'POST'))
def index():
if request.method == 'POST':
Expand All @@ -32,6 +32,7 @@ def index():
return render_template('index.html')


#------- Home -----------------------------------------------------------------
@bp.route('/home', methods=('GET', 'POST'))
def home():
return render_template('portal/home.html')
109 changes: 75 additions & 34 deletions portal/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,103 @@

bp = Blueprint('courses', __name__)

#------- Course Page -----------------------------------------------------------------
@bp.route('/courses')
def courses():
"""View for the courses"""
if session['user'][4] == '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()

cur.execute("SELECT * FROM courses WHERE teacher_id = %s;", (teacher,))
teacher_courses = cur.fetchall()
else:

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

return render_template('portal/courses.html', teacher_courses=teacher_courses)

#------- Create Courses -----------------------------------------------------------------
@bp.route('/createcourse', methods=("GET", "POST"))
def courses_create():
"""View for creating a course"""
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']
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']

# make a query that inserts into courses table with this info and teacher id
cur = get_db().cursor()

cur.execute("""INSERT INTO courses (major, name, num, description, credits, teacher_id)
VALUES (%s, %s, %s, %s, %s, %s);""", (cour_maj, cour_name, cour_num, cour_desc, cour_cred, teacher))
get_db().commit()
cur.close()

# make a query that inserts into courses table with this info and teacher id
return redirect(url_for('courses.courses'))

return render_template('portal/createcourse.html')
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
teacher = session['user'][0]
cur = get_db().cursor()

cur.execute("""INSERT INTO courses (major, name, num, credits, teacher_id)
VALUES (%s, %s, %s, %s, %s);""", (cour_maj, cour_name, cour_num, cour_cred, teacher))
get_db().commit()
cur.close()
cur.execute("SELECT * FROM courses WHERE teacher_id = %s AND id = %s;", (teacher, cour_id))

return redirect(url_for('courses.courses'))
course = cur.fetchone()
return render_template('portal/viewcourse.html', course=course)
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 request.method == 'POST':
course_to_delete = request.form['course_to_delete']
teacher = session['user'][0]
cur = get_db().cursor()

return render_template('portal/createcourse.html')
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'))


#------- Edit Courses -----------------------------------------------------------------
@bp.route('/<int:cour_id>/editcourse', methods=("GET", "POST"))
def courses_edit(cour_id):
"""Edits the course name/info"""
cur = get_db().cursor()
if request.method == "POST":
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 task
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)
)
get_db().commit()
cur.close()

return redirect(url_for('courses.courses'))
return render_template("portal/editcourse.html")
if session['user'][4] == 'teacher': # if they are a teacher
cur = get_db().cursor()
if request.method == "POST":
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
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)
)
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/home.html')
25 changes: 16 additions & 9 deletions portal/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask.cli import with_appcontext
from werkzeug.security import generate_password_hash


#------- Get Database -----------------------------------------------------------------
def get_db():
"""Get a PostgreSQL database connection object."""

Expand All @@ -30,6 +30,7 @@ def get_db():

return g.db

#------- Close Database -----------------------------------------------------------------
def close_db(e=None):
"""Close the current PostgreSQL connection"""

Expand All @@ -41,6 +42,7 @@ def close_db(e=None):
db.close()


#------- Initialize Database -----------------------------------------------------------------
def init_db():
"""Clear any existing data and create all tables."""

Expand All @@ -54,14 +56,7 @@ def init_db():
cur.execute(f.read())


@click.command("init-db")
@with_appcontext
def init_db_command():
"""CLI command to clear any existing data and create all tables."""
init_db()
click.echo("Initialized the database.")


#------- Mock Database -----------------------------------------------------------------
def mock_db():
"""Seed the database with mock data."""

Expand All @@ -72,6 +67,8 @@ def mock_db():
with con.cursor() as cur:
cur.execute(f.read())


#------- Import CSV -----------------------------------------------------------------
def import_csv():
""" import csv """
file = os.path.join(os.path.dirname(__file__), os.pardir, "portal_users.csv")
Expand All @@ -88,6 +85,16 @@ def import_csv():

sql.close()


#------- Click Commands -----------------------------------------------------------------
@click.command("init-db")
@with_appcontext
def init_db_command():
"""CLI command to clear any existing data and create all tables."""
init_db()
click.echo("Initialized the database.")


@click.command("import-csv")
@with_appcontext
def import_csv_command():
Expand Down
23 changes: 20 additions & 3 deletions portal/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-- command in your terminal.

-- Drop existing tables
DROP TABLE IF EXISTS assignments;
DROP TABLE IF EXISTS student_sessions;
DROP TABLE IF EXISTS sessions;
DROP TABLE IF EXISTS courses;
Expand All @@ -15,7 +16,7 @@ DROP TABLE IF EXISTS users;

-- Users
CREATE TABLE users (
id bigserial PRIMARY KEY,
id bigint PRIMARY KEY,
email text UNIQUE NOT NULL,
password text NOT NULL,
name varchar(100),
Expand All @@ -28,12 +29,15 @@ CREATE TABLE courses (
id bigserial PRIMARY KEY,
major varchar(4) NOT NULL,
name varchar(100) UNIQUE NOT NULL,
num integer UNIQUE NOT NULL,
num integer NOT NULL,
description varchar(1000),
credits integer NOT NULL,
teacher_id bigint REFERENCES users (id) -- One teacher owns many courses

);



-- Session
CREATE TABLE sessions (
course_id bigint REFERENCES courses (id) NOT NULL, -- One course owns many sessions
Expand All @@ -51,4 +55,17 @@ CREATE TABLE student_sessions (
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,
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,
due_date date NOT NULL,
student_sessions_id bigint REFERENCES student_sessions (id) -- One student session owns many Assignments
);
11 changes: 4 additions & 7 deletions portal/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def sessions():
cur.close()

for sess in sessions:
course_id = sess[1] # sess[1] = course id from session table

cur = get_db().cursor()
# grabbing name of the course by session's fk
cur.execute('SELECT name FROM courses WHERE id = %s;',
(sess[1],))
(sess[0],))
classname = cur.fetchall()
# pulling string out of nested list
classes.append(classname[0][0])
Expand All @@ -48,8 +48,8 @@ def sessions():
@bp.route('/createsession', methods=("GET", "POST"))
def session_create():
"""View for creating a session"""
course_id = request.args.get('course_id')
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---
Expand All @@ -60,17 +60,14 @@ def session_create():
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')
print(students)
# TODO: take students and put them into student session and match with the course id and section

# make a query that inserts into courses table with this info and teacher id
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()
Expand Down
Loading