Skip to content

Commit

Permalink
Merge 484904d into dfacc03
Browse files Browse the repository at this point in the history
  • Loading branch information
gogobd committed Jul 3, 2020
2 parents dfacc03 + 484904d commit d5192dd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,8 @@ 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]


2.0 (2019-07-12)
Expand Down
2 changes: 1 addition & 1 deletion plone-5.2.x.cfg
@@ -1,4 +1,4 @@
[buildout]
extends =
https://dist.plone.org/release/5.2-pending/versions.cfg
https://dist.plone.org/release/5.2/versions.cfg
base.cfg
2 changes: 1 addition & 1 deletion requirements-5.2.x.txt
@@ -1 +1 @@
-r https://dist.plone.org/release/5.2.2-pending/requirements.txt
-r https://dist.plone.org/release/5.2/requirements.txt
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 d5192dd

Please sign in to comment.