diff --git a/attendance/models.py b/attendance/models.py index e86dd76..838c69d 100644 --- a/attendance/models.py +++ b/attendance/models.py @@ -29,10 +29,9 @@ class Period(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) - # def duration(self): - # duration = self.clocked_out - self.clocked_in - # duration_in_s = duration.total_seconds() - # return divmod(duration_in_s, 3600)[0] + @property + def p_duration(self): + return round((self.clocked_out - self.clocked_in).seconds / 3600, 2) def get_absolute_url(self): return reverse('period-detail', kwargs={'pk': self.pk}) diff --git a/attendance/templates/attendance/attendance_form.html b/attendance/templates/attendance/attendance_form.html index d3c38f9..42446ed 100644 --- a/attendance/templates/attendance/attendance_form.html +++ b/attendance/templates/attendance/attendance_form.html @@ -1,10 +1,9 @@ {% extends 'application.html' %} {% block content %} -

Scan code to clock-in/out

- -
-
+
+

Scan code to clock-in/out

+ {% csrf_token %} {{ form.as_p }} diff --git a/attendance/templates/attendance/attendance_overview_instructor.html b/attendance/templates/attendance/attendance_overview_instructor.html index c7b818f..d3cb5e6 100644 --- a/attendance/templates/attendance/attendance_overview_instructor.html +++ b/attendance/templates/attendance/attendance_overview_instructor.html @@ -1,99 +1,102 @@ -
-
-

{{ user.instructor.department.name }}

+{% load timedelta_filter %} +
- -

Active sessions

-

- + Add new session -

- - - - - - - - - - - {% for period in period_list %} - {% if not period.clocked_out %} + +
+

Students clocked-in

+

+ + Add new session +

+
StudentStationClocked inDuration
+ - - - - {% if period.clocked_out %} - - - {% else %} - - {% endif %} - + + + + - {% endif %} - {% empty %} - - {% endfor %} - -
{{ period.student }}{{ period.station_number }}{{ period.clocked_in }}{{ period.clocked_out }}{{ period.clocked_in|timesince:period.clocked_out }}Current sesson: {{ period.clocked_in|timesince }}ViewStudentStationClocked inDuration
No periods yet.
-
-
-
-

Attendance log

- - - - - - - - - - - - {% for period in period_list %} - {% if period.clocked_out %} - - - - - {% if period.clocked_out %} - - - {% else %} - + + + {% for period in period_list %} + {% if not period.clocked_out %} + + + + + {% if period.clocked_out %} + + + {% else %} + + {% endif %} + + {% endif %} - - - {% endif %} - {% empty %} - - {% endfor %} - -
StudentStationClocked inClocked outDuration
{{ period.student }}{{ period.station_number }}{{ period.clocked_in }}{{ period.clocked_out }}{{ period.clocked_in|timesince:period.clocked_out }}Current sesson: {{ period.clocked_in|timesince }}
{{ period.student }}{{ period.station_number }}{{ period.clocked_in }}{{ period.clocked_out }}{{ period.clocked_in|timesince:period.clocked_out }}Current sesson: {{ period.clocked_in|timesince }}View
View
No periods yet.
-
-
-
- - - - - - - - - {% for student in student_list %} + {% empty %} + + {% endfor %} + +
StudentTotal hours
No periods yet.
+ +
+
+
+

Attendance log

+ + - - + + + + + - {% empty %} - - {% endfor %} - -
{{ student.user.first_name }} {{ student.user.last_name }}{{ student.total_hours }}StudentStationClocked inClocked outDuration
No periods yet.
+ + + {% for period in period_list %} + {% if period.clocked_out %} + + {{ period.student }} + {{ period.station_number }} + {{ period.clocked_in }} + {% if period.clocked_out %} + {{ period.clocked_out }} + {{ period.clocked_in|timesince:period.clocked_out }} + {% else %} + Current sesson: {{ period.clocked_in|timesince }} + {% endif %} + View + + {% endif %} + {% empty %} + No periods yet. + {% endfor %} + + +
+
+
+ + + + + + + + + {% for student in student_list %} + + + + + {% empty %} + + {% endfor %} + +
StudentTotal hours
{{ student.user.first_name }} {{ student.user.last_name }}{{ student.total_hours|dimedelta_format }}
No periods yet.
+
diff --git a/attendance/templates/attendance/attendance_overview_student.html b/attendance/templates/attendance/attendance_overview_student.html index b371c6d..600a57b 100644 --- a/attendance/templates/attendance/attendance_overview_student.html +++ b/attendance/templates/attendance/attendance_overview_student.html @@ -1,22 +1,25 @@ -
-

{{ user.student.department.name }}

- {% if user.student.is_clocked_in %} -
-

You are currently clocked in.

-

- Clocked in at: {{ current_period.clocked_in|date:"P" }}
- Current sesson: {{ current_period.clocked_in|timesince }} -

-
- {% include 'attendance/_student_code.html' with clocked_in=True %} - {% else %} -
You are not clocked in.

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

Attendance log

-

Total hours for the month: {{period_total}}
- (Does not include current session.)

- {% include 'attendance/_student_periods.html' %} -
+{% load timedelta_filter %} +
+
+

{{ user.student.department.name }}

+ {% if user.student.is_clocked_in %} +
+

You are currently clocked in.

+

+ Clocked in at: {{ current_period.clocked_in|date:"P" }}
+ Current sesson: {{ current_period.clocked_in|timesince }} +

+
+ {% include 'attendance/_student_code.html' with clocked_in=True %} + {% else %} +
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 }}
+ (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 26159d4..6752f53 100644 --- a/attendance/templates/attendance/code_detail.html +++ b/attendance/templates/attendance/code_detail.html @@ -2,11 +2,10 @@ {% load qr_code %} {% block content %} -

Clock in

- -
-

Scan code at clock-in station

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

Clock in

+

Scan code at clock-in station

+ {% qr_from_text code.qr_code_str size=24 version=2 %} + Done
{% endblock %} diff --git a/attendance/templates/attendance/code_form.html b/attendance/templates/attendance/code_form.html index 7a32adf..5685814 100644 --- a/attendance/templates/attendance/code_form.html +++ b/attendance/templates/attendance/code_form.html @@ -1,10 +1,10 @@ {% extends 'application.html' %} {% block content %} -

Generate code

-
- +
+

Generate code

+ {% csrf_token %} {{ form.as_p }} diff --git a/attendance/templatetags/__init__.py b/attendance/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/attendance/templatetags/timedelta_filter.py b/attendance/templatetags/timedelta_filter.py new file mode 100644 index 0000000..9351c96 --- /dev/null +++ b/attendance/templatetags/timedelta_filter.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + +@register.filter() +def dimedelta_format(value, arg=2): + """Format timedelta""" + return round((value).seconds / 3600, arg) diff --git a/attendance/views.py b/attendance/views.py index 1973ba5..167d08d 100644 --- a/attendance/views.py +++ b/attendance/views.py @@ -27,7 +27,7 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['user'] = User.objects.get(pk=self.request.user.id) + context['user'] = self.request.user if hasattr(self.request.user, 'instructor'): context['student_list'] = Student.objects.filter( department=self.request.user.instructor.department @@ -36,18 +36,18 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView): elif hasattr(self.request.user, 'student'): student = self.request.user.student # sum all duration fields for student - periods_duration_sum = Period.objects.filter( + context['period_total'] = Period.objects.filter( student = student ).filter( clocked_in__year=timezone.now().year ).filter( clocked_in__month=timezone.now().month - ).aggregate(total_duration=Sum('duration')) + ).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) + # 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 @@ -56,7 +56,6 @@ class AttendanceOverview(LoginRequiredMixin, TemplateView): ).filter( clocked_in__month=timezone.now().month ).order_by('-clocked_in') - context['period_total'] = hours if student.current_period_id != None: context['current_period'] = Period.objects.get(pk=student.current_period_id) return context @@ -141,7 +140,7 @@ class CodeDetailView(LoginRequiredMixin, DetailView): class CodeUpdateView(LoginRequiredMixin, UpdateView): model = Code fields = ['station_number'] - template_name = 'attendance/code_update_form.html' + template_name = 'attendance/code_form.html' def get_success_url(self): pk = self.kwargs["pk"] diff --git a/static/scss/_attendance.scss b/static/scss/_attendance.scss new file mode 100644 index 0000000..e69de29 diff --git a/static/scss/_codes.scss b/static/scss/_codes.scss index e69de29..c721109 100644 --- a/static/scss/_codes.scss +++ b/static/scss/_codes.scss @@ -0,0 +1,16 @@ +.code-detail { + display: flex; + flex-direction: column; + align-items: center; + + &__instructions { + + } + &__qrcode { + + } + &__done { + margin: 1rem 0; + + } +} diff --git a/static/scss/_forms.scss b/static/scss/_forms.scss index 64d6852..9ca8e18 100644 --- a/static/scss/_forms.scss +++ b/static/scss/_forms.scss @@ -51,6 +51,7 @@ input[type=submit], color: white; cursor: pointer; text-decoration: none; + border-radius: 3.75rem; } input:focus, diff --git a/static/scss/_globals.scss b/static/scss/_globals.scss index 8ad9e20..ce6d6d1 100644 --- a/static/scss/_globals.scss +++ b/static/scss/_globals.scss @@ -51,7 +51,7 @@ hr { } // BLOCK ELEMENTS -main { +main, aside { max-width: 58rem; margin: 0 auto; } diff --git a/static/scss/_instructors.scss b/static/scss/_instructors.scss index e69de29..aa1cb04 100644 --- a/static/scss/_instructors.scss +++ b/static/scss/_instructors.scss @@ -0,0 +1,14 @@ +.instructor { + &__active_periods { + + } + + &__attendance_log { + margin: 0 1rem; + } + + &__total_hours { + margin: 0 1rem; + + } +} diff --git a/static/scss/_messages.scss b/static/scss/_messages.scss new file mode 100644 index 0000000..4117097 --- /dev/null +++ b/static/scss/_messages.scss @@ -0,0 +1,3 @@ +.messages { + +} diff --git a/static/scss/_students.scss b/static/scss/_students.scss index b396f87..ad351ce 100644 --- a/static/scss/_students.scss +++ b/static/scss/_students.scss @@ -1,9 +1,7 @@ .student { &__header { - display: flex; - justify-content: space-between; - align-items: baseline; + } &__department { diff --git a/static/scss/main.scss b/static/scss/main.scss index bc4d059..81363ac 100644 --- a/static/scss/main.scss +++ b/static/scss/main.scss @@ -3,9 +3,11 @@ @import "helpers"; @import "forms"; @import "nav"; +@import "messages"; @import "registration"; @import "students"; @import "instructors"; +@import "attendance"; @import "periods"; @import "codes"; diff --git a/templates/application.html b/templates/application.html index 8e5d3af..a2db450 100644 --- a/templates/application.html +++ b/templates/application.html @@ -32,11 +32,11 @@