Skip to content

Commit

Permalink
Merge pull request #46 from plone/issue_45
Browse files Browse the repository at this point in the history
add before/after relative date query
  • Loading branch information
gforcada committed Sep 19, 2015
2 parents 1e84811 + 7854816 commit e0e14d2
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.3.8 (unreleased)
------------------

- Add "before/after N days" functionality
[petschki]

- Fixed Sortable Indexes to not return ZCTextIndex type indexes.
[winstonf88]

Expand Down
2 changes: 2 additions & 0 deletions plone/app/querystring/hiddenprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
8 changes: 8 additions & 0 deletions plone/app/querystring/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:registerProfile
name="upgrade_to_11"
title="Querystring Upgrade profile to v11"
description=""
directory="profiles/upgrades/to_11"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

</configure>
2 changes: 1 addition & 1 deletion plone/app/querystring/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>10</version>
<version>11</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
Expand Down
28 changes: 28 additions & 0 deletions plone/app/querystring/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@
<value key="widget"></value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.date.beforeRelativeDate">
<value key="title" i18n:translate="">Before relative Date</value>
<value key="description" i18n:translate="">Before N days in the past</value>
<value key="operation">plone.app.querystring.queryparser._beforeRelativeDate</value>
<value key="widget">RelativeDateWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.date.afterRelativeDate">
<value key="title" i18n:translate="">After relative Date</value>
<value key="description" i18n:translate="">After N days in the future</value>
<value key="operation">plone.app.querystring.queryparser._afterRelativeDate</value>
<value key="widget">RelativeDateWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.list.contains">
<value key="title" i18n:translate="">Contains</value>
Expand Down Expand Up @@ -268,6 +284,8 @@
<element>plone.app.querystring.operation.date.today</element>
<element>plone.app.querystring.operation.date.beforeToday</element>
<element>plone.app.querystring.operation.date.afterToday</element>
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
<value key="group" i18n:translate="">Dates</value>
</records>
Expand Down Expand Up @@ -313,6 +331,8 @@
<element>plone.app.querystring.operation.date.today</element>
<element>plone.app.querystring.operation.date.beforeToday</element>
<element>plone.app.querystring.operation.date.afterToday</element>
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
<value key="group" i18n:translate="">Dates</value>
</records>
Expand Down Expand Up @@ -343,6 +363,8 @@
<element>plone.app.querystring.operation.date.today</element>
<element>plone.app.querystring.operation.date.beforeToday</element>
<element>plone.app.querystring.operation.date.afterToday</element>
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
<value key="group" i18n:translate="">Dates</value>
</records>
Expand Down Expand Up @@ -414,6 +436,8 @@
<element>plone.app.querystring.operation.date.today</element>
<element>plone.app.querystring.operation.date.beforeToday</element>
<element>plone.app.querystring.operation.date.afterToday</element>
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
<value key="group" i18n:translate="">Dates</value>
</records>
Expand All @@ -433,6 +457,8 @@
<element>plone.app.querystring.operation.date.today</element>
<element>plone.app.querystring.operation.date.beforeToday</element>
<element>plone.app.querystring.operation.date.afterToday</element>
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
<value key="group" i18n:translate="">Dates</value>
</records>
Expand Down Expand Up @@ -516,6 +542,8 @@
<element>plone.app.querystring.operation.date.today</element>
<element>plone.app.querystring.operation.date.beforeToday</element>
<element>plone.app.querystring.operation.date.afterToday</element>
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
<value key="group" i18n:translate="">Dates</value>
</records>
Expand Down
68 changes: 68 additions & 0 deletions plone/app/querystring/profiles/upgrades/to_11/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone">

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.date.beforeRelativeDate">
<value key="title" i18n:translate="">Before relative Date</value>
<value key="description" i18n:translate="">Before N days in the past</value>
<value key="operation">plone.app.querystring.queryparser._beforeRelativeDate</value>
<value key="widget">RelativeDateWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.date.afterRelativeDate">
<value key="title" i18n:translate="">After relative Date</value>
<value key="description" i18n:translate="">After N days in the future</value>
<value key="operation">plone.app.querystring.queryparser._afterRelativeDate</value>
<value key="widget">RelativeDateWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.created">
<value key="operations" purge="false">
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.modified">
<value key="operations" purge="false">
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.start">
<value key="operations" purge="false">
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.end">
<value key="operations" purge="false">
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.effective">
<value key="operations" purge="false">
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.expires">
<value key="operations" purge="false">
<element>plone.app.querystring.operation.date.beforeRelativeDate</element>
<element>plone.app.querystring.operation.date.afterRelativeDate</element>
</value>
</records>

</registry>
22 changes: 22 additions & 0 deletions plone/app/querystring/queryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions plone/app/querystring/tests/testQueryParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
10 changes: 10 additions & 0 deletions plone/app/querystring/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
source="10"
destination="11"
profile="plone.app.querystring:default">
<genericsetup:upgradeDepends
title="Add new 'before/after relative Date' operation"
import_profile="plone.app.querystring:upgrade_to_11"
/>
</genericsetup:upgradeSteps>

</configure>

0 comments on commit e0e14d2

Please sign in to comment.