Add localize to templates

This commit is contained in:
Nathan Chapman 2021-02-03 21:57:04 -07:00
parent cc311a9424
commit 515967766a
4 changed files with 34 additions and 7 deletions

View File

@ -1,3 +1,4 @@
{% load l10n %}
<section>
<header>
<h1>{{ user.instructor.department.name }}</h1>
@ -25,9 +26,9 @@
<tr>
<td>{{ period.student }}</td>
<td>{{ period.station_number }}</td>
<td>{{ period.clocked_in }}</td>
<td>{{ period.clocked_in|localize }}</td>
{% if period.clocked_out %}
<td>{{ period.clocked_out }}</td>
<td>{{ period.clocked_out|localize }}</td>
<td>{{ period.clocked_in|timesince:period.clocked_out }}</td>
{% else %}
<td>Current sesson: {{ period.clocked_in|timesince }}</td>
@ -60,9 +61,9 @@
<tr>
<td>{{ period.student }}</td>
<td>{{ period.station_number }}</td>
<td>{{ period.clocked_in }}</td>
<td>{{ period.clocked_in|localize }}</td>
{% if period.clocked_out %}
<td>{{ period.clocked_out }}</td>
<td>{{ period.clocked_out|localize }}</td>
<td>{{ period.clocked_in|timesince:period.clocked_out }}</td>
{% else %}
<td colspan="2">Current sesson: {{ period.clocked_in|timesince }}</td>
@ -77,3 +78,23 @@
</table>
</div>
</article>
<article>
<table>
<thead>
<tr>
<th>Student</th>
<th>Total hours</th>
</tr>
</thead>
<tbody>
{% for student in student_list %}
<tr>
<td>{{ student.user.first_name }} {{ student.user.last_name }}</td>
<td>{{ student.total_hours }}</td>
</tr>
{% empty %}
<tr><td colspan="2">No periods yet.</td></tr>
{% endfor %}
</tbody>
</table>
</article>

View File

@ -38,9 +38,9 @@
{% if period.clocked_out %}
<tr>
<td>{{ period.station_number }}</td>
<td>{{ period.clocked_in }}</td>
<td>{{ period.clocked_in|localize }}</td>
{% if period.clocked_out %}
<td>{{ period.clocked_out }}</td>
<td>{{ period.clocked_out|localize }}</td>
<td>{{ period.clocked_in|timesince:period.clocked_out }}</td>
{% else %}
<td colspan="2">Current sesson: {{ period.clocked_in|timesince }}</td>

View File

@ -1,5 +1,6 @@
from django.shortcuts import render, reverse
from django.db.models import Avg, Count, Min, Sum
from django.db.models.functions import Round
from django.urls import reverse_lazy
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
@ -28,7 +29,9 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView):
context = super().get_context_data(**kwargs)
context['user'] = User.objects.get(pk=self.request.user.id)
if hasattr(self.request.user, 'instructor'):
context['student_list'] = Student.objects.filter(department=self.request.user.instructor.department)
context['student_list'] = Student.objects.filter(
department=self.request.user.instructor.department
).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
@ -41,6 +44,8 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView):
clocked_in__month=timezone.now().month
).aggregate(total_duration=Sum('duration'))
print(periods_duration_sum)
print(timezone.now().month)
hours = 0
# Convert to hours floating point
if periods_duration_sum['total_duration'] != None:

1
fixtures/db_base.json Normal file

File diff suppressed because one or more lines are too long