本文整理汇总了Python中Products.CMFDynamicViewFTI.interfaces.IBrowserDefault类的典型用法代码示例。如果您正苦于以下问题:Python IBrowserDefault类的具体用法?Python IBrowserDefault怎么用?Python IBrowserDefault使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IBrowserDefault类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getRootPath
def getRootPath(context, currentFolderOnly, topLevel, root):
"""Helper function to calculate the real root path
"""
context = aq_inner(context)
if currentFolderOnly:
folderish = getattr(aq_base(context), 'isPrincipiaFolderish', False) and not INonStructuralFolder.providedBy(context)
parent = aq_parent(context)
is_default_page = False
browser_default = IBrowserDefault(parent, None)
if browser_default is not None:
is_default_page = (browser_default.getDefaultPage() == context.getId())
if not folderish:
return '/'.join(parent.getPhysicalPath())
else:
return '/'.join(context.getPhysicalPath())
rootPath = getNavigationRoot(context, relativeRoot=root)
# Adjust for topLevel
if topLevel > 0:
contextPath = '/'.join(context.getPhysicalPath())
if not contextPath.startswith(rootPath):
return None
contextSubPathElements = contextPath[len(rootPath)+1:]
if contextSubPathElements:
contextSubPathElements = contextSubPathElements.split('/')
if len(contextSubPathElements) < topLevel:
return None
rootPath = rootPath + '/' + '/'.join(contextSubPathElements[:topLevel])
else:
return None
return rootPath
示例2: getObjectDefaultView
def getObjectDefaultView(context):
"""Get the id of an object's default view
"""
# courtesy of Producs.CacheSetup
browserDefault = IBrowserDefault(context, None)
if browserDefault is not None:
try:
return stripLeadingCharacters(browserDefault.defaultView())
except AttributeError:
# Might happen if FTI didn't migrate yet.
pass
if not IDynamicType.providedBy(context):
return None
fti = context.getTypeInfo()
try:
# XXX: This isn't quite right since it assumes the action starts
#with ${object_url}
action = fti.getActionInfo('object/view')['url'].split('/')[-1]
except ValueError:
# If the action doesn't exist, stop
return None
# Try resolving method aliases because we need a real template_id here
if action:
action = fti.queryMethodID(action, default = action, context = context)
else:
action = fti.queryMethodID('(Default)', default = action,
context = context)
return stripLeadingCharacters(action)
示例3: test_is_view_template_alias
def test_is_view_template_alias(self):
browserDefault = IBrowserDefault(self.folder, None)
fti = browserDefault.getTypeInfo()
aliases = fti.getMethodAliases()
aliases["foo_alias"] = "(Default)"
fti.setMethodAliases(aliases)
self.app.REQUEST["ACTUAL_URL"] = self.folder.absolute_url() + "/foo_alias"
self.assertEquals(self.fview.is_view_template(), True)
self.assertEquals(self.dview.is_view_template(), False)
示例4: test_get_default_page_step_2
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))
示例5: browserDefault
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(
#.........这里部分代码省略.........
示例6: get_default_page
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
示例7: getConfiguration
#.........这里部分代码省略.........
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:
results['image_shortcuts_html'].extend(shortcuts_dict.get(name).render(context))
# init vars specific for "After the Deadline" spellchecker
mtool = getToolByName(portal, 'portal_membership')
member = mtool.getAuthenticatedMember()
results['atd_rpc_id'] = 'Products.TinyMCE-' + (member.getId() or '') # None when Anonymous User
results['atd_rpc_url'] = "%s/@@" % portal_url
results['atd_show_types'] = self.libraries_atd_show_types.strip().replace('\n', ',')
results['atd_ignore_strings'] = self.libraries_atd_ignore_strings.strip().replace('\n', ',')
# generic configuration
results['mode'] = "exact"
results['theme'] = "advanced"
results['skin'] = "plone"
results['inlinepopups_skin'] = "plonepopup"
results['body_class'] = "documentContent"
plone_view = context.restrictedTraverse('@@plone')
template = None
if IBrowserDefault.providedBy(context):
template = context.unrestrictedTraverse(context.getLayout())
results['body_class'] += ' ' + plone_view.bodyClass(template, template)
results['body_id'] = "content"
results['table_firstline_th'] = True
results['fix_list_elements'] = False
# allow embed tag if user removes it from
# list of nasty tags - see #10681
results['media_strict'] = False
results['theme_advanced_path'] = False
results['theme_advanced_toolbar_align'] = "left"
results['plugins'] = self.getPlugins()
results['theme_advanced_styles'] = self.getStyles(styles, labels)
results['theme_advanced_buttons1'], results['theme_advanced_buttons2'], \
results['theme_advanced_buttons3'], results['theme_advanced_buttons4'] = self.getToolbars(results)
if self.formats and self.formats.strip():
results['formats'] = json.loads(self.formats)
return results
示例8: getConfiguration
#.........这里部分代码省略.........
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:
results["image_shortcuts_html"].extend(shortcuts_dict.get(name).render(context))
# init vars specific for "After the Deadline" spellchecker
mtool = getToolByName(portal, "portal_membership")
member = mtool.getAuthenticatedMember()
results["atd_rpc_id"] = "Products.TinyMCE-" + (member.getId() or "") # None when Anonymous User
results["atd_rpc_url"] = "%s/@@" % portal_url
results["atd_show_types"] = self.libraries_atd_show_types.strip().replace("\n", ",")
results["atd_ignore_strings"] = self.libraries_atd_ignore_strings.strip().replace("\n", ",")
# generic configuration
results["mode"] = "exact"
results["theme"] = "advanced"
results["skin"] = "plone"
results["inlinepopups_skin"] = "plonepopup"
results["body_class"] = "documentContent"
plone_view = context.restrictedTraverse("@@plone")
template = None
if IBrowserDefault.providedBy(context):
template = context.unrestrictedTraverse(context.getLayout())
results["body_class"] += " " + plone_view.bodyClass(template, template)
results["body_id"] = "content"
results["table_firstline_th"] = True
results["fix_list_elements"] = False
# allow embed tag if user removes it from
# list of nasty tags - see #10681
results["media_strict"] = False
results["theme_advanced_path"] = False
results["theme_advanced_toolbar_align"] = "left"
results["plugins"] = self.getPlugins()
results["theme_advanced_styles"] = self.getStyles(styles, labels)
results["theme_advanced_buttons1"], results["theme_advanced_buttons2"], results[
"theme_advanced_buttons3"
], results["theme_advanced_buttons4"] = self.getToolbars(results)
if self.formats and self.formats.strip():
results["formats"] = json.loads(self.formats)
return results
示例9: getDefaultPage
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