我有一个以 zope 3 zcml 方式工作的 python 类,但我想将 python 移动到一个独立的脚本中,a 可以通过 tal:content='context/get_tags' 的方式访问该脚本。这是目前的代码:
class TagListView(BrowserView):
def getCategories(self):
categories = set()
for cat in self.portal_catalog.uniqueValuesFor('Subject'):
categories.add(cat.lower())
for cat in self.__mapping:
categories.add(cat.lower())
return tuple(sorted(categories))
def getSynonyms(self,category):
r = self.__mapping.get(category)
if r is None:
return ()
return r[0]
def __init__(self,context,request):
self.context = context
self.request = request
self.tool = self.context.portal_categories
def entries(self):
taglist = '(['
for category in self.tool.getCategories():
taglist = taglist + '\'' + category + '\','
for synonym in self.tool.getSynonyms(category):
if len(synonym) > 0:
taglist = taglist + '\'' + synonym + '\','
taglist = taglist + '])'
return taglist
不是很好(你可能已经猜到程序员不是我的职位),但这是我所拥有的。如何将其转换为独立脚本?