Skip to content

Commit

Permalink
Merge pull request #38 from GatorEducator/quickfix/release-changes
Browse files Browse the repository at this point in the history
Full release
  • Loading branch information
Michionlion authored May 2, 2019
2 parents 2e0b348 + 2ca2f1f commit de56b08
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 115 deletions.
19 changes: 15 additions & 4 deletions application/db_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,20 @@ def insert_db(query, args=()):
db.commit()


#################
# STUDENT FUNCS #
#################
def get_class_name(class_id):
"""Get name of class"""
class_name = query_db(
"SELECT name FROM classes WHERE class_id=?;", [class_id], one=True
)
return str(class_name[0]) if class_name else None


def get_quiz_name(quiz_id):
"""Get name of quiz"""
quiz_name = query_db(
"SELECT name FROM quizzes WHERE quiz_id=?;", [quiz_id], one=True
)
return str(quiz_name[0]) if quiz_name else None


def validate_student(func):
Expand Down Expand Up @@ -188,7 +199,7 @@ def get_student_classes():
return classes


def get_student_grade(class_id):
def get_student_grades(class_id):
"""Gets all the grades given to the student"""
grades = []
quiz_grade = query_db(
Expand Down
63 changes: 26 additions & 37 deletions application/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,44 @@ def student_home():
)


@app.route("/students/classes/")
@db.validate_student
def student_classes_home():
"""Student classes page"""
return flask.render_template(
"/students/classes.html", classes=db.get_student_classes()
)


@app.route("/students/classes/join/", methods=["POST"])
@app.route("/students/classes/join/", methods=["GET", "POST"])
@db.validate_student
def student_class_join():
"""If student joins a class"""
db.insert_db(
"INSERT INTO roster (person_id, class_id) VALUES (?, ?);",
[flask.session["id"], flask.request.form["id"]],
)
flask.flash(f"You joined the class with an id of {flask.request.form['id']}")
return flask.redirect("/students/classes")
if flask.request.method == "GET":
return flask.render_template("/students/join.html")

class_id = flask.request.form["id"]
class_name = db.get_class_name(class_id)
if class_name:
db.insert_db(
"INSERT INTO roster (person_id, class_id) VALUES (?, ?);",
[flask.session["id"], class_id],
)
flask.flash(f"You joined {class_name}")
return flask.redirect(f"/students/classes/{class_id}/")
flask.flash(f"No class exists with id {class_id}!")
return flask.redirect(f"/students/")


@app.route("/students/classes/<class_id>/")
@db.validate_student
def student_class_page(class_id):
"""Show classes"""
class_name = db.query_db(
"SELECT name FROM classes WHERE class_id=?;", [class_id], one=True
)
return flask.render_template(
"/students/class_page.html",
class_id=class_id,
class_name=str(class_name[0]),
class_name=db.get_class_name(class_id),
quizzes=db.get_class_quizzes(class_id),
grades=db.get_student_grade(class_id),
grades=db.get_student_grades(class_id),
)


@app.route("/students/classes/<class_id>/quizzes/<quiz_id>/")
@db.validate_student
def student_quiz_page(class_id, quiz_id):
"""Allows students to view/take quizzes"""
quiz_name = str(
db.query_db(
"SELECT name FROM quizzes WHERE quiz_id=? AND class_id=?;",
[quiz_id, class_id],
)[0][0]
)
quiz_name = db.get_quiz_name(quiz_id)
result = db.query_db(
"SELECT grade from quiz_grades WHERE quiz_id=? AND student_id=?;",
[quiz_id, flask.session["id"]],
Expand All @@ -81,7 +72,7 @@ def student_quiz_page(class_id, quiz_id):
question_info["type"] = question[1]
question_info["text"] = question[2]
# if this is a multiple-choice question
if question[0] == 1:
if question[1] == 1:
question_info["answers"] = {}
question_info["answers"]["a"] = question[3]
question_info["answers"]["b"] = question[4]
Expand All @@ -94,10 +85,10 @@ def student_quiz_page(class_id, quiz_id):
quiz_name=quiz_name,
quiz_id=quiz_id,
class_id=class_id,
class_name=db.get_class_name(class_id),
)

flask.flash(f"You receieved {result[0]} on this quiz.")
return flask.render_template("/students/quiz_page.html", quiz_name=quiz_name)
return flask.redirect(f"/students/classes/{class_id}/quizzes/{quiz_id}/grade/")


@app.route(
Expand All @@ -108,20 +99,18 @@ def student_grade_quiz(class_id, quiz_id):
"""Show or calculate a student's grade on a quiz"""
# display grades
if flask.request.method == "GET":
quiz_name = str(
db.query_db(
"SELECT name FROM quizzes WHERE quiz_id=? AND class_id=?;",
[quiz_id, class_id],
)[0][0]
)
result = db.query_db(
"SELECT grade from quiz_grades WHERE quiz_id=? AND student_id=?;",
[quiz_id, flask.session["id"]],
one=True,
)

return flask.render_template(
"/students/quiz_grade.html", quiz_name=quiz_name, grade=result[0]
"/students/quiz_grade.html",
class_id=class_id,
class_name=db.get_class_name(class_id),
quiz_name=db.get_quiz_name(quiz_id),
grade=result[0],
)

# process quiz form from POST request
Expand Down
3 changes: 1 addition & 2 deletions application/templates/students/base_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
</style>
</head>
<body>
<!-- add simple list-style navbar -->
<!-- simple list-style navbar -->
<header>
<div class="navbar">
<ul>
<li> <a href="/students/">Dashboard</a></li>
<li> <a href="/students/classes">Classes</a></li>
<li style="float:right;"> <a href="/logout/">Logout</a></li>
</ul>
</div>
Expand Down
43 changes: 0 additions & 43 deletions application/templates/students/classes.html

This file was deleted.

13 changes: 12 additions & 1 deletion application/templates/students/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
list-style-type: none;
margin: 0;
}
div.button {
margin: 2px;
}
.inline {
display: inline-block;
}
</style>
<div class="container">
<div class="row">
Expand All @@ -17,7 +23,12 @@ <h1>Dashboard Home</h1>
</div>
<div class="row">
<div class="span4">
<h2>Your Classes</h2>
<h2 class="inline">Classes</h2>
<div class="button inline">
<form action="/students/classes/join/">
<input type="submit" value="+" />
</form>
</div>
<ul>
{% for class in classes %}
<li><a href="/students/classes/{{class.id}}/">{{class.name}}</a></li>
Expand Down
32 changes: 32 additions & 0 deletions application/templates/students/join.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--Displays form for student to join a class-->
{% extends "/students/base_template.html" %}
{% block title %}Your Classes{% endblock %}
{% block body %}
<style>
ul {
list-style-type: none;
margin: 0;
}
a span {
font-size: 12px;
}
</style>
<div class="container">
<div class="row">
<div class="span12">
<h1>Join a Class</h1>
</div>
</div>
<div class="row">
<div class="span4">
<form method="POST" action="/students/classes/join/">
<fieldset>
<label for="id">Class ID</label>
<input required type="text" name="id"/>
<input type="submit" class="btn btn-primary">
</fieldset>
</form>
</div>
</div>
</div>
{% endblock %}
24 changes: 24 additions & 0 deletions application/templates/students/quiz_grade.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--Displays the grade for a given quiz-->
{% extends "/students/base_template.html" %}
{% block title %}{{class_name}}: {{quiz_name}}{% endblock %}
{% block body %}
<style>
ul {
list-style-type: none;
margin: 0;
}
</style>
<div class="container">
<div class="row">
<div class="span12">
<h1>{{class_name}}: {{quiz_name}}</h1>
</div>
</div>
<div class="row">
<div class="span8">
<h2>Grade Received</h2>
{{grade}}
</div>
</div>
</div>
{% endblock %}
9 changes: 1 addition & 8 deletions application/templates/teachers/base_template.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<!--Includes links like teacher dashboard and message flashing-->
{% set navigation_items = [
('/teachers/classes/', 'classes', 'Classes'),
('/teachers/quiz_page/', 'quiz_page', 'Quizzes'),
('/logout/', 'logout', 'Logout'),
] -%}

{% set active_page = active_page -%}

<!doctype html>
<html>
Expand All @@ -30,10 +23,10 @@
</head>
<body>
<!-- simple list-style navbar -->
<header>
<div class="navbar">
<ul>
<li> <a href="/teachers/">Dashboard</a></li>
<li> <a href="/teachers/classes/create">Create a Class</a></li>
<li style="float:right;"> <a href="/logout/">Logout</a></li>
</ul>
</div>
Expand Down
17 changes: 8 additions & 9 deletions application/templates/teachers/classes/class_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
div.button {
margin: 2px;
}
div.inline {
.inline {
display: inline-block;
}
</style>
Expand All @@ -22,14 +22,13 @@ <h1>{{class_name}}</h1>
</div>
<div class="row">
<div class="span6">
<h2>
Quizzes
<div class="button inline">
<form action="/teachers/classes/{{class_id}}/quizzes/create">
<input type="submit" value="+" />
</form>
</div>
</h2>
<h2 class="inline">Quizzes</h2>
<div class="button inline">
<form action="/teachers/classes/{{class_id}}/quizzes/create">
<input type="submit" value="+" />
</form>
</div>

<ul>
{% for quiz in quizzes %}
<li>
Expand Down
17 changes: 8 additions & 9 deletions application/templates/teachers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
div.button {
margin: 2px;
}
div.inline {
.inline {
display: inline-block;
}
</style>
Expand All @@ -22,14 +22,13 @@ <h1>Dashboard Home</h1>
</div>
<div class="row">
<div class="span12">
<h2>
Classes
<div class="button inline">
<form action="/teachers/classes/create/">
<input type="submit" value="+" />
</form>
</div>
</h2>
<h2 class="inline">Classes</h2>
<div class="button inline">
<form action="/teachers/classes/create/">
<input type="submit" value="+" />
</form>
</div>

<ul>
{% for class in classes %}
<li><a href="/teachers/classes/{{class.id}}/">{{class.name}}</a></li>
Expand Down
Loading

0 comments on commit de56b08

Please sign in to comment.