Ejemplo n.º 1
0
def query_view_layout(view, interface=ILayout, name=""):
    """Returns a layout associated to the view's request and context.
    """
    assert IView.providedBy(view)
    assert interface.isOrExtends(ILayout)
    return queryMultiAdapter(
        (view.request, view.context), interface, name=name)
Ejemplo n.º 2
0
    def __call__(self, request, obj, stack):
        """Resolves a view.
        """
        default_fallback = False
        unconsumed_amount = len(stack)
        if unconsumed_amount == 0:
            default_fallback = True
            ns, name = VIEW, self.default_name
        elif unconsumed_amount == 1:
            ns, name = stack[0]
        else:
            raise ResolveError(
                "Can't resolve view: stack is not fully consumed.")

        if ns not in (DEFAULT, VIEW):
            raise ResolveError(
                "Can't resolve view: namespace %r is not supported." % ns)

        # If this is the last node AND if it's a view, we return it.
        if default_fallback and IView.providedBy(obj):
            return obj

        # Else, we need to resolve the model into a view.
        view = self.lookup(request, obj, name)
        if view is None:
            if default_fallback:
                raise ResolveError(
                    "Can't resolve view: no default view on %r." % obj)
            else:
                if ns == VIEW:
                    raise ResolveError(
                        "Can't resolve view: no view `%s` on %r." % (name, obj))
                raise ResolveError(
                    "%r is neither a view nor a model." % name)
        return view
Ejemplo n.º 3
0
def query_view_template(view, interface=ITemplate, name=""):
    """Returns a template associated to a view, or None.
    """
    assert IView.providedBy(view)
    assert interface.isOrExtends(ITemplate)
    return queryMultiAdapter(
        (view, view.request), interface, name=name)
Ejemplo n.º 4
0
    def update(self):
        #tabs = ITab.all_components(self.context, self.request)
        tabs=IView.all_components(self.context, self.request)
        predict, _ = getSecurityGuards()
        if predict is not None:
            tabs = (
                (name, tab) for name, tab in tabs
                if predict(tab, swallow_errors=True) is not None)

        self._tabs = sort_components(tabs, key=sort_key)
        self.available = len(self._tabs) > 0
Ejemplo n.º 5
0
def query_viewlet_manager(view, context=None, request=None,
                          interface=IViewletManager, name=''):
    """Retrieve a viewlet manager"""
    assert IView.providedBy(view), "view must implements IView"
    if context is None:
        context = view.context
    if request is None:
        request = view.request
    assert interface.isOrExtends(IViewletManager), (
        "interface must extends IViewletManager")
    assert IRequest.providedBy(request), "request must be an IRequest"
    return getMultiAdapter((context, request, view), interface, name)
Ejemplo n.º 6
0
 def get_tabs(self, view=None):
     tabs = []
     base_url = get_absolute_url(self.context, self.request)
     if view is not None:
         current = (crom.name.get(view), view.__class__)
     for name, klass in sort_components(
             IView.all_components(self.context, self.request), key=sorter):
         tabs.append({
             'id': name,
             'title': title.get(klass) or name,
             'selected': current == (name, klass),
             'url': '%s/%s' % (base_url, name),
             })
     if len(tabs) == 1 and tabs[0]['selected']:
         return []
     return tabs
Ejemplo n.º 7
0
def query_viewlet_manager(view, context=None, request=None,
                          interface=IViewletManager, name=''):
    """Retrieve a viewlet manager"""
    assert IView.providedBy(view), "view must implements IView"
    if context is None:
        context = view.context
    if request is None:
        request = view.request
    assert interface.isOrExtends(IViewletManager), (
        "interface must extends IViewletManager")
    assert IRequest.providedBy(request), "request must be an IRequest"

    security_predict, security_check = getSecurityGuards()
    try:
        factory = interface.component(context, request, view, name=name)
        if factory is not None and security_predict is not None:
            factory = security_predict(factory)  # raises if security error
            manager = factory(context, request, view)
            if security_check is not None:
                manager = security_check(manager)  # raises if security error
    except ComponentLookupError:
        pass
    else:
        return manager