Convert python based on zcml script to standalone script in zope / plone

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?

+3
source share
1 answer

You can access views from page templates using the syntax @@: context / @@ viewname:

tal:define="view context/@@get_tags;
            entries view/entries;"
+2
source

Source: https://habr.com/ru/post/1726333/


All Articles