Skip to content

Commit c6216d7

Browse files
committed
Fix merging of date operations
1 parent cd24bbd commit c6216d7

9 files changed

Lines changed: 112 additions & 5 deletions

File tree

news/188.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix merging multiple date operations. @davisagli

src/plone/app/querystring/profiles.zcml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,12 @@
9090
directory="profiles/upgrades/to_14"
9191
/>
9292

93+
<genericsetup:registerProfile
94+
name="upgrade_to_15"
95+
title="Querystring Upgrade profile to v15"
96+
description=""
97+
provides="Products.GenericSetup.interfaces.EXTENSION"
98+
directory="profiles/upgrades/to_15"
99+
/>
100+
93101
</configure>

src/plone/app/querystring/profiles/default/metadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<metadata>
3-
<version>14</version>
3+
<version>15</version>
44
<dependencies>
55
<dependency>profile-plone.app.registry:default</dependency>
66
</dependencies>

src/plone/app/querystring/profiles/default/registry.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
i18n:translate=""
6868
>Before date</value>
6969
<value key="description">Please use YYYY/MM/DD.</value>
70-
<value key="operation">plone.app.querystring.queryparser._lessThan</value>
70+
<value key="operation">plone.app.querystring.queryparser._dateLessThan</value>
7171
<value key="widget">DateWidget</value>
7272
</records>
7373

@@ -80,7 +80,7 @@
8080
<value key="description"
8181
i18n:translate=""
8282
>Please use YYYY/MM/DD.</value>
83-
<value key="operation">plone.app.querystring.queryparser._largerThan</value>
83+
<value key="operation">plone.app.querystring.queryparser._dateLargerThan</value>
8484
<value key="widget">DateWidget</value>
8585
</records>
8686

@@ -93,7 +93,7 @@
9393
<value key="description"
9494
i18n:translate=""
9595
>Please use YYYY/MM/DD.</value>
96-
<value key="operation">plone.app.querystring.queryparser._between</value>
96+
<value key="operation">plone.app.querystring.queryparser._dateBetween</value>
9797
<value key="widget">DateRangeWidget</value>
9898
</records>
9999

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
3+
i18n:domain="plone"
4+
>
5+
6+
<records interface="plone.app.querystring.interfaces.IQueryOperation"
7+
prefix="plone.app.querystring.operation.date.lessThan"
8+
>
9+
<value key="operation">plone.app.querystring.queryparser._dateLessThan</value>
10+
</records>
11+
12+
<records interface="plone.app.querystring.interfaces.IQueryOperation"
13+
prefix="plone.app.querystring.operation.date.largerThan"
14+
>
15+
<value key="operation">plone.app.querystring.queryparser._dateLargerThan</value>
16+
</records>
17+
18+
<records interface="plone.app.querystring.interfaces.IQueryOperation"
19+
prefix="plone.app.querystring.operation.date.between"
20+
>
21+
<value key="operation">plone.app.querystring.queryparser._dateBetween</value>
22+
</records>
23+
24+
</registry>

src/plone/app/querystring/queryparser.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ def _between(context, row):
163163
return tmp
164164

165165

166+
def _dateBetween(context, row):
167+
try:
168+
start_date = DateTime(row.values[0])
169+
except DateTimeError:
170+
start_date = DateTime(0)
171+
try:
172+
end_date = DateTime(row.values[1])
173+
except DateTimeError:
174+
end_date = DateTime()
175+
row = Row(index=row.index, operator=row.operator, values=(start_date, end_date))
176+
return _between(context, row)
177+
178+
166179
def _largerThan(context, row):
167180
tmp = {
168181
row.index: {
@@ -186,6 +199,19 @@ def _intLargerThan(context, row):
186199
}
187200

188201

202+
def _dateLargerThan(context, row):
203+
try:
204+
value = DateTime(row.values)
205+
except (DateTimeError, TypeError, AttributeError):
206+
return {}
207+
return {
208+
row.index: {
209+
"query": value,
210+
"range": "min",
211+
},
212+
}
213+
214+
189215
def _lessThan(context, row):
190216
tmp = {
191217
row.index: {
@@ -209,6 +235,19 @@ def _intLessThan(context, row):
209235
}
210236

211237

238+
def _dateLessThan(context, row):
239+
try:
240+
value = DateTime(row.values)
241+
except (DateTimeError, TypeError, AttributeError):
242+
return {}
243+
return {
244+
row.index: {
245+
"query": value,
246+
"range": "max",
247+
},
248+
}
249+
250+
212251
def _currentUser(context, row):
213252
"""Current user lookup"""
214253
mt = getToolByName(context, "portal_membership")

src/plone/app/querystring/tests/testQueryParser.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,30 @@ def test_merge_ranges(self):
289289
parsed = queryparser.parseFormquery(MockSite(), data)
290290
self.assertEqual(parsed, {"modified": {"query": [10, 20], "range": "minmax"}})
291291

292+
def test_merge_date_operations(self):
293+
data = [
294+
{
295+
"i": "start",
296+
"o": "plone.app.querystring.operation.date.afterRelativeDate",
297+
"v": "0",
298+
},
299+
{
300+
"i": "start",
301+
"o": "plone.app.querystring.operation.date.largerThan",
302+
"v": "2026/05/04",
303+
},
304+
]
305+
parsed = queryparser.parseFormquery(MockSite(), data)
306+
self.assertEqual(
307+
parsed,
308+
{
309+
"start": {
310+
"query": [DateTime("2026/05/04"), DateTime().earliestTime()],
311+
"range": "min",
312+
}
313+
},
314+
)
315+
292316

293317
class TestQueryGenerators(TestQueryParserBase):
294318
def test__between(self):

src/plone/app/querystring/tests/testRegistryIntegration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_date_lessthan(self):
3333
self.assertEqual(registry[prefix + ".description"], "Please use YYYY/MM/DD.")
3434
self.assertEqual(
3535
registry[prefix + ".operation"],
36-
"plone.app.querystring.queryparser._lessThan",
36+
"plone.app.querystring.queryparser._dateLessThan",
3737
)
3838

3939

src/plone/app/querystring/upgrades.zcml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,15 @@
159159
/>
160160
</genericsetup:upgradeSteps>
161161

162+
<genericsetup:upgradeSteps
163+
profile="plone.app.querystring:default"
164+
source="14"
165+
destination="15"
166+
>
167+
<genericsetup:upgradeDepends
168+
title="Use date-specific lessThan, largerThan, and between operators."
169+
import_profile="plone.app.querystring:upgrade_to_15"
170+
/>
171+
</genericsetup:upgradeSteps>
172+
162173
</configure>

0 commit comments

Comments
 (0)