I have a python class working in zope 3 zcml, but I want to move python to a stand-alone script that could access through something along the lines: content = 'context / get_tags'. This is the code in its current form:
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
Incredible (as you might have guessed that the programmer is not my name), but this is what I have. How to convert it to a standalone script?
source
share