From 79cb2e778e5be3acaeb49c589533d01496fb01b0 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Thu, 4 Jan 2024 12:03:49 +0700 Subject: [PATCH 01/14] Out of range date fix for DataBox view --- src/senaite/databox/browser/view.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/senaite/databox/browser/view.py b/src/senaite/databox/browser/view.py index eb927e2..44c8da4 100644 --- a/src/senaite/databox/browser/view.py +++ b/src/senaite/databox/browser/view.py @@ -57,6 +57,7 @@ class DataBoxView(ListingView): """The default DataBox view """ + from senaite.core.api import dtime template = ViewPageTemplateFile("templates/databox_view.pt") def __init__(self, context, request): From b9805713629b48adef5814cbf7ef1fb011f6f338 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Thu, 4 Jan 2024 12:06:48 +0700 Subject: [PATCH 02/14] Update databox_controls.pt --- src/senaite/databox/browser/templates/databox_controls.pt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/senaite/databox/browser/templates/databox_controls.pt b/src/senaite/databox/browser/templates/databox_controls.pt index 1d199f5..a41991e 100644 --- a/src/senaite/databox/browser/templates/databox_controls.pt +++ b/src/senaite/databox/browser/templates/databox_controls.pt @@ -146,7 +146,7 @@ @@ -161,7 +161,7 @@ From 803fd3beb9e50ad48da4c94b4082da42d887af4f Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:20:48 +0700 Subject: [PATCH 03/14] date properties added props with date check for "date to" field - replace future dates with empty string --- src/senaite/databox/browser/view.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/senaite/databox/browser/view.py b/src/senaite/databox/browser/view.py index 44c8da4..c940f4c 100644 --- a/src/senaite/databox/browser/view.py +++ b/src/senaite/databox/browser/view.py @@ -35,6 +35,7 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from senaite.app.listing.view import ListingView from senaite.app.supermodel.model import SuperModel +from senaite.core.api import dtime from senaite.databox import logger from senaite.databox.behaviors.databox import IDataBoxBehavior from senaite.databox.interfaces import IFieldConverter @@ -57,7 +58,6 @@ class DataBoxView(ListingView): """The default DataBox view """ - from senaite.core.api import dtime template = ViewPageTemplateFile("templates/databox_view.pt") def __init__(self, context, request): @@ -199,6 +199,18 @@ def databox(self): def catalog(self): return self.databox.get_query_catalog() + @property + def date_from(self): + if not self.context.date_from: + return "" + return dtime.date_to_string(self.context.date_from) + + @property + def date_to(self): + if not self.context.date_to or dtime.to_DT(self.context.date_to) > DateTime(): + return "" + return dtime.date_to_string(self.context.date_to) + @view.memoize def get_query_types(self): """Returns the `query_types` list of the context as JSON From a84fc460ffa63a700604379c4f01509ec97b8ba8 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:23:02 +0700 Subject: [PATCH 04/14] Update databox_controls.pt use props of DataBoxView instead of expression --- src/senaite/databox/browser/templates/databox_controls.pt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/senaite/databox/browser/templates/databox_controls.pt b/src/senaite/databox/browser/templates/databox_controls.pt index a41991e..1f3ae42 100644 --- a/src/senaite/databox/browser/templates/databox_controls.pt +++ b/src/senaite/databox/browser/templates/databox_controls.pt @@ -145,8 +145,7 @@ @@ -161,7 +160,7 @@ From e8c1d57b968196d776bb12e067a946572ef117e7 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:36:03 +0700 Subject: [PATCH 05/14] Update databox.py --- src/senaite/databox/behaviors/databox.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/senaite/databox/behaviors/databox.py b/src/senaite/databox/behaviors/databox.py index f9c840f..1a00e33 100644 --- a/src/senaite/databox/behaviors/databox.py +++ b/src/senaite/databox/behaviors/databox.py @@ -163,11 +163,11 @@ def query(self): query["sort_order"] = self.sort_order if self.date_index: - date_from = self.date_from or DateTime("2000-01-01") - date_to = self.date_to or DateTime() + date_from = DateTime(self.date_from or "2000-01-01") + date_to = DateTime() if not self.date_to or DateTime(self.date_to) > DateTime() else DateTime(self.date_to) # always make the to_date inclusive query[self.date_index] = { - "query": (DateTime(date_from), DateTime(date_to) + 1), + "query": (date_from, date_to + 1 if date_from <= date_to else date_from), "range": "minmax" } From f7061c905cf38a4331ccef5658d6030c5ed5b3cd Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:40:40 +0700 Subject: [PATCH 06/14] Update databox.py --- src/senaite/databox/behaviors/databox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/senaite/databox/behaviors/databox.py b/src/senaite/databox/behaviors/databox.py index 1a00e33..5d3295a 100644 --- a/src/senaite/databox/behaviors/databox.py +++ b/src/senaite/databox/behaviors/databox.py @@ -164,7 +164,7 @@ def query(self): if self.date_index: date_from = DateTime(self.date_from or "2000-01-01") - date_to = DateTime() if not self.date_to or DateTime(self.date_to) > DateTime() else DateTime(self.date_to) + date_to = DateTime(self.date_to) if self.date_to else DateTime() # always make the to_date inclusive query[self.date_index] = { "query": (date_from, date_to + 1 if date_from <= date_to else date_from), From fcb273e67e6a6ba829ba8592e424372f07f798e3 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:47:17 +0700 Subject: [PATCH 07/14] Update view.py --- src/senaite/databox/browser/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/senaite/databox/browser/view.py b/src/senaite/databox/browser/view.py index c940f4c..45d1c09 100644 --- a/src/senaite/databox/browser/view.py +++ b/src/senaite/databox/browser/view.py @@ -207,7 +207,7 @@ def date_from(self): @property def date_to(self): - if not self.context.date_to or dtime.to_DT(self.context.date_to) > DateTime(): + if not self.context.date_to or self.context.date_to < self.context.date_from: return "" return dtime.date_to_string(self.context.date_to) From 37462657ad83f3c055a5de32002c53263f174c28 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:56:45 +0700 Subject: [PATCH 08/14] Update view.py --- src/senaite/databox/browser/view.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/senaite/databox/browser/view.py b/src/senaite/databox/browser/view.py index 45d1c09..66146ca 100644 --- a/src/senaite/databox/browser/view.py +++ b/src/senaite/databox/browser/view.py @@ -207,8 +207,10 @@ def date_from(self): @property def date_to(self): - if not self.context.date_to or self.context.date_to < self.context.date_from: + if not self.context.date_to: return "" + if self.context.date_to < self.context.date_from: + return dtime.date_to_string(self.context.date_from) return dtime.date_to_string(self.context.date_to) @view.memoize From 3c7b87b6e3b17148c3e031ebabb35f299a309ee2 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 16:59:57 +0700 Subject: [PATCH 09/14] Update view.py --- src/senaite/databox/browser/view.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/senaite/databox/browser/view.py b/src/senaite/databox/browser/view.py index 66146ca..5c701f3 100644 --- a/src/senaite/databox/browser/view.py +++ b/src/senaite/databox/browser/view.py @@ -203,8 +203,8 @@ def catalog(self): def date_from(self): if not self.context.date_from: return "" - return dtime.date_to_string(self.context.date_from) - + return dtime.date_to_string(self.context.date_from) + @property def date_to(self): if not self.context.date_to: @@ -212,7 +212,7 @@ def date_to(self): if self.context.date_to < self.context.date_from: return dtime.date_to_string(self.context.date_from) return dtime.date_to_string(self.context.date_to) - + @view.memoize def get_query_types(self): """Returns the `query_types` list of the context as JSON From f9209361d05ee1bafdb351c805fb0de5cf783749 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 17:00:48 +0700 Subject: [PATCH 10/14] Update databox.py --- src/senaite/databox/behaviors/databox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/senaite/databox/behaviors/databox.py b/src/senaite/databox/behaviors/databox.py index 5d3295a..692b911 100644 --- a/src/senaite/databox/behaviors/databox.py +++ b/src/senaite/databox/behaviors/databox.py @@ -164,7 +164,7 @@ def query(self): if self.date_index: date_from = DateTime(self.date_from or "2000-01-01") - date_to = DateTime(self.date_to) if self.date_to else DateTime() + date_to = DateTime(self.date_to) if self.date_to else DateTime() # always make the to_date inclusive query[self.date_index] = { "query": (date_from, date_to + 1 if date_from <= date_to else date_from), From d3d626aceb1226c549f00c52effc812ea61d34e9 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 17:08:28 +0700 Subject: [PATCH 11/14] Update databox.py --- src/senaite/databox/behaviors/databox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/senaite/databox/behaviors/databox.py b/src/senaite/databox/behaviors/databox.py index 692b911..92a139c 100644 --- a/src/senaite/databox/behaviors/databox.py +++ b/src/senaite/databox/behaviors/databox.py @@ -167,7 +167,7 @@ def query(self): date_to = DateTime(self.date_to) if self.date_to else DateTime() # always make the to_date inclusive query[self.date_index] = { - "query": (date_from, date_to + 1 if date_from <= date_to else date_from), + "query": (date_from, (date_to if date_from <= date_to else date_from) + 1), "range": "minmax" } From 53bb88d9da82c91ff7619e280b7759d620f1091b Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 17:18:29 +0700 Subject: [PATCH 12/14] Update Changelog.rst --- docs/Changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Changelog.rst b/docs/Changelog.rst index 0ae42a7..2494f29 100644 --- a/docs/Changelog.rst +++ b/docs/Changelog.rst @@ -1,7 +1,7 @@ 1.5.0 (unreleased) ------------------ -- no changes yet +- #33 Fix date issues when user inputs: date out of bound or date_to earlier then date_from 1.4.1 (2024-01-03) From 9cae2c969ec134d0e7080324c16e9755e2a3477b Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 17:25:25 +0700 Subject: [PATCH 13/14] Update Changelog.rst --- docs/Changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Changelog.rst b/docs/Changelog.rst index 2494f29..a8ef677 100644 --- a/docs/Changelog.rst +++ b/docs/Changelog.rst @@ -1,7 +1,7 @@ 1.5.0 (unreleased) ------------------ -- #33 Fix date issues when user inputs: date out of bound or date_to earlier then date_from +- #33 Fix date issues when user inputs: date out of bound or date_to earlier than date_from 1.4.1 (2024-01-03) From 25f1c19bdb098ac04562db7d38356e5b3ad05794 Mon Sep 17 00:00:00 2001 From: Leonid Toporkov Date: Mon, 8 Jan 2024 17:49:57 +0700 Subject: [PATCH 14/14] Update view.py --- src/senaite/databox/browser/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/senaite/databox/browser/view.py b/src/senaite/databox/browser/view.py index 5c701f3..e4c2db2 100644 --- a/src/senaite/databox/browser/view.py +++ b/src/senaite/databox/browser/view.py @@ -209,7 +209,7 @@ def date_from(self): def date_to(self): if not self.context.date_to: return "" - if self.context.date_to < self.context.date_from: + if self.context.date_from and self.context.date_to < self.context.date_from: return dtime.date_to_string(self.context.date_from) return dtime.date_to_string(self.context.date_to)