我有一个以zope 3 zcml方式工作的python类,但是我想将python移动到一个独立的脚本中,可以通过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
不太好(因为你可能已经猜到程序员不是我的职位)但是这就是我所拥有的。如何将其转换为独立脚本?
答案 0 :(得分:2)
您可以使用@@ syntax:context / @@ viewname:
从页面模板访问视图tal:define="view context/@@get_tags;
entries view/entries;"