Add pagination for periods
This commit is contained in:
parent
804a3daed7
commit
19deae3d50
@ -29,6 +29,9 @@ class Period(models.Model):
|
|||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['-clocked_in']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def p_duration(self):
|
def p_duration(self):
|
||||||
return round((self.clocked_out - self.clocked_in).seconds / 3600, 2)
|
return round((self.clocked_out - self.clocked_in).seconds / 3600, 2)
|
||||||
|
|||||||
@ -41,12 +41,13 @@
|
|||||||
<section class="instructor__attendance_log">
|
<section class="instructor__attendance_log">
|
||||||
<div>
|
<div>
|
||||||
<h3>Attendance log</h3>
|
<h3>Attendance log</h3>
|
||||||
<a class="instructor__generate_reports action-button" href="">Generate Reports</a>
|
<a class="instructor__generate_reports action-button" href="">Generate Reports →</a>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Student</th>
|
<th>Student</th>
|
||||||
<th>Station</th>
|
<th>Station</th>
|
||||||
|
<th>Date</th>
|
||||||
<th>Clocked in</th>
|
<th>Clocked in</th>
|
||||||
<th>Clocked out</th>
|
<th>Clocked out</th>
|
||||||
<th colspan="2">Duration</th>
|
<th colspan="2">Duration</th>
|
||||||
@ -58,9 +59,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ period.student }}</td>
|
<td>{{ period.student }}</td>
|
||||||
<td>{{ period.station_number }}</td>
|
<td>{{ period.station_number }}</td>
|
||||||
<td>{{ period.clocked_in }}</td>
|
<td>{{ period.clocked_in|date:"M d, y" }}</td>
|
||||||
|
<td>{{ period.clocked_in|time:"P" }}</td>
|
||||||
{% if period.clocked_out %}
|
{% if period.clocked_out %}
|
||||||
<td>{{ period.clocked_out }}</td>
|
<td>{{ period.clocked_out|time:"P" }}</td>
|
||||||
<td>{{ period.clocked_in|timesince:period.clocked_out }}</td>
|
<td>{{ period.clocked_in|timesince:period.clocked_out }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td colspan="2">Current sesson: {{ period.clocked_in|timesince }}</td>
|
<td colspan="2">Current sesson: {{ period.clocked_in|timesince }}</td>
|
||||||
@ -73,6 +75,9 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<p>
|
||||||
|
<a class="action-button" href="{% url 'period-list' %}">See more →</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="instructor__total_hours">
|
<section class="instructor__total_hours">
|
||||||
|
|||||||
@ -22,5 +22,8 @@
|
|||||||
<h2 class="attendance__title">Attendance log</h2>
|
<h2 class="attendance__title">Attendance log</h2>
|
||||||
<p class="attendance__total">Total hours for the month: <strong>{{ period_total.total|timedelta_format:2 }}</strong> <small>(Does not include current session.)</small></p>
|
<p class="attendance__total">Total hours for the month: <strong>{{ period_total.total|timedelta_format:2 }}</strong> <small>(Does not include current session.)</small></p>
|
||||||
{% include 'attendance/_student_periods.html' %}
|
{% include 'attendance/_student_periods.html' %}
|
||||||
|
<p>
|
||||||
|
<a class="action-button" href="{% url 'period-list' %}">See previous →</a>
|
||||||
|
</p>
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@ -10,6 +10,7 @@ from . import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.AttendanceOverview.as_view(), name='attendance-overview'),
|
path('', views.AttendanceOverview.as_view(), name='attendance-overview'),
|
||||||
path('update/', views.AttendanceUpdateView.as_view(), name='attendance-update'),
|
path('update/', views.AttendanceUpdateView.as_view(), name='attendance-update'),
|
||||||
|
path('periods/', views.PeriodListView.as_view(), name='period-list'),
|
||||||
path('periods/new/', views.PeriodCreateView.as_view(), name='period-create'),
|
path('periods/new/', views.PeriodCreateView.as_view(), name='period-create'),
|
||||||
path('periods/<int:pk>/', include([
|
path('periods/<int:pk>/', include([
|
||||||
path('', views.PeriodDetailView.as_view(), name='period-detail'),
|
path('', views.PeriodDetailView.as_view(), name='period-detail'),
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from django.views.generic.base import TemplateView
|
|||||||
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
|
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
|
||||||
from django.views.generic.detail import DetailView
|
from django.views.generic.detail import DetailView
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@ -31,10 +32,16 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView):
|
|||||||
if hasattr(self.request.user, 'instructor'):
|
if hasattr(self.request.user, 'instructor'):
|
||||||
instructor = self.request.user.instructor
|
instructor = self.request.user.instructor
|
||||||
context['student_list'] = Student.objects.filter(
|
context['student_list'] = Student.objects.filter(
|
||||||
department=instructor
|
department=instructor.department
|
||||||
).annotate(total_hours=Sum('period__duration'))
|
).annotate(total_hours=Sum('period__duration'))
|
||||||
|
|
||||||
context['period_list'] = Period.objects.order_by('-clocked_in')
|
context['period_list'] = Period.objects.filter(
|
||||||
|
student__department=instructor.department
|
||||||
|
).filter(
|
||||||
|
clocked_in__year=timezone.now().year
|
||||||
|
).filter(
|
||||||
|
clocked_in__month=timezone.now().month
|
||||||
|
)
|
||||||
|
|
||||||
elif hasattr(self.request.user, 'student'):
|
elif hasattr(self.request.user, 'student'):
|
||||||
student = self.request.user.student
|
student = self.request.user.student
|
||||||
@ -90,6 +97,24 @@ class AttendanceUpdateView(LoginRequiredMixin, FormView):
|
|||||||
|
|
||||||
|
|
||||||
# PERIODS
|
# PERIODS
|
||||||
|
class PeriodListView(LoginRequiredMixin, ListView):
|
||||||
|
model = Period
|
||||||
|
paginate_by = 25
|
||||||
|
template_name = 'attendance/period_list.html'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
if hasattr(self.request.user, 'student'):
|
||||||
|
period_list = Period.objects.filter(
|
||||||
|
student = self.request.user.student
|
||||||
|
)
|
||||||
|
paginator = Paginator(period_list, 25)
|
||||||
|
page_number = self.request.GET.get('page')
|
||||||
|
page_obj = paginator.get_page(page_number)
|
||||||
|
|
||||||
|
context['page_obj'] = page_obj
|
||||||
|
return context
|
||||||
|
|
||||||
class PeriodCreateView(LoginRequiredMixin, CreateView):
|
class PeriodCreateView(LoginRequiredMixin, CreateView):
|
||||||
model = Period
|
model = Period
|
||||||
form_class = PeriodForm
|
form_class = PeriodForm
|
||||||
|
|||||||
@ -11,4 +11,13 @@
|
|||||||
margin: 0 1rem;
|
margin: 0 1rem;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__add_period {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__generate_reports {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user