How to use the zope.component.queryUtility function in Zope

To help you get started, we’ve selected a few Zope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ggozad / jarn.xmpp.core / jarn / xmpp / core / subscribers / startup.py View on Github external
def setupAdminClient(portal, event):
    client = queryUtility(IAdminClient)
    if client is None:
        settings = getUtility(IRegistry)

        try:
            jid = settings['jarn.xmpp.adminJID']
            jdomain = settings['jarn.xmpp.xmppDomain']
            password = settings['jarn.xmpp.adminPassword']
            pubsub_jid = settings['jarn.xmpp.pubsubJID']
        except KeyError:
            return

        client = AdminClient(jid, jdomain, password, pubsub_jid)
        gsm = getGlobalSiteManager()
        gsm.registerUtility(client, IAdminClient)

        def checkAdminClientConnected():
github plone / Products.CMFPlone / Products / CMFPlone / defaultpage.py View on Github external
else:
                dynamic_fti = queryAdapter(fti, IDynamicViewTypeInformation)
            if dynamic_fti is not None:
                page = dynamic_fti.getDefaultPage(context, check_exists=True)
                if page is not None:
                    return page

    # 3.1 Test for default_page attribute in folder, no acquisition
    pages = getattr(aq_base(context), 'default_page', [])
    if isinstance(pages, six.string_types):
        pages = [pages]
    for page in pages:
        if page and page in ids:
            return page

    portal = queryUtility(ISiteRoot)
    # Might happen during portal creation
    if portal is None:
        return

    # 3.2 Test for default page in portal, acquire
    for page in pages:
        if portal.unrestrictedTraverse(page, None):
            return page

    # 4. Test for default sitewide default_page setting
    registry = getUtility(IRegistry)
    for page in registry.get('plone.default_page', []):
        if page in ids:
            return page
github ploneintranet / ploneintranet / src / ploneintranet / microblog / migration.py View on Github external
def discuss_older_docs(context, do_commit=True):
    """Add document discussion on pre-existing documents.
    This only adds a 'created' message, since we cannot reconstruct
    the publication date and actor.
    """
    if context is not None:
        # Backport ondelete_archive in order not to fail
        # if some documents have been deleted (see quaive/ploneintranet #354)
        ondelete_archive(context)
    logger.info("Adding streams to older content")
    mtool = queryUtility(IMicroblogTool)
    haveseen = [x for x in mtool._content_uuid_mapping.keys()]
    ctool = api.portal.get_tool('portal_catalog')
    i = 0
    for brain in ctool.unrestrictedSearchResults(
            {'portal_type': [
                'Document', 'File', 'Image', 'Event', 'News Item']}):
        if brain.UID in haveseen:
            continue
        created = brain.created
        if isinstance(created, DateTime):
            created = created.asdatetime()
        obj = brain.getObject()
        pi_api.microblog.statusupdate.create(
            content_context=obj,
            action_verb=u'created',
            tags=obj.Subject() or None,
github plone / plone.app.discussion / plone / app / discussion / browser / controlpanel.py View on Github external
def settings(self):
        """Compose a string that contains all registry settings that are
           needed for the discussion control panel.
        """
        registry = queryUtility(IRegistry)
        settings = registry.forInterface(IDiscussionSettings, check=False)
        wftool = getToolByName(self.context, "portal_workflow", None)
        wf = wftool.getChainForPortalType('Discussion Item')
        output = []

        # Globally enabled
        if settings.globally_enabled:
            output.append("globally_enabled")

        # Comment moderation
        if 'one_state_workflow' not in wf and \
        'comment_review_workflow' not in wf:
            output.append("moderation_custom")
        # p.a.discussion > 2.0 only
        #elif settings.moderation_enabled:
        #    output.append("moderation_enabled")
github collective / collective.solr / src / collective / solr / search.py View on Github external
def getManager(self):
        if self.manager is None:
            self.manager = queryUtility(ISolrConnectionManager)
        return self.manager
github plone / Plone / Products / CMFPlone / setuphandlers.py View on Github external
members.setLanguage(language)
        members.reindexObject()

        if wftool.getInfoFor(members, 'review_state') != 'published':
            wftool.doActionFor(members, 'publish')

        # add index_html to Members area
        if 'index_html' not in members.objectIds():
            addPy = members.manage_addProduct['PythonScripts'].manage_addPythonScript
            addPy('index_html')
            index_html = getattr(members, 'index_html')
            index_html.write(member_indexhtml)
            index_html.ZPythonScript_setTitle('User Search')

        # Block all right column portlets by default
        manager = queryUtility(IPortletManager, name='plone.rightcolumn')
        if manager is not None:
            assignable = queryMultiAdapter((members, manager), ILocalPortletAssignmentManager)
            assignable.setBlacklistStatus('context', True)
            assignable.setBlacklistStatus('group', True)
            assignable.setBlacklistStatus('content_type', True)
github plone / plone.schemaeditor / plone / schemaeditor / browser / schema / listing.py View on Github external
def protected_field(self, field):
        field_identifier = u'{0}.{1}'.format(
            field.__module__,
            field.__class__.__name__,
        )
        field_factory = queryUtility(IFieldFactory, name=field_identifier)
        return field_factory and field_factory.protected(field)
github plomino / Plomino / Products / CMFPlomino / PlominoField.py View on Github external
def getSettings(self, key=None):
        """
        """
        fieldclass = component.queryUtility(interfaces.IPlominoField, self.FieldType, None)
        if fieldclass is None:
            if hasattr(fields, self.FieldType.lower()):
                fieldinterface = getattr(getattr(fields, self.FieldType.lower()), "I"+self.FieldType.capitalize()+"Field")
            else:
                fieldinterface = getattr(getattr(fields, "base"), "IBaseField")
        else:
            fieldinterface = fieldclass.plomino_field_parameters['interface']

        if key is None:
            return fieldinterface(self)
        else:
            return getattr(fieldinterface(self), key, None)
github senaite / senaite.core / bika / lims / databasesanitize / controller_view.py View on Github external
def __call__(self):
        """
        Returns the number of tasks in the sanitation-tasks queue
        """
        try:
            PostOnly(self.context.REQUEST)
        except:
            logger.error(traceback.format_exc())
            return json.dumps({'count': 0})
        try:
            CheckAuthenticator(self.request.form)
        except:
            logger.error(traceback.format_exc())
            return json.dumps({'count': 0})
        task_queue = queryUtility(ITaskQueue, name='sanitation-tasks')
        count = len(task_queue) if task_queue is not None else 0
        return json.dumps({'count': count})
github plomino / Plomino / Products / CMFPlomino / __init__.py View on Github external
def get_resource_directory():
    """Obtain the Plomino persistent resource directory, creating it if
    necessary.
    """
    persistentDirectory = queryUtility(IResourceDirectory, name="persistent")
    if not persistentDirectory:
        return None
    if PLOMINO_RESOURCE_NAME not in persistentDirectory:
        persistentDirectory.makeDirectory(PLOMINO_RESOURCE_NAME)

    return persistentDirectory[PLOMINO_RESOURCE_NAME]