-
Notifications
You must be signed in to change notification settings - Fork 1
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
Staff #15
Merged
Staff #15
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
18b5e40
not sure how to add 'salesforce' to test_staff.StaffViewsTest.databases
5fc35e7
adding assertTemplateUsed
ffe4975
more coverage
12c11b2
finishing testing
bc21911
update django requirement
e776095
round of testing complete
b88607d
fixed templates
4580c2f
social auth default entry problem solved
ac2f098
modifying classrooms complete
c7f76ec
db setup for attendance
51cafb9
taking attendance complete
e1a9793
reformat-taking attendance done
00abd7d
.gitignore updated
74357a0
unneccessary migrations removed
a8dbda5
addedanddeleted
97b4db5
changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,7 @@ ENV/ | |
env.bak/ | ||
venv.bak/ | ||
db/ | ||
*.idea | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AttendanceConfig(AppConfig): | ||
name = "attendance" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{% extends "home/home.html" %} | ||
|
||
{% block content %} | ||
|
||
<style> | ||
table { | ||
font-family: arial, sans-serif; | ||
border-collapse: collapse; | ||
width: 75%; | ||
} | ||
|
||
td, th { | ||
border: 1px solid #dddddd; | ||
text-align: left; | ||
padding: 8px; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: cadetblue; | ||
} | ||
|
||
.button { | ||
font-size: 10px; | ||
font-family: "American Typewriter"; | ||
border-radius: 14px; | ||
background-color: white; | ||
color: #4CAF50; | ||
border: 2px solid #000080; | ||
} | ||
.buttonSub { | ||
font-size: 14px; | ||
font-family: "American Typewriter"; | ||
border-radius: 18px; | ||
background-color: white; | ||
color: #4CAF50; | ||
border: 2px solid #000080; | ||
} | ||
</style> | ||
|
||
<div class="sidenav"> | ||
<li><a href="{% url 'home-home' %}">Home</a></li> | ||
</div> | ||
|
||
<div class="main-container"> | ||
{% if course %} | ||
<h1 style="padding-bottom: 30px"> Attendance for {{ course }} </h1> | ||
<table> | ||
<tr> | ||
<th>Date</th> | ||
<th>Daily Attendance</th> | ||
<th>Take Attendance</th> | ||
</tr> | ||
{% for date in dates %} | ||
<tr> | ||
<td>{{ date }}</td> | ||
<td>{{ daily_attendance|get_item:date }}%</td> | ||
<td> | ||
<form method="post"> | ||
{% csrf_token %} | ||
<input type="hidden" name="date" value="{{ date }}" /> | ||
<input type="hidden" name="course_id" value={{ course_id }} /> | ||
<input type="hidden" name="date_id" value={{ id }} /> | ||
<button class="button" type="submit">Take Attendance</button> | ||
</form> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% elif attendance_objects %} | ||
<h1 style="padding-bottom: 30px"> {{ course_name }} </h1> | ||
<form method="POST" style="width: 80%"> | ||
{% csrf_token %} | ||
<table> | ||
<tr> | ||
<th>Date</th> | ||
<th>Student</th> | ||
<th>Status</th> | ||
<th>Current Status</th> | ||
</tr> | ||
{% for attendance_object in attendance_objects %} | ||
<tr> | ||
<td>{{ attendance_object.date }}</td> | ||
<td>{{ attendance_object.student.first_name }} {{ attendance_object.student.last_name }}</td> | ||
<td> | ||
<select name="{{ attendance_object.student.first_name }} {{ attendance_object.student.last_name }}"> | ||
<option value="{{ attendance_object.presence }}">-----------</option> | ||
<option value="Present">Present</option> | ||
<option value="Absent">Absent</option> | ||
<option value="Late">Late</option> | ||
<option value="Excused">Excused</option> | ||
</select> | ||
</td> | ||
<td> | ||
{{ attendance_object.presence }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
<input type="hidden" name="attendance_taken" value="true" /> | ||
<input type="hidden" name="date" value="{{ attendance_objects.first.date }}" /> | ||
<input type="hidden" name="course_id" value="{{ course_id }}" /> | ||
<div style="padding-top: 20px"> | ||
<button class="buttonSub" type="submit"> Submit </button> | ||
</div> | ||
</form> | ||
{% else %} | ||
<h1 style="padding-bottom: 30px"> Attendance Home </h1> | ||
<table> | ||
<tr> | ||
<th>Course</th> | ||
<th>Teacher</th> | ||
<th>Overall Attendance</th> | ||
<th>View Attendance</th> | ||
</tr> | ||
{% for classroom in classrooms %} | ||
<tr> | ||
<td>{{ classroom.course }}</td> | ||
<td>{{ classroom.teacher }}</td> | ||
<td>{{ attendance_averages|get_item:classroom.course }}%</td> | ||
<td> | ||
<form method="GET"> | ||
<button class="button" type="submit" name="course_id" value="{{ classroom.id }}">View Class Attendance</button> | ||
</form> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endif %} | ||
</div> | ||
|
||
{% endblock content %} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
urlpatterns = [path("", views.attendance, name="attendance")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from django.http import HttpResponse | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render, redirect | ||
from home.models.models import Classroom, Attendance | ||
from home.models.salesforce import ClassOffering | ||
from staff.staff_views_helper import class_offering_meeting_dates | ||
from datetime import datetime | ||
from django.template.defaulttags import register | ||
|
||
|
||
@login_required | ||
def attendance(request): | ||
if request.method == "POST": | ||
if request.POST.get("attendance_taken") is not None: | ||
store_attendance_data(request) | ||
attendance_averages = compile_attendance_averages_for_all_courses() | ||
context = { | ||
"classrooms": Classroom.objects.all(), | ||
"attendance_averages": attendance_averages, | ||
} | ||
return render(request, "attendance.html", context) | ||
else: | ||
context = take_attendance_context( | ||
request.POST.get("course_id"), | ||
datetime.strptime(request.POST.get("date"), "%B %d, %Y").date(), | ||
) | ||
return render(request, "attendance.html", context) | ||
if request.GET.get("course_id") is not None: | ||
context = get_classroom_attendance(request.GET.get("course_id")) | ||
context.update( | ||
{ | ||
"attendance_statistic": get_course_attendance_statistic( | ||
request.GET.get("course_id") | ||
) | ||
} | ||
) | ||
else: | ||
attendance_averages = compile_attendance_averages_for_all_courses() | ||
context = { | ||
"classrooms": Classroom.objects.all(), | ||
"attendance_averages": attendance_averages, | ||
} | ||
return render(request, "attendance.html", context) | ||
|
||
|
||
def get_classroom_attendance(course_id): | ||
dates = get_classroom_meeting_dates(course_id) | ||
classroom_attendance = Attendance.objects.filter(classroom_id=course_id) | ||
course = Classroom.objects.get(id=course_id).course | ||
daily_attendance = compile_daily_attendance_for_course(course_id) | ||
return { | ||
"classroom_attendance": classroom_attendance, | ||
"dates": dates, | ||
"course": course, | ||
"course_id": course_id, | ||
"daily_attendance": daily_attendance, | ||
} | ||
|
||
|
||
def take_attendance_context(course_id, date): | ||
course = Classroom.objects.get(id=course_id).course | ||
attendance_objects = Attendance.objects.filter(classroom_id=course_id, date=date) | ||
return { | ||
"course_name": course, | ||
"course_id": course_id, | ||
"attendance_objects": attendance_objects, | ||
} | ||
|
||
|
||
def store_attendance_data(request): | ||
date = datetime.strptime(request.POST.get("date"), "%B %d, %Y").date() | ||
course_id = request.POST.get("course_id") | ||
attendance_objects = Attendance.objects.filter(classroom_id=course_id, date=date) | ||
for attendance_object in attendance_objects: | ||
attendance_object.presence = request.POST.get(str(attendance_object.student)) | ||
attendance_object.save() | ||
|
||
|
||
def get_course_attendance_statistic(course_id): | ||
class_attendance = Attendance.objects.filter(classroom_id=course_id) | ||
class_attendance = [ | ||
daily_attendance | ||
for daily_attendance in class_attendance | ||
if daily_attendance.date < datetime.today().date() | ||
tylerIams marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
average = get_average_attendance_from_list(class_attendance) | ||
return round(average * 100, 2) | ||
|
||
|
||
def compile_attendance_averages_for_all_courses(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance follow-up in #16 |
||
attendance_averages = {} | ||
for classroom in Classroom.objects.all(): | ||
stat = get_course_attendance_statistic(classroom.id) | ||
attendance_averages.update({classroom.course: stat}) | ||
return attendance_averages | ||
|
||
|
||
def compile_daily_attendance_for_course(course_id): | ||
daily_attendance_record = {} | ||
dates = get_classroom_meeting_dates(course_id) | ||
for date in dates: | ||
daily_attendance = Attendance.objects.filter(classroom_id=course_id, date=date) | ||
average = round(get_average_attendance_from_list(daily_attendance) * 100, 2) | ||
daily_attendance_record.update({date: average}) | ||
return daily_attendance_record | ||
|
||
|
||
def get_average_attendance_from_list(list): | ||
return sum( | ||
attendance_object.presence == "Present" or attendance_object.presence == "Late" | ||
for attendance_object in list | ||
) / len(list) | ||
|
||
|
||
def get_classroom_meeting_dates(course_id): | ||
return class_offering_meeting_dates( | ||
ClassOffering.objects.get(name=Classroom.objects.get(id=course_id).course) | ||
) | ||
|
||
|
||
@register.filter | ||
def get_item(dictionary, key): | ||
return dictionary.get(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up notes in #16, this could use input validation and Post/Redirect/Get refactor