From ca84bc99200a8d0323756dbf4f30182315cd9e66 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Tue, 18 Jun 2024 09:11:26 +0200 Subject: [PATCH 01/13] Pickadate format now based on js format. Closes #237 --- .../templates/kiosk/tool_reservation.html | 10 ++--- NEMO/context_processors.py | 10 ++++- NEMO/templates/mobile/new_reservation.html | 10 ++--- NEMO/utilities.py | 43 ++++++++++++++++++- resources/settings.py | 9 ++++ 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index ad055baa..1f1ade7b 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -56,9 +56,9 @@

When would you like to reserve the {{ tool }}?

{% for item in tool_reservation_times %} unavailable_times.push([{{ item.start|date:"U" }},{{ item.end|date:"U" }}]); {% endfor %} - let date_picker = $('#date').pickadate({format: "dddd, mmmm d", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); - let end_time_picker = $('#end').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); + let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "HH:mm", hiddenName: true, formatLabel: format_label}); + let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { date_picker.pickadate('picker').set('select', '{{ date }}', {format: 'yyyy-mm-dd'}) @@ -77,11 +77,11 @@

When would you like to reserve the {{ tool }}?

let start = times[0]; let end = times[1]; if (date_time_selected >= start && date_time_selected < end) { - return 'h:i A !alre!ad!y re!serve!d'; + return '{{ pick_time_format }} !alre!ad!y re!serve!d'; } } } - return "h:i A"; + return '{{ pick_time_format }}'; } revert(120) diff --git a/NEMO/context_processors.py b/NEMO/context_processors.py index 18f3e5f3..c303b37e 100644 --- a/NEMO/context_processors.py +++ b/NEMO/context_processors.py @@ -1,5 +1,11 @@ from NEMO.models import Area, Notification, PhysicalAccessLevel, Tool, User -from NEMO.utilities import date_input_js_format, datetime_input_js_format, time_input_js_format +from NEMO.utilities import ( + date_input_js_format, + datetime_input_js_format, + time_input_js_format, + date_pick_format, + time_pick_format, +) from NEMO.views.customization import CustomizationBase from NEMO.views.notifications import get_notification_counts @@ -84,6 +90,8 @@ def base_context(request): "time_input_js_format": time_input_js_format, "date_input_js_format": date_input_js_format, "datetime_input_js_format": datetime_input_js_format, + "date_pick_format": date_pick_format, + "time_pick_format": time_pick_format, "no_header": request.session.get("no_header", False), "safety_menu_item": customization_values.get("safety_main_menu") == "enabled", "calendar_page_title": customization_values.get("calendar_page_title"), diff --git a/NEMO/templates/mobile/new_reservation.html b/NEMO/templates/mobile/new_reservation.html index eea20145..13783cbf 100644 --- a/NEMO/templates/mobile/new_reservation.html +++ b/NEMO/templates/mobile/new_reservation.html @@ -69,9 +69,9 @@

When would you like to reserve the {{ item }}?

{% for times in item_reservation_times %} unavailable_times.push([{{ times.start|date:"U" }},{{ times.end|date:"U" }}]); {% endfor %} - let date_picker = $('#date').pickadate({format: "dddd, mmmm d", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); - let end_time_picker = $('#end').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); + let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label }); + let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { @@ -93,11 +93,11 @@

When would you like to reserve the {{ item }}?

let start = times[0]; let end = times[1]; if (date_time_selected >= start && date_time_selected < end) { - return 'h:i A !alre!ad!y re!serve!d'; + return '{{ pick_time_format }} !alre!ad!y re!serve!d'; } } } - return "h:i A"; + return "{{ pick_time_format }}"; } diff --git a/NEMO/utilities.py b/NEMO/utilities.py index 09a23124..48510c18 100644 --- a/NEMO/utilities.py +++ b/NEMO/utilities.py @@ -66,6 +66,24 @@ "%%": "%", } +py_to_pick_date_formats = { + "%A": "dddd", + "%a": "ddd", + "%B": "mmmm", + "%b": "mmm", + "%d": "dd", + "%H": "HH", + "%I": "hh", + "%M": "i", + "%m": "mm", + "%p": "A", + "%X": "HH:i", + "%x": "mm/dd/yyyy", + "%Y": "yyyy", + "%y": "yy", + "%%": "%", +} + # Convert a python format string to javascript format string def convert_py_format_to_js(string_format: str) -> str: @@ -74,13 +92,36 @@ def convert_py_format_to_js(string_format: str) -> str: return string_format +def convert_py_to_pick_time(string_format: str) -> str: + try: + return settings.PICK_TIME_FORMAT + except AttributeError: + string_format = ( + string_format.replace("%w", "") + .replace("%s", "") + .replace("%f", "") + .replace("%z", "") + .replace("%Z", "") + .replace("%j", "") + .replace(":%S", "") + .replace("%S", "") + .replace("%U", "") + .replace("%W", "") + .replace("%c", "") + ) + for py, pick in py_to_pick_date_formats.items(): + string_format = pick.join(string_format.split(py)) + return string_format + + time_input_format = get_format("TIME_INPUT_FORMATS")[0] date_input_format = get_format("DATE_INPUT_FORMATS")[0] datetime_input_format = get_format("DATETIME_INPUT_FORMATS")[0] time_input_js_format = convert_py_format_to_js(time_input_format) date_input_js_format = convert_py_format_to_js(date_input_format) datetime_input_js_format = convert_py_format_to_js(datetime_input_format) - +date_pick_format = convert_py_to_pick_time(date_input_format) +time_pick_format = convert_py_to_pick_time(time_input_format) supported_embedded_video_extensions = [".mp4", ".ogv", ".webm", ".3gp"] supported_embedded_pdf_extensions = [".pdf"] diff --git a/resources/settings.py b/resources/settings.py index 02af55e5..b72fdf6a 100644 --- a/resources/settings.py +++ b/resources/settings.py @@ -78,6 +78,15 @@ DATE_INPUT_FORMATS = ["%m/%d/%Y", *global_settings.DATE_INPUT_FORMATS] TIME_INPUT_FORMATS = ["%I:%M:%S %p", *global_settings.TIME_INPUT_FORMATS] +# -------------------- Pick date and time formats -------------------- +# Those formats are optional in most cases and only used on kiosk or mobile views, when picking up date/time separately. +# If not defined, a conversion from DATE_INPUT_FORMATS and TIME_INPUT_FORMATS will be attempted. +# See allowed date formats at https://amsul.ca/pickadate.js/date/#formatting-rules +# See allowed time formats at https://amsul.ca/pickadate.js/time/#formatting-rules +# PICK_DATE_FORMAT = "mm/dd/yyyy" +# PICK_TIME_FORMAT = "HH:i A" + + # -------------------- Internationalization and localization -------------------- # A boolean that specifies whether Django’s translation system should be enabled. # This provides an easy way to turn it off, for performance. From ae7c0960219f5b8500125bb4ab3267ea28102c97 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:50:34 +0200 Subject: [PATCH 02/13] Pickadate format conversion: remove additional unsupported formats. --- NEMO/utilities.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEMO/utilities.py b/NEMO/utilities.py index 48510c18..44e0b693 100644 --- a/NEMO/utilities.py +++ b/NEMO/utilities.py @@ -108,6 +108,13 @@ def convert_py_to_pick_time(string_format: str) -> str: .replace("%U", "") .replace("%W", "") .replace("%c", "") + .replace("%U", "") + .replace("%W", "") + .replace("%G", "") + .replace("%U", "") + .replace("%u", "") + .replace("%V", "") + .replace("%:z", "") ) for py, pick in py_to_pick_date_formats.items(): string_format = pick.join(string_format.split(py)) From 478d1111ca2d0b371e04eab786373b53c078c047 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:51:06 +0200 Subject: [PATCH 03/13] Pickadate format conversion: fix submit format. --- NEMO/apps/kiosk/templates/kiosk/tool_reservation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index 1f1ade7b..293bf0b9 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -57,7 +57,7 @@

When would you like to reserve the {{ tool }}?

unavailable_times.push([{{ item.start|date:"U" }},{{ item.end|date:"U" }}]); {% endfor %} let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "HH:mm", hiddenName: true, formatLabel: format_label}); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "HH:i", hiddenName: true, formatLabel: format_label}); let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { From 971c4edc10092233f1b9b48835019ba18f6ce4c7 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:01:00 +0200 Subject: [PATCH 04/13] Pickadate format: rename variable. --- NEMO/apps/kiosk/templates/kiosk/tool_reservation.html | 10 +++++----- NEMO/context_processors.py | 8 ++++---- NEMO/templates/mobile/new_reservation.html | 10 +++++----- NEMO/utilities.py | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index 293bf0b9..8456f531 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -56,9 +56,9 @@

When would you like to reserve the {{ tool }}?

{% for item in tool_reservation_times %} unavailable_times.push([{{ item.start|date:"U" }},{{ item.end|date:"U" }}]); {% endfor %} - let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "HH:i", hiddenName: true, formatLabel: format_label}); - let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); + let date_picker = $('#date').pickadate({format: "{{ pickadata_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "HH:i", hiddenName: true, formatLabel: format_label}); + let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { date_picker.pickadate('picker').set('select', '{{ date }}', {format: 'yyyy-mm-dd'}) @@ -77,11 +77,11 @@

When would you like to reserve the {{ tool }}?

let start = times[0]; let end = times[1]; if (date_time_selected >= start && date_time_selected < end) { - return '{{ pick_time_format }} !alre!ad!y re!serve!d'; + return '{{ pickadate_time_format }} !alre!ad!y re!serve!d'; } } } - return '{{ pick_time_format }}'; + return '{{ pickadate_time_format }}'; } revert(120) diff --git a/NEMO/context_processors.py b/NEMO/context_processors.py index c303b37e..ddfe78a9 100644 --- a/NEMO/context_processors.py +++ b/NEMO/context_processors.py @@ -3,8 +3,8 @@ date_input_js_format, datetime_input_js_format, time_input_js_format, - date_pick_format, - time_pick_format, + pickadate_date_format, + pickadate_time_format, ) from NEMO.views.customization import CustomizationBase from NEMO.views.notifications import get_notification_counts @@ -90,8 +90,8 @@ def base_context(request): "time_input_js_format": time_input_js_format, "date_input_js_format": date_input_js_format, "datetime_input_js_format": datetime_input_js_format, - "date_pick_format": date_pick_format, - "time_pick_format": time_pick_format, + "pickadate_date_format": pickadate_date_format, + "pickadate_time_format": pickadatetime_format, "no_header": request.session.get("no_header", False), "safety_menu_item": customization_values.get("safety_main_menu") == "enabled", "calendar_page_title": customization_values.get("calendar_page_title"), diff --git a/NEMO/templates/mobile/new_reservation.html b/NEMO/templates/mobile/new_reservation.html index 13783cbf..ae885ea3 100644 --- a/NEMO/templates/mobile/new_reservation.html +++ b/NEMO/templates/mobile/new_reservation.html @@ -69,9 +69,9 @@

When would you like to reserve the {{ item }}?

{% for times in item_reservation_times %} unavailable_times.push([{{ times.start|date:"U" }},{{ times.end|date:"U" }}]); {% endfor %} - let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label }); - let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); + let date_picker = $('#date').pickadate({format: "{{ pickadate_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label }); + let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { @@ -93,11 +93,11 @@

When would you like to reserve the {{ item }}?

let start = times[0]; let end = times[1]; if (date_time_selected >= start && date_time_selected < end) { - return '{{ pick_time_format }} !alre!ad!y re!serve!d'; + return '{{ pickadate_time_format }} !alre!ad!y re!serve!d'; } } } - return "{{ pick_time_format }}"; + return "{{ pickadate_time_format }}"; } diff --git a/NEMO/utilities.py b/NEMO/utilities.py index 44e0b693..5e769050 100644 --- a/NEMO/utilities.py +++ b/NEMO/utilities.py @@ -127,8 +127,8 @@ def convert_py_to_pick_time(string_format: str) -> str: time_input_js_format = convert_py_format_to_js(time_input_format) date_input_js_format = convert_py_format_to_js(date_input_format) datetime_input_js_format = convert_py_format_to_js(datetime_input_format) -date_pick_format = convert_py_to_pick_time(date_input_format) -time_pick_format = convert_py_to_pick_time(time_input_format) +pickadate_date_format = convert_py_to_pick_time(date_input_format) +pickadate_time_format = convert_py_to_pick_time(time_input_format) supported_embedded_video_extensions = [".mp4", ".ogv", ".webm", ".3gp"] supported_embedded_pdf_extensions = [".pdf"] From 23c674a4015c0285c6e256e1e1b2f0dcd9dc0c8e Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:01:24 +0200 Subject: [PATCH 05/13] Pickadate format: remove additional hardcoded value. --- NEMO/apps/kiosk/templates/kiosk/tool_reservation.html | 2 +- NEMO/templates/mobile/new_reservation.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index 8456f531..c935937e 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -61,7 +61,7 @@

When would you like to reserve the {{ tool }}?

let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { - date_picker.pickadate('picker').set('select', '{{ date }}', {format: 'yyyy-mm-dd'}) + date_picker.pickadate('picker').set('select', '{{ date }}', {format: '{{ pickadate_time_format }}'}) } function refresh_times() { start_time_picker.pickatime('picker').render(); diff --git a/NEMO/templates/mobile/new_reservation.html b/NEMO/templates/mobile/new_reservation.html index ae885ea3..24ba5940 100644 --- a/NEMO/templates/mobile/new_reservation.html +++ b/NEMO/templates/mobile/new_reservation.html @@ -75,7 +75,7 @@

When would you like to reserve the {{ item }}?

// set initial date if ('{{ date|default_if_none:'' }}') { - date_picker.pickadate('picker').set('select', '{{ date }}', {format: 'yyyy-mm-dd'}) + date_picker.pickadate('picker').set('select', '{{ date }}', {format: '{{ pickadate_date_format }}'}) } function refresh_times() { From 01b3006c1ce7468a1a6b7a8286b6ac7fea776461 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:04:04 +0200 Subject: [PATCH 06/13] Pickadate format: fix unsupported removal order. --- NEMO/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/utilities.py b/NEMO/utilities.py index 5e769050..6080eb79 100644 --- a/NEMO/utilities.py +++ b/NEMO/utilities.py @@ -100,6 +100,7 @@ def convert_py_to_pick_time(string_format: str) -> str: string_format.replace("%w", "") .replace("%s", "") .replace("%f", "") + .replace("%:z", "") .replace("%z", "") .replace("%Z", "") .replace("%j", "") @@ -114,7 +115,6 @@ def convert_py_to_pick_time(string_format: str) -> str: .replace("%U", "") .replace("%u", "") .replace("%V", "") - .replace("%:z", "") ) for py, pick in py_to_pick_date_formats.items(): string_format = pick.join(string_format.split(py)) From b90cf6ee2271c500bfb3841ed072ec7e1c620b30 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:05:03 +0200 Subject: [PATCH 07/13] Pickadate format: fix typo. --- NEMO/apps/kiosk/templates/kiosk/tool_reservation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index c935937e..0aa8a297 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -56,7 +56,7 @@

When would you like to reserve the {{ tool }}?

{% for item in tool_reservation_times %} unavailable_times.push([{{ item.start|date:"U" }},{{ item.end|date:"U" }}]); {% endfor %} - let date_picker = $('#date').pickadate({format: "{{ pickadata_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); + let date_picker = $('#date').pickadate({format: "{{ pickadate_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "HH:i", hiddenName: true, formatLabel: format_label}); let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date From 9094844dc6df15f773e28a9d44c06c276e388a55 Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:05:30 +0200 Subject: [PATCH 08/13] Pickadate format: fix typo. --- NEMO/context_processors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/context_processors.py b/NEMO/context_processors.py index ddfe78a9..9897cfc7 100644 --- a/NEMO/context_processors.py +++ b/NEMO/context_processors.py @@ -91,7 +91,7 @@ def base_context(request): "date_input_js_format": date_input_js_format, "datetime_input_js_format": datetime_input_js_format, "pickadate_date_format": pickadate_date_format, - "pickadate_time_format": pickadatetime_format, + "pickadate_time_format": pickadate_time_format, "no_header": request.session.get("no_header", False), "safety_menu_item": customization_values.get("safety_main_menu") == "enabled", "calendar_page_title": customization_values.get("calendar_page_title"), From 626be272efa3911af34ebee6d835662d911b92fd Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:08:04 +0200 Subject: [PATCH 09/13] Pickadate format: remove duplicated formats. --- NEMO/utilities.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/NEMO/utilities.py b/NEMO/utilities.py index 6080eb79..3c7ea15a 100644 --- a/NEMO/utilities.py +++ b/NEMO/utilities.py @@ -109,10 +109,7 @@ def convert_py_to_pick_time(string_format: str) -> str: .replace("%U", "") .replace("%W", "") .replace("%c", "") - .replace("%U", "") - .replace("%W", "") .replace("%G", "") - .replace("%U", "") .replace("%u", "") .replace("%V", "") ) From bad044c0edac31448d79ecb2e4680c0f0b77f31b Mon Sep 17 00:00:00 2001 From: r-xyz <100710244+r-xyz@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:58:40 +0200 Subject: [PATCH 10/13] Pickadate format: improved logic. Also renamed variables. --- NEMO/utilities.py | 49 ++++++++++++++++++++----------------------- resources/settings.py | 4 ++-- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/NEMO/utilities.py b/NEMO/utilities.py index 3c7ea15a..47313097 100644 --- a/NEMO/utilities.py +++ b/NEMO/utilities.py @@ -92,30 +92,27 @@ def convert_py_format_to_js(string_format: str) -> str: return string_format -def convert_py_to_pick_time(string_format: str) -> str: - try: - return settings.PICK_TIME_FORMAT - except AttributeError: - string_format = ( - string_format.replace("%w", "") - .replace("%s", "") - .replace("%f", "") - .replace("%:z", "") - .replace("%z", "") - .replace("%Z", "") - .replace("%j", "") - .replace(":%S", "") - .replace("%S", "") - .replace("%U", "") - .replace("%W", "") - .replace("%c", "") - .replace("%G", "") - .replace("%u", "") - .replace("%V", "") - ) - for py, pick in py_to_pick_date_formats.items(): - string_format = pick.join(string_format.split(py)) - return string_format +def convert_py_format_to_pickadate(string_format: str) -> str: + string_format = ( + string_format.replace("%w", "") + .replace("%s", "") + .replace("%f", "") + .replace("%:z", "") + .replace("%z", "") + .replace("%Z", "") + .replace("%j", "") + .replace(":%S", "") + .replace("%S", "") + .replace("%U", "") + .replace("%W", "") + .replace("%c", "") + .replace("%G", "") + .replace("%u", "") + .replace("%V", "") + ) + for py, pick in py_to_pick_date_formats.items(): + string_format = pick.join(string_format.split(py)) + return string_format time_input_format = get_format("TIME_INPUT_FORMATS")[0] @@ -124,8 +121,8 @@ def convert_py_to_pick_time(string_format: str) -> str: time_input_js_format = convert_py_format_to_js(time_input_format) date_input_js_format = convert_py_format_to_js(date_input_format) datetime_input_js_format = convert_py_format_to_js(datetime_input_format) -pickadate_date_format = convert_py_to_pick_time(date_input_format) -pickadate_time_format = convert_py_to_pick_time(time_input_format) +pickadate_date_format = getattr(settings, "PICKADATE_DATE_FORMAT", convert_py_format_to_pickadate(date_input_format)) +pickadate_time_format = getattr(settings, "PICKADATE_TIME_FORMAT", convert_py_format_to_pickadate(time_input_format)) supported_embedded_video_extensions = [".mp4", ".ogv", ".webm", ".3gp"] supported_embedded_pdf_extensions = [".pdf"] diff --git a/resources/settings.py b/resources/settings.py index b72fdf6a..ac032dcc 100644 --- a/resources/settings.py +++ b/resources/settings.py @@ -83,8 +83,8 @@ # If not defined, a conversion from DATE_INPUT_FORMATS and TIME_INPUT_FORMATS will be attempted. # See allowed date formats at https://amsul.ca/pickadate.js/date/#formatting-rules # See allowed time formats at https://amsul.ca/pickadate.js/time/#formatting-rules -# PICK_DATE_FORMAT = "mm/dd/yyyy" -# PICK_TIME_FORMAT = "HH:i A" +# PICKADATE_DATE_FORMAT = "mm/dd/yyyy" +# PICKADATE_TIME_FORMAT = "HH:i A" # -------------------- Internationalization and localization -------------------- From a99b8ad5e7670ae58ab49f177a176fce48209d43 Mon Sep 17 00:00:00 2001 From: Mathieu Rampant Date: Wed, 19 Jun 2024 11:44:49 -0400 Subject: [PATCH 11/13] Update NEMO/apps/kiosk/templates/kiosk/tool_reservation.html --- NEMO/apps/kiosk/templates/kiosk/tool_reservation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index 0aa8a297..3ae15e03 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -57,7 +57,7 @@

When would you like to reserve the {{ tool }}?

unavailable_times.push([{{ item.start|date:"U" }},{{ item.end|date:"U" }}]); {% endfor %} let date_picker = $('#date').pickadate({format: "{{ pickadate_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "HH:i", hiddenName: true, formatLabel: format_label}); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { From b5a7a1670c2ef38ae12acb8de943027c781be41e Mon Sep 17 00:00:00 2001 From: Mathieu Rampant Date: Wed, 19 Jun 2024 11:45:49 -0400 Subject: [PATCH 12/13] Update NEMO/templates/mobile/new_reservation.html --- NEMO/templates/mobile/new_reservation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/templates/mobile/new_reservation.html b/NEMO/templates/mobile/new_reservation.html index 24ba5940..ea2b370d 100644 --- a/NEMO/templates/mobile/new_reservation.html +++ b/NEMO/templates/mobile/new_reservation.html @@ -70,7 +70,7 @@

When would you like to reserve the {{ item }}?

unavailable_times.push([{{ times.start|date:"U" }},{{ times.end|date:"U" }}]); {% endfor %} let date_picker = $('#date').pickadate({format: "{{ pickadate_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times}); - let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label }); + let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') From 06c681465198c1052969219ab420eb415e17ae09 Mon Sep 17 00:00:00 2001 From: Mathieu Rampant Date: Wed, 19 Jun 2024 11:47:22 -0400 Subject: [PATCH 13/13] fixed wrong format for date --- NEMO/apps/kiosk/templates/kiosk/tool_reservation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html index 3ae15e03..1bc8d3f2 100644 --- a/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html +++ b/NEMO/apps/kiosk/templates/kiosk/tool_reservation.html @@ -61,7 +61,7 @@

When would you like to reserve the {{ tool }}?

let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pickadate_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label}); // set initial date if ('{{ date|default_if_none:'' }}') { - date_picker.pickadate('picker').set('select', '{{ date }}', {format: '{{ pickadate_time_format }}'}) + date_picker.pickadate('picker').set('select', '{{ date }}', {format: '{{ pickadate_date_format }}'}) } function refresh_times() { start_time_picker.pickatime('picker').render();