diff --git a/accounts/models.py b/accounts/models.py index 73df69f..9bbf0b4 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -2,6 +2,7 @@ from django.db import models from django.urls import reverse from django.contrib.auth.models import User + class Department(models.Model): name = models.CharField(max_length=200) diff --git a/accounts/templates/accounts/account_detail.html b/accounts/templates/accounts/account_detail.html index 41bd090..91fc0c9 100644 --- a/accounts/templates/accounts/account_detail.html +++ b/accounts/templates/accounts/account_detail.html @@ -10,7 +10,7 @@ {% elif user.instructor %}
{{ user.instructor.department }}
{% endif %} - {% if periods %} + {% if periods and periods.total %}Total clocked hours: {{ periods.total|timedelta_format }}
{% endif %}diff --git a/attendance/models.py b/attendance/models.py index 4ea25c5..2e1c889 100644 --- a/attendance/models.py +++ b/attendance/models.py @@ -2,6 +2,8 @@ from datetime import datetime from django.db import models from django.urls import reverse from accounts.models import Student +from django.db.models.signals import post_save +from django.dispatch import receiver class Code(models.Model): student = models.ForeignKey(Student, on_delete=models.CASCADE) @@ -46,3 +48,10 @@ class Period(models.Model): if self.clocked_out != None: self.duration = self.clocked_out - self.clocked_in super(Period, self).save(*args, **kwargs) + +@receiver(post_save, sender=Period) +def auto_clockin_student(sender, instance, created, **kwargs): + if created: + instance.student.is_clocked_in = True + instance.student.current_period_id = instance.pk + instance.student.save() diff --git a/attendance/templates/attendance/attendance_form.html b/attendance/templates/attendance/attendance_form.html index 42446ed..8ff7d2b 100644 --- a/attendance/templates/attendance/attendance_form.html +++ b/attendance/templates/attendance/attendance_form.html @@ -7,7 +7,7 @@ {% csrf_token %} {{ form.as_p }} - + {% endblock %} diff --git a/attendance/templates/attendance/attendance_overview_instructor.html b/attendance/templates/attendance/attendance_overview_instructor.html index 75d2799..25efd98 100644 --- a/attendance/templates/attendance/attendance_overview_instructor.html +++ b/attendance/templates/attendance/attendance_overview_instructor.html @@ -93,7 +93,9 @@ {% for student in student_list %}
Total hours for the month: {{ period_total.total|timedelta_format:2 }} (Does not include current session.)
+ {% if monthly_total.duration %} +Total hours for the month: {{ monthly_total.duration|timedelta_format }} + (Does not include current session.) +
+ {% endif %} {% include 'attendance/_student_periods.html' %}See previous → diff --git a/attendance/templates/attendance/period_confirm_delete.html b/attendance/templates/attendance/period_confirm_delete.html index 54ca616..1c42b1a 100644 --- a/attendance/templates/attendance/period_confirm_delete.html +++ b/attendance/templates/attendance/period_confirm_delete.html @@ -2,9 +2,13 @@ {% load static %} {% block content %} -
+