Skip to content

Commit

Permalink
Merge a35e5d1 into bbe5144
Browse files Browse the repository at this point in the history
  • Loading branch information
petschki committed Mar 22, 2019
2 parents bbe5144 + a35e5d1 commit 067b6e4
Show file tree
Hide file tree
Showing 30 changed files with 552 additions and 75 deletions.
13 changes: 13 additions & 0 deletions .coveragerc
@@ -0,0 +1,13 @@
[report]
omit =
/home/*/.buildout/eggs/*
/home/travis/buildout-cache/eggs/*
/home/travis/virtualenv/*
/usr/*
bin/test
eggs/*
parts/*
src/collective/collectionfilter/tests/*
*/lib/*
*.txt
*.rst
2 changes: 0 additions & 2 deletions .gitignore
@@ -1,5 +1,3 @@
*.egg-info
*.pyc
*.mo
.*
!.gitignore
57 changes: 57 additions & 0 deletions .travis.yml
@@ -0,0 +1,57 @@
language: python
sudo: false
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
matrix:
include:
- python: "2.7"
env: PLONE_VERSION=5.1.x
- python: "2.7"
env: PLONE_VERSION=5.2.x
- python: "3.6"
env: PLONE_VERSION=5.2.x
- python: "3.7"
env: PLONE_VERSION=5.2.x
dist: xenial
sudo: true
cache:
pip: true
directories:
- eggs
- downloads
before_install:
# install chrome webdriver
- mkdir webdriver;
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-linux64.tar.gz;
tar -xzf geckodriver-v0.20.0-linux64.tar.gz -C webdriver;
wget https://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip;
unzip chromedriver_linux64.zip -d webdriver;
export PATH=$PATH:$(pwd)/webdriver;
- mkdir -p $HOME/buildout-cache/{eggs,downloads}
- mkdir $HOME/.buildout
- echo "[buildout]" > $HOME/.buildout/default.cfg
- echo "download-cache = $HOME/buildout-cache/downloads" >> $HOME/.buildout/default.cfg
- echo "eggs-directory = $HOME/buildout-cache/eggs" >> $HOME/.buildout/default.cfg
- pip install zc.buildout
- cp test-$PLONE_VERSION.cfg buildout.cfg
install:
- buildout -N annotate
- buildout -N
- pip install zest.pocompile
- pocompile src
before_script:
- 'export DISPLAY=:99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- sleep 3
script:
# Run code-analysis, except on Python 3.6, which mysteriously fails to find zc.buildout.
- python --version 2> /dev/stdout | grep 3.6 || bin/code-analysis
- bin/test --all $TEST_OPTIONS
- bin/createcoverage
after_success:
- pip install -q coveralls
- coveralls
21 changes: 19 additions & 2 deletions CHANGES.rst
@@ -1,10 +1,27 @@
Changelog
=========

2.2 (unreleased)
3.0 (unreleased)
----------------

- Nothing changed yet.
Breaking changes:

- Remove support for Plone < 5.1.
[petschki]

New features:

- Python 3 compatibility.
[petschki]

- Test setup
[petschki]

Bug fixes:

- fix bug in @@render-portlet for Python 3.
NOTE on Python 3: this required plone.app.portlets >= 4.4.2
[petschki]


2.1 (2019-03-22)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -86,7 +86,7 @@ Your adapter is called by ``collective.collectionfilter.vocabularies.GroupByCrit
Compatibility
-------------

This package is compatible with Plone 5 and above. Note that in 5.0 some functionality is reduced such as AJAX loading of search results.
This package is compatible with Plone 5.1 and above.

Author
------
Expand Down
35 changes: 35 additions & 0 deletions buildout.cfg
@@ -0,0 +1,35 @@
[buildout]
extends = test-5.1.x.cfg

parts +=
releaser
i18ndude
omelette


[omelette]
recipe = collective.recipe.omelette
eggs = ${test:eggs}


[releaser]
recipe = zc.recipe.egg
eggs = zest.releaser


[i18ndude]
recipe = zc.recipe.egg
eggs = i18ndude


[sphinxbuilder]
recipe = collective.recipe.sphinxbuilder
source = ${buildout:directory}/docs
eggs =
${instance:eggs}
sphinxcontrib-robotdoc
sphinxcontrib-httpdomain

[versions]
# Don't use a released version of collective.easyforms
collective.collectionfilter =
18 changes: 15 additions & 3 deletions setup.py
Expand Up @@ -2,7 +2,7 @@
from setuptools import find_packages
from setuptools import setup

version = '2.2.dev0'
version = '3.0.dev0'

setup(
name='collective.collectionfilter',
Expand All @@ -14,9 +14,12 @@
),
classifiers=[
"Framework :: Plone",
"Framework :: Plone :: 5.0",
"Framework :: Plone :: 5.1",
"Framework :: Plone :: 5.2",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='plone collection filter faceted tagcloud tags',
Expand All @@ -31,9 +34,18 @@
zip_safe=False,
install_requires=[
'setuptools',
'Products.CMFPlone >= 5.0',
'Products.CMFPlone >= 5.1',
'plone.app.contenttypes',
],
extras_require={
'test': [
'plone.app.testing[robot]',
'plone.app.robotframework',
'plone.app.contenttypes',
'robotframework-selenium2library',
'robotframework-selenium2screenshots',
]
},
entry_points="""
# -*- Entry points: -*-
[z3c.autoinclude.plugin]
Expand Down
3 changes: 0 additions & 3 deletions src/collective/collectionfilter/__init__.py
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from zope.i18nmessageid import MessageFactory
from plone.api import env


_ = MessageFactory('collective.collectionfilter')

PLONE_VERSION = env.plone_version()
17 changes: 3 additions & 14 deletions src/collective/collectionfilter/baseviews.py
@@ -1,22 +1,17 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from Products.CMFPlone.utils import get_top_request
from Products.CMFPlone.utils import safe_unicode
from collective.collectionfilter.filteritems import get_filter_items
from collective.collectionfilter.utils import base_query
from collective.collectionfilter.utils import safe_decode
from collective.collectionfilter.utils import safe_encode
from collective.collectionfilter.vocabularies import TEXT_IDX
from Acquisition import aq_inner
from collective.collectionfilter import PLONE_VERSION
from plone.app.uuid.utils import uuidToCatalogBrain
from plone.i18n.normalizer.interfaces import IIDNormalizer
from Products.CMFPlone.utils import safe_unicode
from six.moves.urllib.parse import urlencode
from zope.component import queryUtility

try:
from Products.CMFPlone.utils import get_top_request
except ImportError:
from collective.collectionfilter.utils import get_top_request


class BaseView(object):
"""Abstract base filter view class.
Expand Down Expand Up @@ -67,12 +62,6 @@ def collection(self):
)
return aq_inner(self._collection)

@property
def patCollectionFilter(self):
if PLONE_VERSION >= '5.1':
return 'pat-collectionfilter'
return ''


class BaseFilterView(BaseView):

Expand Down
25 changes: 16 additions & 9 deletions src/collective/collectionfilter/filteritems.py
Expand Up @@ -16,30 +16,30 @@
from plone.i18n.normalizer import idnormalizer
from plone.memoize import ram
from plone.memoize.volatile import DontCache
from time import time
from six.moves.urllib.parse import urlencode
from zope.component import getUtility
from zope.globalrequest import getRequest
from zope.i18n import translate

import plone.api

import six

try:
from plone.app.event.browser.event_listing import EventListing
except ImportError:
class EventListing(object):
pass


def _results_cachekey(
method,
target_collection,
group_by,
filter_type,
narrow_down,
view_name,
cache_enabled,
request_params):
filter_type=DEFAULT_FILTER_TYPE,
narrow_down=False,
view_name='',
cache_enabled=True,
request_params=None):
if not cache_enabled:
raise DontCache
cachekey = (
Expand Down Expand Up @@ -94,8 +94,15 @@ def get_filter_items(
groupby_criteria = getUtility(IGroupByCriteria).groupby
idx = groupby_criteria[group_by]['index']
current_idx_value = request_params.get(idx)
if not getattr(current_idx_value, '__iter__', False):
current_idx_value = [current_idx_value] if current_idx_value else []
if isinstance(current_idx_value, six.string_types):
# do not expand a string to a list of chars
current_idx_value = [current_idx_value, ]
else:
try:
current_idx_value = list(current_idx_value)
except TypeError:
# int and other stuff
current_idx_value = [current_idx_value, ]

extra_ignores = []
if not narrow_down:
Expand Down
23 changes: 10 additions & 13 deletions src/collective/collectionfilter/interfaces.py
@@ -1,22 +1,11 @@
# -*- coding: utf-8 -*-
from collective.collectionfilter import _
from collective.collectionfilter import PLONE_VERSION
from collective.collectionfilter import utils
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform.directives import widget
from zope import schema
from zope.interface import Interface


def pattern_options():
options = {
'basePath': utils.target_collection_base_path,
'recentlyUsed': True,
# 'selectableTypes': ['Collection'],
}
if PLONE_VERSION < '5.1':
del options['basePath']
return options
from zope.publisher.interfaces.browser import IDefaultBrowserLayer


class ICollectionFilterBaseSchema(Interface):
Expand All @@ -43,7 +32,11 @@ class ICollectionFilterBaseSchema(Interface):
widget(
'target_collection',
RelatedItemsFieldWidget,
pattern_options=pattern_options()
pattern_options={
'basePath': utils.target_collection_base_path,
'recentlyUsed': True,
# 'selectableTypes': ['Collection'],
},
)

view_name = schema.TextLine(
Expand Down Expand Up @@ -178,3 +171,7 @@ class IGroupByModifier(Interface):
"""Adapter interface for modifying the groupby criteria data structure,
after it has been initially created.
"""


class ICollectionFilterBrowserLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""
@@ -1,4 +1,4 @@
<aside class="portlet ${view/filterClassName} collectionFilter ${view/patCollectionFilter}"
<aside class="portlet ${view/filterClassName} collectionFilter pat-collectionfilter"
tal:define="input_type view/input_type"
data-pat-collectionfilter='{
"collectionUUID": "${view/settings/target_collection}",
Expand Down
11 changes: 4 additions & 7 deletions src/collective/collectionfilter/portlets/collectionfilter.py
@@ -1,18 +1,15 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.utils import get_top_request
from Products.CMFPlone.utils import safe_unicode
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from collective.collectionfilter import _
from collective.collectionfilter.baseviews import BaseFilterView
from collective.collectionfilter.interfaces import ICollectionFilterSchema
from collective.collectionfilter.vocabularies import DEFAULT_FILTER_TYPE
from plone.app.portlets.portlets import base
from plone.portlets.interfaces import IPortletDataProvider
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.interface import implementer

try:
from Products.CMFPlone.utils import get_top_request
except ImportError:
from collective.collectionfilter.utils import get_top_request


class ICollectionFilterPortlet(ICollectionFilterSchema, IPortletDataProvider):
"""Portlet interface based on ICollectionFilterSchema
Expand Down Expand Up @@ -90,7 +87,7 @@ def filter_id(self):
def reload_url(self):
reload_url = '{0}/@@render-portlet?portlethash={1}'.format(
self.context.absolute_url(),
self.filter_id
safe_unicode(self.filter_id),
)
return reload_url

Expand Down
@@ -1,4 +1,4 @@
<aside class="portlet ${view/filterClassName} collectionSearch ${view/patCollectionFilter}"
<aside class="portlet ${view/filterClassName} collectionSearch pat-collectionfilter"
data-pat-collectionfilter='{
"collectionUUID": "${view/settings/target_collection}",
"reloadURL": "${view/reload_url}",
Expand Down

0 comments on commit 067b6e4

Please sign in to comment.