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/tests/test_zcatalog.py
modified:   src/Products/ZCatalog/zpt/catalogIndexes.zpt
  • Loading branch information
jugmac00 committed Nov 14, 2019
1 parent 456582e commit 3f8464f
Show file tree
Hide file tree
Showing 3 changed files with 18 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
6 changes: 6 additions & 0 deletions src/Products/ZCatalog/tests/test_zcatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ def testAddIndex(self):
self._catalog.addIndex('id', self._makeOneIndex('id'))
self.assertIn('id', self._catalog.indexes())

def testAvailableIndexes(self):
# work in progress
self._catalog.addIndex('title', self._makeOneIndex('title'))
# availableIndexes currently returns an empty list
sorted_indexes = self._catalog.availableIndexes()

def testDelIndex(self):
self._catalog.addIndex('title', self._makeOneIndex('title'))
self.assertTrue('title', self._catalog.indexes())
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 3f8464f

Please sign in to comment.