当前位置: 首页>>代码示例>>Python>>正文


Python IBrowserDefault.providedBy方法代码示例

本文整理汇总了Python中Products.CMFDynamicViewFTI.interfaces.IBrowserDefault.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IBrowserDefault.providedBy方法的具体用法?Python IBrowserDefault.providedBy怎么用?Python IBrowserDefault.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Products.CMFDynamicViewFTI.interfaces.IBrowserDefault的用法示例。


在下文中一共展示了IBrowserDefault.providedBy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_default_page_step_2

# 需要导入模块: from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault [as 别名]
# 或者: from Products.CMFDynamicViewFTI.interfaces.IBrowserDefault import providedBy [as 别名]
    def test_get_default_page_step_2(self):
        # Else check for IBrowserDefault, either if the container implements
        # it or if an adapter exists. In both cases fetch its FTI and either
        # take it if it implements IDynamicViewTypeInformation or adapt it to
        # IDynamicViewTypeInformation. call get_default_page on the implementer
        # and take value if given.

        # first check some preconditions
        #
        # 1) a folder provides IBrowserDefault
        from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault
        self.assertTrue(IBrowserDefault.providedBy(self.folder))

        # 2) a folder also provides an fti that implements
        #    IDynamicViewTypeInformation
        from Products.CMFDynamicViewFTI.interfaces import IDynamicViewTypeInformation  # noqa
        fti = self.folder.getTypeInfo()
        self.assertTrue(IDynamicViewTypeInformation.providedBy(fti))

        # so if we set a document as defaultpage
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")
        self.folder.setDefaultPage('d1')

        # 3) fti should return it
        self.assertEqual(
            'd1',
            fti.getDefaultPage(self.folder, check_exists=True)
        )

        # now test since we're sure everythings set up correctly
        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
开发者ID:sneridagh,项目名称:Products.CMFPlone,代码行数:34,代码来源:test_defaultpage.py

示例2: browserDefault

# 需要导入模块: from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault [as 别名]
# 或者: from Products.CMFDynamicViewFTI.interfaces.IBrowserDefault import providedBy [as 别名]
    def browserDefault(self, obj):
        """Sets default so we can return whatever we want instead of index_html.

        This method is complex, and interacts with mechanisms such as
        IBrowserDefault (implemented in CMFDynamicViewFTI), LinguaPlone and
        various mechanisms for setting the default page.

        The method returns a tuple (obj, [path]) where path is a path to
        a template or other object to be acquired and displayed on the object.
        The path is determined as follows:

        0. If we're c oming from WebDAV, make sure we don't return a contained
            object "default page" ever
        1. If there is an index_html attribute (either a contained object or
            an explicit attribute) on the object, return that as the
            "default page". Note that this may be used by things like
            File and Image to return the contents of the file, for example,
            not just content-space objects created by the user.
        2. If the object implements IBrowserDefault, query this for the
            default page.
        3. If the object has a property default_page set and this gives a list
            of, or single, object id, and that object is is found in the
            folder or is the name of a skin template, return that id
        4. If the property default_page is set in site_properties and that
            property contains a list of ids of which one id is found in the
            folder, return that id
        5. If the object implements IBrowserDefault, try to get the selected
            layout.
        6. If the type has a 'folderlisting' action and no default page is
            set, use this action. This permits folders to have the default
            'view' action be 'string:${object_url}/' and hence default to
            a default page when clicking the 'view' tab, whilst allowing the
            fallback action to be specified TTW in portal_types (this action
            is typically hidden)
        7. If nothing else is found, fall back on the object's 'view' action.
        8. If this is not found, raise an AttributeError
        """

        # WebDAV in Zope is odd it takes the incoming verb eg: PROPFIND
        # and then requests that object, for example for: /, with verb PROPFIND
        # means acquire PROPFIND from the folder and call it
        # its all very odd and WebDAV'y
        request = getattr(self, 'REQUEST', None)
        if request is not None and 'REQUEST_METHOD' in request:
            if request['REQUEST_METHOD'] not in ['GET', 'POST']:
                return obj, [request['REQUEST_METHOD']]
        # Now back to normal

        #
        # 1. Get an attribute or contained object index_html
        #

        # Note: The base PloneFolder, as well as ATCT's ATCTOrderedFolder
        # defines a method index_html() which returns a ReplaceableWrapper.
        # This is needed for WebDAV to work properly, and to avoid implicit
        # acquisition of index_html's, which are generally on-object only.
        # For the purposes of determining a default page, we don't want to
        # use this index_html(), nor the ComputedAttribute which defines it.

        if not isinstance(getattr(obj, 'index_html', None),
                          ReplaceableWrapper):
            index_obj = getattr(aq_base(obj), 'index_html', None)
            if index_obj is not None \
                    and not isinstance(index_obj, ComputedAttribute):
                return obj, ['index_html']

        #
        # 2. Look for a default_page managed by an IBrowserDefault-implementing
        #    object
        #
        # 3. Look for a default_page property on the object
        #
        # 4. Try the default sitewide default_page setting
        #

        if obj.isPrincipiaFolderish:
            defaultPage = self.getDefaultPage(obj)
            if defaultPage is not None:
                if defaultPage in obj:
                    return obj, [defaultPage]
                # Avoid infinite recursion in the case that the page id == the
                # object id
                elif (
                    defaultPage != obj.getId()
                    and defaultPage != '/'.join(obj.getPhysicalPath())
                ):
                    # For the default_page property, we may get things in the
                    # skin layers or with an explicit path - split this path
                    # to comply with the __browser_default__() spec
                    return obj, defaultPage.split('/')

        # 5. If there is no default page, try IBrowserDefault.getLayout()
        if IBrowserDefault.providedBy(obj):
            browserDefault = obj
        else:
            browserDefault = queryAdapter(obj, IBrowserDefault)
        if browserDefault is not None:
            layout = browserDefault.getLayout()
            if layout is None:
                raise AttributeError(
#.........这里部分代码省略.........
开发者ID:erral,项目名称:Products.CMFPlone,代码行数:103,代码来源:PloneTool.py

示例3: get_default_page

# 需要导入模块: from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault [as 别名]
# 或者: from Products.CMFDynamicViewFTI.interfaces.IBrowserDefault import providedBy [as 别名]
def get_default_page(context):
    """Given a folderish item, find out if it has a default-page using
    the following lookup rules:

        1. A content object called 'index_html' wins
        2. Else check for IBrowserDefault, either if the container implements
           it or if an adapter exists. In both cases fetch its FTI and either
           take it if it implements IDynamicViewTypeInformation or adapt it to
           IDynamicViewTypeInformation. call getDefaultPage on the implementer
           and take value if given.
        3. Else, look up the attribute default_page on the object, without
           acquisition in place
        3.1 look for a content in the container with the id, no acquisition!
        3.2 look for a content at portal, with acquisition
        4. Else, look up the property default_page in site_properties for
           magic ids and test these

    The id of the first matching item is then used to lookup a translation
    and if found, its id is returned. If no default page is set, None is
    returned. If a non-folderish item is passed in, return None always.
    """
    # met precondition?
    if not IFolderish.providedBy(context):
        return

    # The ids where we look for default - must support __contains__
    ids = set()

    # For BTreeFolders we just use the __contains__ otherwise build a set
    if isinstance(aq_base(context), BTreeFolder2Base):
        ids = context
    elif hasattr(aq_base(context), 'objectIds'):
        ids = set(context.objectIds())

    # 1. test for contentish index_html
    if 'index_html' in ids:
        return 'index_html'

    # 2. Test for IBrowserDefault
    if IBrowserDefault.providedBy(context):
        browserDefault = context
    else:
        browserDefault = queryAdapter(context, IBrowserDefault)

    if browserDefault is not None:
        fti = context.getTypeInfo()
        if fti is not None:
            if IDynamicViewTypeInformation.providedBy(fti):
                dynamic_fti = fti
            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, basestring):
        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
    pp = getattr(portal, 'portal_properties', None)
    if pp is not None:
        site_properties = getattr(pp, 'site_properties', None)
        if site_properties is not None:
            for page in site_properties.getProperty('default_page', []):
                if page in ids:
                    return page
开发者ID:sneridagh,项目名称:Products.CMFPlone,代码行数:84,代码来源:defaultpage.py

示例4: getConfiguration

# 需要导入模块: from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault [as 别名]
# 或者: from Products.CMFDynamicViewFTI.interfaces.IBrowserDefault import providedBy [as 别名]

#.........这里部分代码省略.........

        results['link_using_uids'] = self.link_using_uids
        results['contextmenu'] = self.contextmenu
        results['entity_encoding'] = self.entity_encoding
        results['script_url'] = portal_url + '/tiny_mce_gzip.js'
        results['allow_captioned_images'] = bool(self.allow_captioned_images)
        results['rooted'] = bool(self.rooted or rooted)

        props = getToolByName(portal, 'portal_properties')
        plone_livesearch = props.site_properties.getProperty('enable_livesearch', False)
        livesearch = props.site_properties.getProperty('enable_tinymce_livesearch', plone_livesearch)
        results['livesearch'] = bool(livesearch)

        AVAILABLE_LANGUAGES = set(
        'sq ar hy az eu be bn nb bs br bg ca ch zh hr cs da dv nl en et fi fr gl '
        'ka de el gu he hi hu is id ia it ja ko lv lt lb mk ms ml mn se no nn fa '
        'pl pt ps ro ru sc sr ii si sk sl es sv ta tt te th tr zh-cn zh-tw uk ur cy vi zu'.split())

        if 'LANGUAGE' in context.REQUEST:
            if context.REQUEST.LANGUAGE in AVAILABLE_LANGUAGES:
                results['language'] = context.REQUEST.LANGUAGE
            elif context.REQUEST.LANGUAGE[:2] in AVAILABLE_LANGUAGES:
                results['language'] = context.REQUEST.LANGUAGE[:2]
            else:
                results['language'] = "en"
        else:
            results['language'] = "en"

        try:
            results['document_url'] = context.absolute_url()

            obj = context
            while obj is not None:
                if IFolderish.providedBy(obj):
                    if obj.portal_type != 'TempFolder':
                        # do not use portal_factory generated
                        # temporary object for base url.
                        results['document_base_url'] = obj.absolute_url() + "/"
                        break

                # We should never reach this.
                if ISiteRoot.providedBy(obj):
                    results['document_base_url'] = portal_url + "/"
                    results['document_url'] = portal_url
                    break

                obj = aq_parent(aq_inner(obj))

        except AttributeError:
            results['document_base_url'] = portal_url + "/"
            results['document_url'] = portal_url

        # Get Library options
        results['gecko_spellcheck'] = self.libraries_spellchecker_choice == 'browser'

        # Content Browser
        shortcuts_dict = dict(getUtilitiesFor(ITinyMCEShortcut))
        results['link_shortcuts_html'] = []
        results['image_shortcuts_html'] = []
        results['num_of_thumb_columns'] = self.num_of_thumb_columns
        results['thumbnail_size'] = self.thumbnail_size
        results['anchor_selector'] = self.anchor_selector

        for name in self.link_shortcuts:
            results['link_shortcuts_html'].extend(shortcuts_dict.get(name).render(context))
        for name in self.image_shortcuts:
开发者ID:4teamwork,项目名称:Products.TinyMCE,代码行数:70,代码来源:utility.py

示例5: getConfiguration

# 需要导入模块: from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault [as 别名]
# 或者: from Products.CMFDynamicViewFTI.interfaces.IBrowserDefault import providedBy [as 别名]

#.........这里部分代码省略.........
        results["link_using_uids"] = self.link_using_uids
        results["contextmenu"] = self.contextmenu
        results["entity_encoding"] = self.entity_encoding
        results["script_url"] = portal_url + "/tiny_mce_gzip.js"
        results["allow_captioned_images"] = bool(self.allow_captioned_images)
        results["rooted"] = bool(self.rooted or rooted)

        props = getToolByName(portal, "portal_properties")
        plone_livesearch = props.site_properties.getProperty("enable_livesearch", False)
        livesearch = props.site_properties.getProperty("enable_tinymce_livesearch", plone_livesearch)
        results["livesearch"] = bool(livesearch)

        AVAILABLE_LANGUAGES = set(
            "sq ar hy az eu be bn nb bs br bg ca ch zh hr cs da dv nl en et fi fr gl "
            "ka de el gu he hi hu is id ia it ja ko lv lt lb mk ms ml mn se no nn fa "
            "pl pt ps ro ru sc sr ii si sk sl es sv ta tt te th tr zh-cn zh-tw uk ur cy vi zu".split()
        )

        if "LANGUAGE" in context.REQUEST:
            if context.REQUEST.LANGUAGE in AVAILABLE_LANGUAGES:
                results["language"] = context.REQUEST.LANGUAGE
            elif context.REQUEST.LANGUAGE[:2] in AVAILABLE_LANGUAGES:
                results["language"] = context.REQUEST.LANGUAGE[:2]
            else:
                results["language"] = "en"
        else:
            results["language"] = "en"

        try:
            results["document_url"] = context.absolute_url()

            obj = context
            while obj is not None:
                if IFolderish.providedBy(obj):
                    if obj.portal_type != "TempFolder":
                        # do not use portal_factory generated
                        # temporary object for base url.
                        results["document_base_url"] = obj.absolute_url() + "/"
                        break

                # We should never reach this.
                if ISiteRoot.providedBy(obj):
                    results["document_base_url"] = portal_url + "/"
                    results["document_url"] = portal_url
                    break

                obj = aq_parent(aq_inner(obj))

        except AttributeError:
            results["document_base_url"] = portal_url + "/"
            results["document_url"] = portal_url

        # Get Library options
        results["gecko_spellcheck"] = self.libraries_spellchecker_choice == "browser"

        # Content Browser
        shortcuts_dict = dict(getUtilitiesFor(ITinyMCEShortcut))
        results["link_shortcuts_html"] = []
        results["image_shortcuts_html"] = []
        results["num_of_thumb_columns"] = self.num_of_thumb_columns
        results["thumbnail_size"] = self.thumbnail_size
        results["anchor_selector"] = self.anchor_selector

        for name in self.link_shortcuts:
            results["link_shortcuts_html"].extend(shortcuts_dict.get(name).render(context))
        for name in self.image_shortcuts:
开发者ID:jougs,项目名称:Products.TinyMCE,代码行数:70,代码来源:utility.py

示例6: getDefaultPage

# 需要导入模块: from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault [as 别名]
# 或者: from Products.CMFDynamicViewFTI.interfaces.IBrowserDefault import providedBy [as 别名]
def getDefaultPage(context):
    """Given a folderish item, find out if it has a default-page using
    the following lookup rules:

        1. A content object called 'index_html' wins
        2. If the folder implements IBrowserDefault, query this
        3. Else, look up the property default_page on the object
            - Note that in this case, the returned id may *not* be of an
              object in the folder, since it could be acquired from a
              parent folder or skin layer
        4. Else, look up the property default_page in site_properties for
            magic ids and test these

    The id of the first matching item is then used to lookup a translation
    and if found, its id is returned. If no default page is set, None is
    returned. If a non-folderish item is passed in, return None always.
    """
    # The list of ids where we look for default
    ids = {}

    # For BTreeFolders we just use the has_key, otherwise build a dict
    if hasattr(aq_base(context), 'has_key'):
        ids = context
    elif hasattr(aq_base(context), 'objectIds'):
        for id in context.objectIds():
            ids[id] = 1

    # 1. test for contentish index_html
    if 'index_html' in ids:
        return 'index_html'

    # 2. Test for IBrowserDefault
    if IBrowserDefault.providedBy(context):
        browserDefault = context
    else:
        browserDefault = queryAdapter(context, IBrowserDefault)

    if browserDefault is not None:
        fti = context.getTypeInfo()
        if fti is not None:
            if IDynamicViewTypeInformation.providedBy(fti):
                dynamicFTI = fti
            else:
                dynamicFTI = queryAdapter(fti, IDynamicViewTypeInformation)
            if dynamicFTI is not None:
                page = dynamicFTI.getDefaultPage(context, check_exists=True)
                if page is not None:
                    return page

    # 3. Test for default_page property in folder, then skins
    pages = getattr(aq_base(context), 'default_page', [])
    if isinstance(pages, basestring):
        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 not None:
        for page in pages:
            if portal.unrestrictedTraverse(page, None):
                return page

        # 4. Test for default sitewide default_page setting
        pp = getattr(portal, 'portal_properties', None)
        if pp is not None:
            site_properties = getattr(pp, 'site_properties', None)
            if site_properties is not None:
                for page in site_properties.getProperty('default_page', []):
                    if page in ids:
                        return page

    return None
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:76,代码来源:defaultpage.py


注:本文中的Products.CMFDynamicViewFTI.interfaces.IBrowserDefault.providedBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。