def _filterCore(self, chunk, **kwargs): pc = self.context.portal_catalog brains = pc(Title=chunk) # lets only handle unique matches if brains and len(brains) == 1: url = brains[0].getURL() # build a context and render a macro for the link # (again, to keep things flexible) data = { 'url' : url, 'anchor' : chunk, } econtext = createContext(self.context, **data) # reuse some of the macro code to render the "wikilink" macro # and insert a stylized link into the output template = self.context.restrictedTraverse(path=kwargs.get('template')) if template: macro = template.macros['wikilink'] return macro_render(macro, self.context, econtext) return chunk
def _macro_renderer(self, macro, template=None, **kw): """render approved macros""" try: if not template: view = _getViewFor(self.context) macro = view.macros[macro] else: template = self.context.restrictedTraverse(path=template) macro = template.macros[macro] except ConflictError: raise except: import traceback traceback.print_exc() return '' econtext = createContext(self.context, **kw) return macro_render(macro, self.context, econtext, **kw)
def filter(self, text, **kwargs): page = kwargs.get('page') if not page: page = self.context.REQUEST.get('page', 1) page = int(page) if page == 0: page = 1 # non-geek counting pages = self.chunkpage(text, limit=int(kwargs.get('limit', self.SIZE_LIMIT))) # if we couldn't parse it or they indicated they want everything if not pages or page == -1: # we couldn't do anything? return text page -= 1 if page > len(pages) or page < 0: page = 0 p = pages[page] # we should now have the relevant page text, but we want to # include some additional information in the output that can # be used to page among these things if kwargs.get('template'): data = { 'pages' : len(pages), 'current' : page + 1, 'prev' : max(page, 1), 'next' : min(page + 2, len(pages)), } econtext = createContext(self.context, **data) # reuse some of the macro code to render the "pages" macro # and insert a pager into the resultant text template = self.context.restrictedTraverse(path=kwargs.get('template')) if template: macro = template.macros['pages'] text = macro_render(macro, self.context, econtext) p = p + text return p