Skip to content

Commit

Permalink
teacher view for course
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissdelaney committed Apr 2, 2024
1 parent 70fc80e commit 7c3f52e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
26 changes: 24 additions & 2 deletions app/spreadsheet_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def get_sheet(self, sheet_name):
# COURSES FUNCTIONS #
#####################

def get_student_courses(self, email:str) -> list:
def get_courses(self, email:str) -> list:
self.set_active_document(GOOGLE_SHEETS_MASTER_DOCUMENT_ID)
students_sheet = self.get_sheet("roster")
all_student_course_ids = students_sheet.get_all_records()
student_course_ids = [course["COURSE_ID"] for course in all_student_course_ids if course["EMAIL"] == email and course["USER_TYPE"] == "student"]
student_course_ids = [course["COURSE_ID"] for course in all_student_course_ids if course["EMAIL"] == email]

courses_sheet = self.get_sheet("courses")
all_courses = courses_sheet.get_all_records()
Expand Down Expand Up @@ -123,6 +123,28 @@ def get_course_assignments(self, student_email:str, course_id:str) -> list:
a['GRADE'] = '0.00%'

return assignments

def get_course_roster(self, course_id:str):
if self.doc.id == GOOGLE_SHEETS_MASTER_DOCUMENT_ID:
courses_sheet = self.get_sheet("courses")
courses_records = courses_sheet.get_all_records()

course_document_id_list = [c["SHEETS_DOCUMENT_ID"] for c in courses_records if c["COURSE_ID"] == int(course_id)]

if len(course_document_id_list) == 0:
raise Exception("course not found...")
#TODO: handle within the route
if len(course_document_id_list) > 1:
raise Exception("course duplicate found...error")
#TODO: handle within the route

self.set_active_document(course_document_id_list[0])

#get student_grade
gradebook_sheet = self.get_sheet("GRADEBOOK")
all_grades = gradebook_sheet.get_all_records()

return all_grades


@staticmethod
Expand Down
6 changes: 4 additions & 2 deletions web_app/routes/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def google_oauth_callback():
#> 'iat': __________,
#> 'exp': __________
#> }
print("USER INFO:", user_info["email"], user_info["name"], user_info.get("locale"))

# add user info to the session
session["current_user"] = user_info
Expand All @@ -67,7 +66,10 @@ def google_oauth_callback():
# "locale": user_info["locale"],
#})

session["user_type"] = get_user_type(user_info["email"])
session['current_user']["user_type"] = get_user_type(user_info["email"])

print(f"{session['current_user']['email']} is a {session['current_user']['user_type']}")


else:
print("NO USER INFO")
Expand Down
10 changes: 9 additions & 1 deletion web_app/routes/courses_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ def course(course_id):
current_user = session.get("current_user")
email = current_user["email"]
#TODO: change hard coded email to "email" fetched from session
assignments_list = ss.get_course_assignments("[email protected]", course_id)
email = "[email protected]"
##################################

if current_user.get('user_type') == "student":
assignments_list = ss.get_course_assignments(email, course_id)
return render_template("assignments.html", assignments=assignments_list, course_id=course_id)
elif current_user.get('user_type') == "teacher":
roster_data = ss.get_course_roster(course_id)
return render_template("course_roster.html", roster_data=roster_data)
return render_template("assignments.html", assignments=assignments_list, course_id=course_id)


Expand Down
5 changes: 4 additions & 1 deletion web_app/routes/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ def courses():
print("USER COURSES...")
current_user = session.get("current_user")
ss = current_app.config["SPREADSHEET_SERVICE"]

email = current_user["email"]
email = "[email protected]"

courses = ss.get_student_courses(current_user["email"])
courses = ss.get_courses(email)

return render_template("courses.html", courses=courses)

Expand Down
6 changes: 4 additions & 2 deletions web_app/routes/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def wrapped_view(**kwargs):
def student_route(view):
@functools.wraps(view)
def wrapped_view(**kwargs):
if session.get("user_type") == "student": #this security is so weak haha
current_user = session.get("current_user")
if current_user.get("user_type") == "student": #this security is so weak haha
#print("CURRENT USER:", session["current_user"])
return view(**kwargs)
else:
Expand All @@ -39,7 +40,8 @@ def wrapped_view(**kwargs):
def teacher_route(view):
@functools.wraps(view)
def wrapped_view(**kwargs):
if session.get("user_type") == "teacher": #this security is so weak haha
current_user = session.get("current_user")
if current_user.get("user_type") == "teacher": #this security is so weak haha
#print("CURRENT USER:", session["current_user"])
return view(**kwargs)
else:
Expand Down
47 changes: 47 additions & 0 deletions web_app/templates/course_roster.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends "bootstrap_5_layout.html" %}
{% set active_page = "assignments" %}

{% block content %}

<h1>Course Roster</h1>

<table class="table table-hover text-center">
<thead>
<tr>
<th scope="col">Last</th>
<th scope="col">First</th>
<th scope="col">Email</th>
<th scope="col">Current Grade</th>
</tr>
</thead>
<tbody>
{% for d in roster_data %}
<tr class="clickable-row" data-href="/courses/{{ course_id }}/student/{{ d.Email }}">
<td>
{{ d.Last }}
</td>
<td>
{{ d.First }}
</td>
<td>
{{ d.Email }}
</td>
<td>
{{ d.TOTAL }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

<script>
document.addEventListener("DOMContentLoaded", function(){
document.querySelectorAll('.clickable-row').forEach(row => {
row.addEventListener('click', function() {
window.location.href = this.dataset.href;
});
});
});
</script>

{% endblock %}

0 comments on commit 7c3f52e

Please sign in to comment.