Skip to content

Commit

Permalink
Extract logic from template.
Browse files Browse the repository at this point in the history
Instead of looking up available indexes in the template and sorting
them, now there is a method in ZCatalog.

modified:   src/Products/ZCatalog/ZCatalog.py
modified:   src/Products/ZCatalog/zpt/catalogIndexes.zpt
  • Loading branch information
jugmac00 committed Jan 8, 2020
1 parent e751eff commit 8b99ccd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Products/ZCatalog/ZCatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,17 @@ def addIndex(self, name, type, extra=None):

self._catalog.addIndex(name, index)

@security.protected(manage_zcatalog_indexes)
def availableIndexes(self):
"""Return a sorted list of indexes.
Only indexes get returned for which the user has adequate
permission to add them.
"""
return sorted(
self.Indexes.filtered_meta_types(),
key=lambda meta_types: meta_types['name'])

@security.protected(manage_zcatalog_indexes)
def delIndex(self, name):
self._catalog.delIndex(name)
Expand Down
2 changes: 1 addition & 1 deletion src/Products/ZCatalog/zpt/catalogIndexes.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
added index. You may want to update the whole Catalog.
</p>
<tal:indexes define="indexes context/Indexes">
<tal:add define="filtered_meta_types python:sorted(indexes.filtered_meta_types(), key=lambda mt: mt['name'])">
<tal:add define="filtered_meta_types context/availableIndexes">
<form tal:attributes="action context/absolute_url" method="get">
<div class="form-group mt-4 mb-4">
<div class="input-group">
Expand Down

0 comments on commit 8b99ccd

Please sign in to comment.