From 90c4b9b2134b5839eb3c7395b4e9bba01223898d Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Fri, 4 Sep 2015 12:31:01 +0200 Subject: [PATCH] add before/after relative date query see #45 --- CHANGES.rst | 3 +- plone/app/querystring/hiddenprofiles.py | 2 + plone/app/querystring/profiles.zcml | 8 +++ .../querystring/profiles/default/metadata.xml | 2 +- .../querystring/profiles/default/registry.xml | 28 ++++++++ .../profiles/upgrades/to_11/registry.xml | 68 +++++++++++++++++++ plone/app/querystring/queryparser.py | 22 ++++++ .../app/querystring/tests/testQueryParser.py | 26 +++++++ plone/app/querystring/upgrades.zcml | 10 +++ 9 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 plone/app/querystring/profiles/upgrades/to_11/registry.xml diff --git a/CHANGES.rst b/CHANGES.rst index 8029e85..83ea82a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 1.3.7 (unreleased) ------------------ -- Nothing changed yet. +- Add "before/after N days" functionality + [petschki] 1.3.6 (2015-08-24) diff --git a/plone/app/querystring/hiddenprofiles.py b/plone/app/querystring/hiddenprofiles.py index 00a2c3a..53c16da 100644 --- a/plone/app/querystring/hiddenprofiles.py +++ b/plone/app/querystring/hiddenprofiles.py @@ -21,4 +21,6 @@ def getNonInstallableProfiles(self): 'plone.app.querystring:upgrade_to_7', 'plone.app.querystring:upgrade_to_8', 'plone.app.querystring:upgrade_to_9', + 'plone.app.querystring:upgrade_to_10', + 'plone.app.querystring:upgrade_to_11', ] diff --git a/plone/app/querystring/profiles.zcml b/plone/app/querystring/profiles.zcml index d93075d..558d035 100644 --- a/plone/app/querystring/profiles.zcml +++ b/plone/app/querystring/profiles.zcml @@ -73,4 +73,12 @@ provides="Products.GenericSetup.interfaces.EXTENSION" /> + + diff --git a/plone/app/querystring/profiles/default/metadata.xml b/plone/app/querystring/profiles/default/metadata.xml index ecb0990..66c4f1f 100644 --- a/plone/app/querystring/profiles/default/metadata.xml +++ b/plone/app/querystring/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 10 + 11 profile-plone.app.registry:default diff --git a/plone/app/querystring/profiles/default/registry.xml b/plone/app/querystring/profiles/default/registry.xml index d125372..028bc88 100644 --- a/plone/app/querystring/profiles/default/registry.xml +++ b/plone/app/querystring/profiles/default/registry.xml @@ -106,6 +106,22 @@ + + Before relative Date + Before N days in the past + plone.app.querystring.queryparser._beforeRelativeDate + RelativeDateWidget + + + + After relative Date + After N days in the future + plone.app.querystring.queryparser._afterRelativeDate + RelativeDateWidget + + Contains @@ -268,6 +284,8 @@ plone.app.querystring.operation.date.today plone.app.querystring.operation.date.beforeToday plone.app.querystring.operation.date.afterToday + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate Dates @@ -313,6 +331,8 @@ plone.app.querystring.operation.date.today plone.app.querystring.operation.date.beforeToday plone.app.querystring.operation.date.afterToday + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate Dates @@ -343,6 +363,8 @@ plone.app.querystring.operation.date.today plone.app.querystring.operation.date.beforeToday plone.app.querystring.operation.date.afterToday + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate Dates @@ -414,6 +436,8 @@ plone.app.querystring.operation.date.today plone.app.querystring.operation.date.beforeToday plone.app.querystring.operation.date.afterToday + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate Dates @@ -433,6 +457,8 @@ plone.app.querystring.operation.date.today plone.app.querystring.operation.date.beforeToday plone.app.querystring.operation.date.afterToday + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate Dates @@ -516,6 +542,8 @@ plone.app.querystring.operation.date.today plone.app.querystring.operation.date.beforeToday plone.app.querystring.operation.date.afterToday + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate Dates diff --git a/plone/app/querystring/profiles/upgrades/to_11/registry.xml b/plone/app/querystring/profiles/upgrades/to_11/registry.xml new file mode 100644 index 0000000..4f230a0 --- /dev/null +++ b/plone/app/querystring/profiles/upgrades/to_11/registry.xml @@ -0,0 +1,68 @@ + + + + Before relative Date + Before N days in the past + plone.app.querystring.queryparser._beforeRelativeDate + RelativeDateWidget + + + + After relative Date + After N days in the future + plone.app.querystring.queryparser._afterRelativeDate + RelativeDateWidget + + + + + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate + + + + + + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate + + + + + + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate + + + + + + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate + + + + + + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate + + + + + + plone.app.querystring.operation.date.beforeRelativeDate + plone.app.querystring.operation.date.afterRelativeDate + + + + \ No newline at end of file diff --git a/plone/app/querystring/queryparser.py b/plone/app/querystring/queryparser.py index 3a67ed0..a77841c 100644 --- a/plone/app/querystring/queryparser.py +++ b/plone/app/querystring/queryparser.py @@ -248,6 +248,28 @@ def _beforeToday(context, row): return _lessThan(context, row) +def _beforeRelativeDate(context, row): + try: + values = int(row.values) + except ValueError: + values = 0 + row = Row(index=row.index, + operator=row.operator, + values=DateTime().earliestTime() - values) + return _lessThan(context, row) + + +def _afterRelativeDate(context, row): + try: + values = int(row.values) + except ValueError: + values = 0 + row = Row(index=row.index, + operator=row.operator, + values=DateTime().earliestTime() + values) + return _largerThan(context, row) + + def _pathByRoot(root, context, row): values = row.values depth = None diff --git a/plone/app/querystring/tests/testQueryParser.py b/plone/app/querystring/tests/testQueryParser.py index 0773261..8fd0663 100644 --- a/plone/app/querystring/tests/testQueryParser.py +++ b/plone/app/querystring/tests/testQueryParser.py @@ -413,6 +413,32 @@ def test__moreThanRelativeDate(self): parsed = queryparser._moreThanRelativeDate(MockSite(), data) self.assertEqual(parsed, expected) + def test__beforeRelativeDate(self): + days = 365 + now = DateTime() + mydate = now.earliestTime() - days + expected = {'modified': {'query': mydate, 'range': 'max'}} + data = Row( + index='modified', + operator='_beforeRelativeDate', + values=days + ) + parsed = queryparser._beforeRelativeDate(MockSite(), data) + self.assertEqual(parsed, expected) + + def test__afterRelativeDate(self): + days = 2 + now = DateTime() + mydate = now.earliestTime() + days + expected = {'effective': {'query': mydate, 'range': 'min'}} + data = Row( + index='effective', + operator='_afterRelativeDate', + values=days + ) + parsed = queryparser._afterRelativeDate(MockSite(), data) + self.assertEqual(parsed, expected) + def test__today(self): now = DateTime() expected_dates = [now.earliestTime(), now.latestTime()] diff --git a/plone/app/querystring/upgrades.zcml b/plone/app/querystring/upgrades.zcml index ff97324..6eb85bc 100644 --- a/plone/app/querystring/upgrades.zcml +++ b/plone/app/querystring/upgrades.zcml @@ -102,4 +102,14 @@ /> + + + +