From f5413b19436e78437a0ffdbf94c5f178f37a21e8 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 3 Apr 2017 16:26:04 +0200 Subject: [PATCH] timezone sepcific issues --- smash/web/api_views/appointment.py | 13 +++++++++---- smash/web/templates/appointments/list.html | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/smash/web/api_views/appointment.py b/smash/web/api_views/appointment.py index 575e6b50..e0106093 100644 --- a/smash/web/api_views/appointment.py +++ b/smash/web/api_views/appointment.py @@ -1,4 +1,5 @@ import traceback +import pytz from django.contrib.auth.decorators import login_required from django.http import JsonResponse @@ -14,15 +15,15 @@ from web.views.notifications import get_filter_locations, \ @login_required def get_appointments(request, type): if type == APPOINTMENT_LIST_GENERIC: - return Appointment.objects.filter(location__in=get_filter_locations(request.user)).order_by("-datetime_when") + return Appointment.objects.filter(location__in=get_filter_locations(request.user)).order_by("datetime_when") elif type == APPOINTMENT_LIST_UNFINISHED: - return get_unfinished_appointments(request.user).order_by("-datetime_when") + return get_unfinished_appointments(request.user).order_by("datetime_when") elif type == APPOINTMENT_LIST_APPROACHING: return Appointment.objects.filter( datetime_when__gt=get_today_midnight_date(), location__in=get_filter_locations(request.user), status=Appointment.APPOINTMENT_STATUS_SCHEDULED - ).order_by("-datetime_when") + ).order_by("datetime_when") else: raise TypeError("Unknown query type: " + type) @@ -71,6 +72,8 @@ def appointments(request, type): def serialize_appointment(appointment): + local_tz = pytz.timezone('UTC') + subject = "" if appointment.visit is not None: title = appointment.visit.follow_up_title() @@ -83,7 +86,9 @@ def serialize_appointment(appointment): type += appointment_type.code + ", " time = "" if appointment.datetime_when is not None: - time = appointment.datetime_when.strftime("%Y-%m-%d") + time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M') + # time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M:%S.%f %Z%z') + result = { "subject": subject, "title": title, diff --git a/smash/web/templates/appointments/list.html b/smash/web/templates/appointments/list.html index e6261de6..b20d99c7 100644 --- a/smash/web/templates/appointments/list.html +++ b/smash/web/templates/appointments/list.html @@ -66,7 +66,23 @@ "targets": 5, "data": "id", "defaultContent": '<a href="#" type="button" class="btn btn-block btn-default">Edit</a>' - }] + }, +{# {#} +{# render: function (data, type, row) {#} +{# var date = new Date(data);#} +{# var mm = date.getMonth() + 1; // getMonth() is zero-based#} +{# var dd = date.getDate();#} +{# var hour = date.getHours();#} +{# var minute = date.getMinutes();#} +{##} +{# return [date.getFullYear(),#} +{# (mm > 9 ? '' : '0') + mm,#} +{# (dd > 9 ? '' : '0') + dd#} +{# ].join('-') + " " + hour + ":" + minute;#} +{# },#} +{# targets: 3#} +{# }#} + ] }); $('#table tbody').on('click', 'a', function () { -- GitLab