Skip to content

Commit

Permalink
Merge 0d7056c into dfacc03
Browse files Browse the repository at this point in the history
  • Loading branch information
gogobd committed Aug 4, 2020
2 parents dfacc03 + 0d7056c commit df7c72e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 32 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,10 @@ Changelog
2.1 (unreleased)
----------------

- Nothing changed yet.
- Patch that allows for using multiple paths, fixing issue https://github.com/plone/plone.app.multilingualindexes/issues/9
[gogobd]
- User PATH_INDICES as suggested by jensens
[gogobd]


2.0 (2019-07-12)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Expand Up @@ -4,3 +4,4 @@ Contributors
- Jens W. Klein, jk@kleinundpartner.at
- Peter Holzer, peter.holzer@agitator.com
- Patrick Gerken, gerken@patrick-gerken.de
- Georg "Gogo" Bernhard
17 changes: 8 additions & 9 deletions base.cfg
@@ -1,12 +1,12 @@
[buildout]
extensions = mr.developer
always-checkout = true
sources-dir = devsrc
extends =
https://raw.githubusercontent.com/plone/buildout.coredev/5.2/sources.cfg
auto-checkout =
archetypes.multilingual
plone.app.multilingual
# extensions = mr.developer
# always-checkout = true
# sources-dir = devsrc
# extends =
# coredev5.cfg
# auto-checkout =
# archetypes.multilingual
# plone.app.multilingual
parts =
instance
test
Expand All @@ -15,7 +15,6 @@ parts =
omelette
develop = .


[instance]
recipe = plone.recipe.zope2instance
user = admin:admin
Expand Down
2 changes: 1 addition & 1 deletion coredev5.cfg
Expand Up @@ -2,6 +2,6 @@
extends =
https://raw.githubusercontent.com/plone/buildout.coredev/5.2/versions.cfg
https://raw.githubusercontent.com/plone/buildout.coredev/5.2/sources.cfg
https://raw.githubusercontent.com/plone/buildout.coredev/5.3/checkouts.cfg
https://raw.githubusercontent.com/plone/buildout.coredev/5.2/checkouts.cfg

sources-dir = devsrc
6 changes: 5 additions & 1 deletion plone-5.2.x.cfg
@@ -1,4 +1,8 @@
[buildout]
extends =
https://dist.plone.org/release/5.2-pending/versions.cfg
https://dist.plone.org/release/5.2.2-pending/versions.cfg
base.cfg

[versions]
# remove if 5.2.2 final was released and used above
plone.app.theming = 4.1.3
12 changes: 8 additions & 4 deletions setup.py
Expand Up @@ -32,22 +32,26 @@
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
keywords="Python Plone",
keywords="Python, Plone, multilingual, translation",
author="Jens W. Klein",
author_email="jk@kleinundpartner.at",
url="https://pypi.python.org/pypi/plone.app.multilingualindexes",
url="https://github.com/plone/plone.app.multilingualindexes",
license="GPL version 2",
packages=find_packages("src"),
namespace_packages=["plone", "plone.app"],
package_dir={"": "src"},
include_package_data=True,
zip_safe=False,
install_requires=["Products.CMFPlone", "setuptools"],
install_requires=[
"setuptools",
"Products.CMFPlone>=5.2.1",
"plone.app.querystring>=1.4.14",
"plone.app.theming>=4.1.3",
],
extras_require={
"test": [
"plone.app.testing",
"plone.app.multilingual[test]",
"plone.app.querystring",
]
},
entry_points="""
Expand Down
3 changes: 3 additions & 0 deletions src/plone/app/multilingualindexes/__init__.py
@@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-
from zope.i18nmessageid import MessageFactory
from plone.app.querystring import queryparser

from . import patches # noqa

_ = MessageFactory("plone.app.multilingualindexes")

queryparser.PATH_INDICES |= {'tgpath'}


def initialize(context):
from plone.app.multilingualindexes.languagefallback import (
Expand Down
1 change: 0 additions & 1 deletion src/plone/app/multilingualindexes/configure.zcml
Expand Up @@ -11,7 +11,6 @@
package="."
/>
<i18n:registerTranslations directory="locales" />
<includeDependencies package="." />
<genericsetup:registerProfile
description="Installs the plone.app.multilingualindexes add-on."
directory="profiles/default"
Expand Down
32 changes: 17 additions & 15 deletions src/plone/app/multilingualindexes/querymodifiers.py
Expand Up @@ -15,16 +15,13 @@
}


def _index_of_criteria(query, name):
for idx, criteria in enumerate(query):
if criteria["i"] == name:
return idx
def _indices_of_criteria(query, name):
return [idx for idx, criteria in enumerate(query) if criteria["i"] == name]


def _remove_criteria_by_index_name(query, name):
remove_idx = _index_of_criteria(query, name)
if remove_idx is not None:
del query[remove_idx]
remove_idxs = _indices_of_criteria(query, name)
return [i for idx, i in enumerate(query) if idx not in remove_idxs]


@provider(IQueryModifier)
Expand Down Expand Up @@ -52,15 +49,19 @@ def modify_query_to_enforce_site_root(query):
if has_path_criteria:
# if we have a path criteria it is replaced here by a tgpath
if has_tgpath_criteria:
_remove_criteria_by_index_name(query, "tgpath")
idx_criteria = _index_of_criteria(query, "path")
new_criteria = dict(query[idx_criteria])
new_criteria["i"] = "tgpath"
if new_criteria["o"] in PATH_MAP:
new_criteria["o"] = PATH_MAP[new_criteria["o"]]
query[idx_criteria] = new_criteria
query = _remove_criteria_by_index_name(query, "tgpath")
# Handle multiple paths
idx_criteria = _indices_of_criteria(query, "path")
new_criteria = [dict(query[i]) for i in idx_criteria]
for i in new_criteria:
i['i'] = 'tgpath'
for i in new_criteria:
if i["o"] in PATH_MAP:
i['o'] = PATH_MAP[i['o']]
for i, x in enumerate(idx_criteria):
query[x] = new_criteria[i]
elif has_tgpath_criteria:
_remove_criteria_by_index_name(query, "tgpath")
query = _remove_criteria_by_index_name(query, "tgpath")

# always set path to the portal root in order to prevent the default query
# modifier to set the path to the navigation root
Expand All @@ -71,4 +72,5 @@ def modify_query_to_enforce_site_root(query):
"v": "/",
}
)

return query

0 comments on commit df7c72e

Please sign in to comment.