From 50be5c48159275932361cffe9c1c2d28bf0b63bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?=
 <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de>
Date: Sun, 16 May 2021 04:06:13 +0200
Subject: [PATCH] Fix now indicator in fullcalendar views (AKPlan) for users
 from other timezones

This is done by generating the "now" timestamp from python instead of JavaScript using a newly created templatetag
The new "now" function is used in all AKPlan calendar views as well as in AKScheduling's scheduler view
---
 AKPlan/templates/AKPlan/plan_akslot.html                  | 2 ++
 AKPlan/templates/AKPlan/plan_detail.html                  | 2 ++
 AKPlan/templates/AKPlan/plan_index.html                   | 2 ++
 AKPlan/templates/AKPlan/plan_wall.html                    | 2 ++
 AKPlan/templatetags/tags_AKPlan.py                        | 8 ++++++++
 AKScheduling/templates/admin/AKScheduling/scheduling.html | 1 +
 6 files changed, 17 insertions(+)

diff --git a/AKPlan/templates/AKPlan/plan_akslot.html b/AKPlan/templates/AKPlan/plan_akslot.html
index 95b6ac0e..a3215326 100644
--- a/AKPlan/templates/AKPlan/plan_akslot.html
+++ b/AKPlan/templates/AKPlan/plan_akslot.html
@@ -1,6 +1,7 @@
 {% load static %}
 {% load tz %}
 {% load i18n %}
+{% load tags_AKPlan %}
 
 {% include "AKPlan/load_fullcalendar.html" %}
 
@@ -27,6 +28,7 @@
             scrollTime: '08:00:00',
             allDaySlot: false,
             nowIndicator: true,
+            now: "{% timestamp_now event.timezone %}",
             eventTextColor: '#fff',
             eventColor: '#127ba3',
             // Create entries for all scheduled slots
diff --git a/AKPlan/templates/AKPlan/plan_detail.html b/AKPlan/templates/AKPlan/plan_detail.html
index 7c4423da..417f4c59 100644
--- a/AKPlan/templates/AKPlan/plan_detail.html
+++ b/AKPlan/templates/AKPlan/plan_detail.html
@@ -4,6 +4,7 @@
 {% load i18n %}
 {% load static %}
 {% load tz %}
+{% load tags_AKPlan %}
 
 
 {% block fullcalendar %}
@@ -36,6 +37,7 @@
                     scrollTime: '08:00:00',
                     allDaySlot: false,
                     nowIndicator: true,
+                    now: "{% timestamp_now event.timezone %}",
                     eventTextColor: '#fff',
                     eventColor: '#127ba3',
                     // Create entries for all scheduled slots
diff --git a/AKPlan/templates/AKPlan/plan_index.html b/AKPlan/templates/AKPlan/plan_index.html
index 0f2129bc..c7a5460b 100644
--- a/AKPlan/templates/AKPlan/plan_index.html
+++ b/AKPlan/templates/AKPlan/plan_index.html
@@ -4,6 +4,7 @@
 {% load i18n %}
 {% load static %}
 {% load tz %}
+{% load tags_AKPlan %}
 
 
 {% block fullcalendar %}
@@ -47,6 +48,7 @@
                     editable: false,
                     allDaySlot: false,
                     nowIndicator: true,
+                    now: "{% timestamp_now event.timezone %}",
                     eventTextColor: '#fff',
                     eventColor: '#127ba3',
                     resourceAreaWidth: '15%',
diff --git a/AKPlan/templates/AKPlan/plan_wall.html b/AKPlan/templates/AKPlan/plan_wall.html
index d4ae656b..2ff5eeaf 100644
--- a/AKPlan/templates/AKPlan/plan_wall.html
+++ b/AKPlan/templates/AKPlan/plan_wall.html
@@ -3,6 +3,7 @@
 {% load bootstrap4 %}
 {% load fontawesome_5 %}
 {% load tags_AKModel %}
+{% load tags_AKPlan %}
 {% load tz %}
 
 
@@ -43,6 +44,7 @@
                 editable: false,
                 allDaySlot: false,
                 nowIndicator: true,
+                now: "{% timestamp_now event.timezone %}",
                 eventTextColor: '#fff',
                 eventColor: '#127ba3',
                 height: '90%',
diff --git a/AKPlan/templatetags/tags_AKPlan.py b/AKPlan/templatetags/tags_AKPlan.py
index 5618fd57..c4d5b32b 100644
--- a/AKPlan/templatetags/tags_AKPlan.py
+++ b/AKPlan/templatetags/tags_AKPlan.py
@@ -1,4 +1,7 @@
+from datetime import datetime
+
 from django import template
+from django.utils.formats import date_format
 
 from AKPlan.templatetags.color_gradients import darken
 from AKPlanning import settings
@@ -18,3 +21,8 @@ def highlight_change_colors(akslot):
     recentness = seconds_since_update / settings.PLAN_MAX_HIGHLIGHT_UPDATE_SECONDS
     return darken("#b71540", recentness)
     # return linear_blend("#b71540", "#000000", recentness)
+
+
+@register.simple_tag
+def timestamp_now(tz):
+    return date_format(datetime.now().astimezone(tz), "c")
diff --git a/AKScheduling/templates/admin/AKScheduling/scheduling.html b/AKScheduling/templates/admin/AKScheduling/scheduling.html
index 9a140a4c..28b8b17d 100644
--- a/AKScheduling/templates/admin/AKScheduling/scheduling.html
+++ b/AKScheduling/templates/admin/AKScheduling/scheduling.html
@@ -138,6 +138,7 @@
                 },
                 allDaySlot: false,
                 nowIndicator: true,
+                now: "{% timestamp_now event.timezone %}",
                 eventTextColor: '#fff',
                 eventColor: '#127ba3',
                 eventBackgroundColor: '#28B62C',
-- 
GitLab