From ee472fb9a06a22059e05e44a3e3bddedf16d9c0c Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Fri, 5 Feb 2021 23:05:16 -0700 Subject: [PATCH] Change templates, update timedelta filter --- .../templates/accounts/account_detail.html | 19 +++++---- accounts/templates/accounts/account_list.html | 17 ++++++-- accounts/views.py | 10 +++++ .../templates/attendance/_student_code.html | 32 +++++++-------- .../attendance_overview_instructor.html | 39 +++++++++---------- .../attendance_overview_student.html | 8 ++-- .../templates/attendance/code_detail.html | 7 ++-- .../templates/attendance/period_form.html | 6 +-- attendance/templatetags/timedelta_filter.py | 10 +++-- attendance/views.py | 11 +++--- static/scss/_attendance.scss | 14 +++++++ static/scss/_forms.scss | 5 ++- templates/application.html | 5 ++- tracker/middleware.py | 3 -- 14 files changed, 111 insertions(+), 75 deletions(-) diff --git a/accounts/templates/accounts/account_detail.html b/accounts/templates/accounts/account_detail.html index 025a013..cb7381d 100644 --- a/accounts/templates/accounts/account_detail.html +++ b/accounts/templates/accounts/account_detail.html @@ -1,12 +1,15 @@ {% extends 'application.html' %} +{% load timedelta_filter %} {% block content %} -

User

-
-

{{ user.first_name }} {{ user.last_name }}

-

{{ user.email }}

-

- Update -

-
+
+

{{ user.first_name }} {{ user.last_name }}

+

{{ user.email }}

+ {% if periods %} +

Total clocked hours: {{ periods.total|timedelta_format }}

+ {% endif %} +

+ Update +

+
{% endblock %} diff --git a/accounts/templates/accounts/account_list.html b/accounts/templates/accounts/account_list.html index 31fe62d..5bbc6f9 100644 --- a/accounts/templates/accounts/account_list.html +++ b/accounts/templates/accounts/account_list.html @@ -1,15 +1,24 @@ {% extends 'application.html' %} {% block content %} -

Users

-
+
+

Users

+ + + + + {% for user in user_list %} - - + + {% if user.student %} + + {% elif user.instructor %} + + {% endif %} {% empty %} diff --git a/accounts/views.py b/accounts/views.py index 9b4aa25..b028a6e 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,5 +1,6 @@ import pytz from django.shortcuts import render, reverse, redirect +from django.db.models import Avg, Count, Min, Sum from django.urls import reverse_lazy from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView from django.views.generic.detail import DetailView @@ -8,6 +9,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.models import User from django.contrib.auth.forms import PasswordChangeForm +from attendance.models import Period def set_timezone(request): if request.method == 'POST': @@ -29,6 +31,14 @@ class AccountDetailView(LoginRequiredMixin, DetailView): model = User template_name = 'accounts/account_detail.html' + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + if hasattr(context['object'], 'student'): + context['periods'] = Period.objects.filter( + student = context['object'].student + ).aggregate(total=Sum('duration')) + return context + class AccountUpdateView(LoginRequiredMixin, UpdateView): model = User # form_class = PasswordChangeForm diff --git a/attendance/templates/attendance/_student_code.html b/attendance/templates/attendance/_student_code.html index 5d0259e..a6522a1 100644 --- a/attendance/templates/attendance/_student_code.html +++ b/attendance/templates/attendance/_student_code.html @@ -1,21 +1,17 @@ {% if user.student.code_set.last %} -

- - {% if clocked_in %} - Clock out → - {% else %} - Clock in → - {% endif %} - -

+ + {% if clocked_in %} + Clock out → + {% else %} + Clock in → + {% endif %} + {% else %} -

- - {% if clocked_in %} - Clock out → - {% else %} - Clock in → - {% endif %} - -

+ + {% if clocked_in %} + Clock out → + {% else %} + Clock in → + {% endif %} + {% endif %} diff --git a/attendance/templates/attendance/attendance_overview_instructor.html b/attendance/templates/attendance/attendance_overview_instructor.html index d3cb5e6..a6b266a 100644 --- a/attendance/templates/attendance/attendance_overview_instructor.html +++ b/attendance/templates/attendance/attendance_overview_instructor.html @@ -2,15 +2,10 @@
UsernameNameRole
{{ user.username }}{{user.first_name}} {{user.last_name}}Update{{user.first_name}} {{user.last_name}}StudentInstructor
No users yet.
@@ -46,6 +41,7 @@

Attendance log

+ Generate Reports
@@ -80,23 +76,24 @@
+

Total hours

- + + + + + + + + {% for student in student_list %} - - + + - - - {% for student in student_list %} - - - - - {% empty %} - - {% endfor %} - -
StudentTotal hours
StudentTotal hours{{ student.user.first_name }} {{ student.user.last_name }}{{ student.total_hours|timedelta_format }}
{{ student.user.first_name }} {{ student.user.last_name }}{{ student.total_hours|dimedelta_format }}
No periods yet.
+ {% empty %} + No periods yet. + {% endfor %} + +
diff --git a/attendance/templates/attendance/attendance_overview_student.html b/attendance/templates/attendance/attendance_overview_student.html index 600a57b..0569ece 100644 --- a/attendance/templates/attendance/attendance_overview_student.html +++ b/attendance/templates/attendance/attendance_overview_student.html @@ -12,13 +12,15 @@ {% include 'attendance/_student_code.html' with clocked_in=True %} {% else %} -
You are not clocked in.

- {% include 'attendance/_student_code.html' with clocked_in=False %} +
+

You are not clocked in.

+ {% include 'attendance/_student_code.html' with clocked_in=False %} +
{% endif %}

Attendance log

-

Total hours for the month: {{ period_total.total|dimedelta_format:2 }}
+

Total hours for the month: {{ period_total.total|timedelta_format:2 }}
(Does not include current session.)

{% include 'attendance/_student_periods.html' %}
diff --git a/attendance/templates/attendance/code_detail.html b/attendance/templates/attendance/code_detail.html index 6752f53..b7a78fd 100644 --- a/attendance/templates/attendance/code_detail.html +++ b/attendance/templates/attendance/code_detail.html @@ -3,9 +3,8 @@ {% block content %}
-

Clock in

-

Scan code at clock-in station

- {% qr_from_text code.qr_code_str size=24 version=2 %} - Done +

Scan code

+ {% qr_from_text code.qr_code_str size=18 version=2 %} + Done
{% endblock %} diff --git a/attendance/templates/attendance/period_form.html b/attendance/templates/attendance/period_form.html index cfd202d..3a28c2e 100644 --- a/attendance/templates/attendance/period_form.html +++ b/attendance/templates/attendance/period_form.html @@ -1,15 +1,15 @@ {% extends 'application.html' %} {% block content %} -

Generate Period

-
+
+

Generate Period

{% csrf_token %} {{ form.as_p }} or - Cancel + Cancel
{% endblock %} diff --git a/attendance/templatetags/timedelta_filter.py b/attendance/templatetags/timedelta_filter.py index 9351c96..fa7e9ea 100644 --- a/attendance/templatetags/timedelta_filter.py +++ b/attendance/templatetags/timedelta_filter.py @@ -3,6 +3,10 @@ from django import template register = template.Library() @register.filter() -def dimedelta_format(value, arg=2): - """Format timedelta""" - return round((value).seconds / 3600, arg) +def timedelta_format(value, arg=2): + """Returns timedelta as float rounded to arg, with default of 2""" + if value.days: + return round((value.days*24) + value.seconds/3600, arg) + elif value.seconds: + return round(value.seconds/3600, arg) + return 0 diff --git a/attendance/views.py b/attendance/views.py index 167d08d..d047572 100644 --- a/attendance/views.py +++ b/attendance/views.py @@ -29,12 +29,16 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView): context = super().get_context_data(**kwargs) context['user'] = self.request.user if hasattr(self.request.user, 'instructor'): + instructor = self.request.user.instructor context['student_list'] = Student.objects.filter( - department=self.request.user.instructor.department + department=instructor ).annotate(total_hours=Sum('period__duration')) + context['period_list'] = Period.objects.order_by('-clocked_in') + elif hasattr(self.request.user, 'student'): student = self.request.user.student + # sum all duration fields for student context['period_total'] = Period.objects.filter( student = student @@ -44,11 +48,6 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView): clocked_in__month=timezone.now().month ).aggregate(total=Sum('duration')) - # hours = 0 - # # Convert to hours floating point - # if periods_duration_sum['total_duration'] != None: - # hours = round((periods_duration_sum['total_duration'].total_seconds() / 3600), 2) - context['period_list'] = Period.objects.filter( student=student ).filter( diff --git a/static/scss/_attendance.scss b/static/scss/_attendance.scss index e69de29..3f136d0 100644 --- a/static/scss/_attendance.scss +++ b/static/scss/_attendance.scss @@ -0,0 +1,14 @@ +.clockin { + display: flex; + flex-direction: column; + align-items: center; + + &__form { + text-align: center; + + input[type=text] { + width: 300px; + } + + } +} diff --git a/static/scss/_forms.scss b/static/scss/_forms.scss index 9ca8e18..aec48fc 100644 --- a/static/scss/_forms.scss +++ b/static/scss/_forms.scss @@ -45,7 +45,7 @@ textarea { input[type=submit], .action-button { font-weight: 900; - padding: 0.5em 1em; + padding: 0.2rem 1rem; border: none; background-color: $blue; color: white; @@ -91,5 +91,8 @@ textarea { } .action-button { + // margin-bottom: 1rem; + display: inline-block; + padding: 0.2rem 1rem; border-radius: 3.75rem; } diff --git a/templates/application.html b/templates/application.html index a2db450..f828931 100644 --- a/templates/application.html +++ b/templates/application.html @@ -22,7 +22,10 @@