Merge branch 'develop'
This commit is contained in:
commit
9118053047
@ -29,6 +29,9 @@ class Period(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-clocked_in']
|
||||
|
||||
@property
|
||||
def p_duration(self):
|
||||
return round((self.clocked_out - self.clocked_in).seconds / 3600, 2)
|
||||
|
||||
@ -41,12 +41,13 @@
|
||||
<section class="instructor__attendance_log">
|
||||
<div>
|
||||
<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>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Student</th>
|
||||
<th>Station</th>
|
||||
<th>Date</th>
|
||||
<th>Clocked in</th>
|
||||
<th>Clocked out</th>
|
||||
<th colspan="2">Duration</th>
|
||||
@ -58,9 +59,10 @@
|
||||
<tr>
|
||||
<td>{{ period.student }}</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 %}
|
||||
<td>{{ period.clocked_out }}</td>
|
||||
<td>{{ period.clocked_out|time:"P" }}</td>
|
||||
<td>{{ period.clocked_in|timesince:period.clocked_out }}</td>
|
||||
{% else %}
|
||||
<td colspan="2">Current sesson: {{ period.clocked_in|timesince }}</td>
|
||||
@ -73,6 +75,9 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<a class="action-button" href="{% url 'period-list' %}">See more →</a>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="instructor__total_hours">
|
||||
|
||||
@ -22,5 +22,8 @@
|
||||
<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>
|
||||
{% include 'attendance/_student_periods.html' %}
|
||||
<p>
|
||||
<a class="action-button" href="{% url 'period-list' %}">See previous →</a>
|
||||
</p>
|
||||
</section>
|
||||
</article>
|
||||
|
||||
@ -10,6 +10,7 @@ from . import views
|
||||
urlpatterns = [
|
||||
path('', views.AttendanceOverview.as_view(), name='attendance-overview'),
|
||||
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/<int:pk>/', include([
|
||||
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.detail import DetailView
|
||||
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.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||
from django.utils import timezone
|
||||
@ -31,10 +32,16 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView):
|
||||
if hasattr(self.request.user, 'instructor'):
|
||||
instructor = self.request.user.instructor
|
||||
context['student_list'] = Student.objects.filter(
|
||||
department=instructor
|
||||
department=instructor.department
|
||||
).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'):
|
||||
student = self.request.user.student
|
||||
@ -90,6 +97,24 @@ class AttendanceUpdateView(LoginRequiredMixin, FormView):
|
||||
|
||||
|
||||
# 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):
|
||||
model = Period
|
||||
form_class = PeriodForm
|
||||
|
||||
@ -11,4 +11,13 @@
|
||||
margin: 0 1rem;
|
||||
|
||||
}
|
||||
|
||||
&__add_period {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
&__generate_reports {
|
||||
margin-bottom: 1rem;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user