Beispiel #1
0
 def __call__(self, context, path=''):
     builder = getUtility(IContextBuilder)
     obj = builder(context, path)
     if IContainer.providedBy(obj):
         return IServiceContainer(obj)
     else:
         return IService(obj)
Beispiel #2
0
 def iterAll(self, container) :
     from zope.container.interfaces import IContainer
     for value in container.values() :
         yield value
         if IContainer.providedBy(value) :
             for obj in self.iterAll(value) :
                 yield obj
Beispiel #3
0
    def update(self):
        main_css.need()
        main_js.need()

        site = grok.getSite()
        self.base = absoluteURL(site, self.request)
        if IContainer.providedBy(self.context) and self.base[:-1] != '/':
            self.base = self.base + '/'
def is_or_contains_any_checked_out_document(obj):
    if IBaseDocument.providedBy(obj):
        return obj.is_checked_out()
    if not IContainer.providedBy(obj):
        return False
    catalog = api.portal.get_tool("portal_catalog")
    results = catalog(path=obj.absolute_url_path(),
                      portal_type="opengever.document.document")
    return any(brain.checked_out for brain in results)
Beispiel #5
0
 def sublocations(self):
     """See `zope.location.interfaces.ISublocations` interface"""
     context = self.context
     # Check for adapted sub-locations first...
     registry = get_current_registry()
     for name, adapter in registry.getAdapters((context, ), ISublocations):
         if not name:  # don't reuse default adapter!!
             continue
         yield from adapter.sublocations()
     # then yield container items
     if IContainer.providedBy(context):
         yield from context.values()
Beispiel #6
0
def subscribe_in_site_manager(site_manager,
                              subscription_kwargs,
                              utility_name=DEFAULT_UTILITY_NAME):
    """
    Produce and return a persistent ``IWebhookSubscription`` in the
    given site manager.

    The *subscription_kwargs* are as for
    :meth:`nti.webhooks.interfaces.IWebhookSubscriptionManager.createSubscription`.
    No defaults are applied here.

    The *utility_name* can be used to namespace subscriptions.
    It must never be empty.
    """
    if IContainer.providedBy(site_manager):
        # The preferred location for utilities is in the 'default'
        # child: A SiteManagementFolder. But not every site manager
        # is guaranteed to have one of those, sadly.
        # The best way to get there, dealing with unicode, etc, is through
        # traversal.
        try:
            parent = ztapi.traverse(site_manager, 'default')
        except LocationError:
            parent = site_manager
        sub_manager = parent.get(utility_name)  # pylint:disable=no-member
        if sub_manager is None:
            sub_manager = parent[
                utility_name] = PersistentWebhookSubscriptionManager()
            site_manager.registerUtility(
                sub_manager,
                IWebhookSubscriptionManager,
                name=utility_name
                if utility_name != DEFAULT_UTILITY_NAME else '')
    else:
        # Perhaps we should fail?
        sub_manager = site_manager.getUtility(IWebhookSubscriptionManager)

    subscription = sub_manager.createSubscription(**subscription_kwargs)
    return subscription
Beispiel #7
0
    def execute(self, factory, config, infos, **kw):
        if not infos:
            return False

        infos = infos.values()
        for info in infos:
            if info.public and not IContainer.implementedBy(factory):
                raise GrokError(
                    "Cannot set public to True with grok.local_utility as "
                    "the site (%r) is not a container." % factory, factory)

        # Store the list of info objects in their "natural" order on the
        # site class. They will be picked up by a subscriber doing the
        # actual registrations in definition order.
        factory.__grok_utilities_to_install__ = sorted(infos)
        adapts = (factory, IObjectAddedEvent)

        config.action(
            discriminator=None,
            callable=grokcore.component.provideHandler,
            args=(localUtilityRegistrationSubscriber, adapts),
        )
        return True
Beispiel #8
0
    def execute(self, factory, config, infos, install_on, **kw):
        if not infos:
            return False

        infos = infos.values()
        for info in infos:
            if info.public and not IContainer.implementedBy(factory):
                raise GrokError(
                    "Cannot set public to True with grok.local_utility as "
                    "the site (%r) is not a container." %
                    factory, factory)

        # Store the list of info objects in their "natural" order on the
        # site class. They will be picked up by a subscriber doing the
        # actual registrations in definition order.
        factory.__grok_utilities_to_install__ = sorted(infos)
        adapts = (factory, install_on)

        config.action(
            discriminator=None,
            callable=grokcore.component.provideHandler,
            args=(localUtilityRegistrationSubscriber, adapts),
            )
        return True
Beispiel #9
0
 def update(self):
     self.base = absoluteURL(self.context, self.request)
     if IContainer.providedBy(self.context) and self.base[:-1] != '/':
         self.base = self.base + '/'
Beispiel #10
0
 def update(self):
     self.base = absoluteURL(self.context, self.request)
     if IContainer.providedBy(self.context) and self.base[:-1] != '/':
         self.base = self.base + '/'