Author: jmorliaguet Date: Sun Oct 30 11:48:26 2005 New Revision: 28815 Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py Log:
- some cleanup Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py ============================================================================== --- z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py (original) +++ z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py Sun Oct 30 11:48:26 2005 @@ -120,13 +120,13 @@ return '<Renderer context info at %s>' % hex(id(self)) class Viewer(BrowserView): - """An element viewer provides a view of an element in two steps: + """An element viewer provides a view of an element which is displayed + in two phases: - a) by creating the tree structure + 1) by creating a tree structure that starts from the element and by + updating all the tree nodes recusively. - b) by updating the entire tree - - c) by rendering the subtree starting from the element's node + 2) by rendering the tree """ adapts(IElement, IRequest) @@ -174,8 +174,6 @@ # if the object is inside a slot, get the parent's display. # TODO this should be moved somewhere else - - perspective = globals.perspective display = IDisplayable(node).getEffectiveDisplay(perspective) if display is None: @@ -208,11 +206,6 @@ return index -class PageTemplateFilter(object): - - def __init__(self): - pass - class Renderer(object): """A renderer is a collection of filters. It provides some rendering for elements. @@ -237,12 +230,11 @@ info = tree_element['info'] engine = info.globals.engine - rendered = [] + markup = '' if ILeaf.providedBy(element): - # do the actual rendering - portlet_markup = element(info) or '' - rendered.append(portlet_markup) + markup = element(info) or '' else: + rendered = [] for node in tree_element['children']: if not INode.providedBy(node): logger.log(INFO, @@ -250,7 +242,7 @@ continue renderer = getMultiAdapter((node, request), IRenderer) rendered.append(renderer()) - markup = ''.join(rendered) + markup = ''.join(rendered) # look for renderers associated to the element's content type iface = IType(element).getContentType() @@ -264,16 +256,14 @@ % (repr(element), engine)) return markup - display = info['display'] - # apply all filters - for f in self._getFilters(iface, display, engine): + # apply all the filters in sequence + for f in self._getFilters(iface, info.display, engine): markup = f(markup, info) - # Filter output return markup def _getFilters(self, iface, display, engine): - """Get the list of filters + """Get the list of filters associated to the element """ element, request = self.element, self.request @@ -285,21 +275,21 @@ filters = [] for filter_name in renderer_registry.get((iface, engine), []): - filter_id = filter_registry.get(filter_name) - if filter_id is None: + filter_proxy = filter_registry.get(filter_name) + if filter_proxy is None: logger.log(INFO, "Filter '%s' is not registered." % filter_name) continue # the filter id is a dyadic predicate - if IPredicate.providedBy(filter_id): - if len(filter_id) != 2: + if IPredicate.providedBy(filter_proxy): + if len(filter_proxy) != 2: logger.log(INFO, "Filter '%s' will not be applied. " "Filter predicates of arity %s are not supported." - % (filter_id, len(filter_id)) + % (filter_proxy, len(filter_proxy)) ) continue - res = relations.search(predicate=filter_id, first=display) + res = relations.search(predicate=filter_proxy, first=display) if not res: continue adapted = relations[res[0]].second @@ -318,21 +308,23 @@ % (filter_name, repr(adapted))) continue - # the filter id is a factory - elif IFilter.providedBy(filter_id): - filter = filter_id() - - # the filter id is a page template applied to the rendered element - elif isinstance(filter_id, ViewPageTemplateFile): + # the filter proxy stands for a factory + elif IFilter.providedBy(filter_proxy): + filter = filter_proxy() + + # the filter proxy is a page template to apply to the element + # that is being rendered. + elif isinstance(filter_proxy, ViewPageTemplateFile): filter = ZPTViewFilter(element, request) - filter.setTemplate(filter_id) + filter.setTemplate(filter_proxy) filters.append(filter) return filters class ZPTViewFilter(BrowserView): - + """A filter view that renders a zope page template. + """ def __init__(self, context, request): self.context = context self.request = request -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins