Skip to content

Commit

Permalink
Issue 32 changes to 1.2.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Apr 27, 2015
1 parent 777da1f commit 704ea80
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
1.2.4 (unreleased)
------------------

- Nothing changed yet.
- Fix collection not filtering integer field (closes `#32`_).
[rodfersou]


1.2.3 (2014-10-20)
Expand Down Expand Up @@ -183,3 +184,5 @@ Changelog
----------------

* Initial release

.. _`#32`: https://github.com/plone/plone.app.querystring/issues/32
8 changes: 8 additions & 0 deletions plone/app/querystring/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:registerProfile
name="upgrade_to_5"
title="Querystring Upgrade profile to v5"
description=""
directory="profiles/upgrades/to_5"
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>4</version>
<version>5</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
Expand Down
14 changes: 11 additions & 3 deletions plone/app/querystring/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
prefix="plone.app.querystring.operation.int.is">
<value key="title" i18n:translate="">Equals</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._equal</value>
<value key="operation">plone.app.querystring.queryparser._intEqual</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.int.lessThan">
<value key="title" i18n:translate="">Less than</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._lessThan</value>
<value key="operation">plone.app.querystring.queryparser._intLessThan</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.int.largerThan">
<value key="title" i18n:translate="">Larger than</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._largerThan</value>
<value key="operation">plone.app.querystring.queryparser._intLargerThan</value>
<value key="widget">StringWidget</value>
</records>

Expand Down Expand Up @@ -178,6 +178,14 @@
<value key="widget">MultipleSelectionWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.intselection.is">
<value key="title" i18n:translate="">Is</value>
<value key="description" i18n:translate="">Tip: you can use * to autocomplete.</value>
<value key="operation">plone.app.querystring.queryparser._intEqual</value>
<value key="widget">MultipleSelectionWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.string.path">
<value key="title" i18n:translate="">Absolute path</value>
Expand Down
36 changes: 36 additions & 0 deletions plone/app/querystring/profiles/upgrades/to_5/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone">

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.int.is">
<value key="title" i18n:translate="">Equals</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._intEqual</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.int.lessThan">
<value key="title" i18n:translate="">Less than</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._intLessThan</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.int.largerThan">
<value key="title" i18n:translate="">Larger than</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._intLargerThan</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.intselection.is">
<value key="title" i18n:translate="">Is</value>
<value key="description" i18n:translate="">Tip: you can use * to autocomplete.</value>
<value key="operation">plone.app.querystring.queryparser._intEqual</value>
<value key="widget">MultipleSelectionWidget</value>
</records>

</registry>
35 changes: 35 additions & 0 deletions plone/app/querystring/queryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ def _equal(context, row):
return {row.index: {'query': row.values, }}


def _intEqual(context, row):
values = None
if type(row.values) is list:
values = [int(v) for v in row.values]
elif type(row.values) is str:
values = int(row.values)
return {row.index: {'query': values, }}


def _isTrue(context, row):
return {row.index: {'query': True, }}

Expand Down Expand Up @@ -92,6 +101,19 @@ def _largerThan(context, row):
return tmp


def _intLargerThan(context, row):
value = None
if type(row.values) is str:
value = int(row.values)
tmp = {row.index:
{
'query': value,
'range': 'min',
},
}
return tmp


def _lessThan(context, row):
tmp = {row.index:
{
Expand All @@ -102,6 +124,19 @@ def _lessThan(context, row):
return tmp


def _intLessThan(context, row):
value = None
if type(row.values) is str:
value = int(row.values)
tmp = {row.index:
{
'query': value,
'range': 'max',
},
}
return tmp


def _currentUser(context, row):
"""Current user lookup"""
mt = getToolByName(context, 'portal_membership')
Expand Down
66 changes: 62 additions & 4 deletions plone/app/querystring/tests/testQueryParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,42 @@ def test__between_reversed_dates(self):
'range': 'minmax'}}
self.assertEqual(parsed, expected)

def test__largerThan(self):
def test__equal(self):
data = Row(
index='modified',
operator='_largerThan',
operator='_equal',
values='2010/03/18'
)
parsed = queryparser._largerThan(MockSite(), data)
expected = {'modified': {'query': '2010/03/18', 'range': 'min'}}
parsed = queryparser._equal(MockSite(), data)
expected = {'modified': {'query': '2010/03/18'}}
self.assertEqual(parsed, expected)

data = Row(
index='modified',
operator='_equal',
values=['2010/03/18', '2010/03/19']
)
parsed = queryparser._equal(MockSite(), data)
expected = {'modified': {'query': ['2010/03/18', '2010/03/19']}}
self.assertEqual(parsed, expected)

def test__intEqual(self):
data = Row(
index='modified',
operator='_intEqual',
values='20'
)
parsed = queryparser._intEqual(MockSite(), data)
expected = {'modified': {'query': 20}}
self.assertEqual(parsed, expected)

data = Row(
index='modified',
operator='_intEqual',
values=['20', '21']
)
parsed = queryparser._intEqual(MockSite(), data)
expected = {'modified': {'query': [20, 21]}}
self.assertEqual(parsed, expected)

def test__lessThan(self):
Expand All @@ -260,6 +288,36 @@ def test__lessThan(self):
expected = {'modified': {'query': '2010/03/18', 'range': 'max'}}
self.assertEqual(parsed, expected)

def test__intLessThan(self):
data = Row(
index='modified',
operator='_intLessThan',
values='20'
)
parsed = queryparser._intLessThan(MockSite(), data)
expected = {'modified': {'query': 20, 'range': 'max'}}
self.assertEqual(parsed, expected)

def test__largerThan(self):
data = Row(
index='modified',
operator='_largerThan',
values='2010/03/18'
)
parsed = queryparser._largerThan(MockSite(), data)
expected = {'modified': {'query': '2010/03/18', 'range': 'min'}}
self.assertEqual(parsed, expected)

def test__intLargerThan(self):
data = Row(
index='modified',
operator='_intLargerThan',
values='20'
)
parsed = queryparser._intLargerThan(MockSite(), data)
expected = {'modified': {'query': 20, 'range': 'min'}}
self.assertEqual(parsed, expected)

def test__currentUser(self):
# Anonymous user
u = MockUser()
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 @@ -31,4 +31,14 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
source="4"
destination="5"
profile="plone.app.querystring:default">
<genericsetup:upgradeDepends
title="Fix int operators"
import_profile="plone.app.querystring:upgrade_to_5"
/>
</genericsetup:upgradeSteps>

</configure>

0 comments on commit 704ea80

Please sign in to comment.