Back to index

plone3  3.1.7
Classes | Functions
plone.app.layout.navigation.defaultpage Namespace Reference

Classes

class  DefaultPage

Functions

def isDefaultPage
def getDefaultPage

Function Documentation

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.

Definition at line 47 of file defaultpage.py.

00047 
00048 def getDefaultPage(context):
00049     """Given a folderish item, find out if it has a default-page using
00050     the following lookup rules:
00051 
00052         1. A content object called 'index_html' wins
00053         2. If the folder implements IBrowserDefault, query this
00054         3. Else, look up the property default_page on the object
00055             - Note that in this case, the returned id may *not* be of an
00056               object in the folder, since it could be acquired from a
00057               parent folder or skin layer
00058         4. Else, look up the property default_page in site_properties for
00059             magic ids and test these
00060 
00061     The id of the first matching item is then used to lookup a translation
00062     and if found, its id is returned. If no default page is set, None is
00063     returned. If a non-folderish item is passed in, return None always.
00064     """
00065     # The list of ids where we look for default
00066     ids = {}
00067 
00068     # For BTreeFolders we just use the has_key, otherwise build a dict
00069     if hasattr(aq_base(context), 'has_key'):
00070         ids = context
00071     else:
00072         for id in context.objectIds():
00073             ids[id] = 1
00074 
00075     # Inline function with default argument.
00076     def lookupTranslationId(obj, page):
00077         return utils.lookupTranslationId(obj, page, ids)
00078 
00079     # 1. test for contentish index_html
00080     if ids.has_key('index_html'):
00081         return lookupTranslationId(context, 'index_html')
00082 
00083     # 2. Test for IBrowserDefault
00084     browserDefault = IBrowserDefault(context, None)
00085     if browserDefault is not None:
00086         fti = context.getTypeInfo()
00087         if fti is not None:
00088             dynamicFTI = IDynamicViewTypeInformation(fti, None)
00089             if dynamicFTI is not None:
00090                 page = dynamicFTI.getDefaultPage(context, check_exists=True)
00091                 if page is not None:
00092                     return lookupTranslationId(context, page)
00093 
00094     # 3. Test for default_page property in folder, then skins
00095     pages = getattr(aq_base(context), 'default_page', [])
00096     if isinstance(pages, basestring):
00097         pages = [pages]
00098     for page in pages:
00099         if page and ids.has_key(page):
00100             return lookupTranslationId(context, page)
00101 
00102     portal = queryUtility(ISiteRoot)
00103     # Might happen during portal creation
00104     if portal is not None:
00105         for page in pages:
00106             if portal.unrestrictedTraverse(page, None):
00107                 return lookupTranslationId(context, page)
00108 
00109         # 4. Test for default sitewide default_page setting
00110         pp = getattr(portal, 'portal_properties', None)
00111         if pp is not None:
00112             site_properties = getattr(pp, 'site_properties', None)
00113             if site_properties is not None:
00114                 for page in site_properties.getProperty('default_page', []):
00115                     if ids.has_key(page):
00116                         return lookupTranslationId(context, page)
00117 
00118     return None

Here is the call graph for this function:

Here is the caller graph for this function:

Finds out if the given obj is the default page in its parent folder.

Only considers explicitly contained objects, either set as index_html,
with the default_page property, or using IBrowserDefault.

Definition at line 35 of file defaultpage.py.

00035 
00036 def isDefaultPage(container, obj):
00037     """Finds out if the given obj is the default page in its parent folder.
00038 
00039     Only considers explicitly contained objects, either set as index_html,
00040     with the default_page property, or using IBrowserDefault.
00041     """
00042     parentDefaultPage = getDefaultPage(container)
00043     if parentDefaultPage is None or '/' in parentDefaultPage:
00044         return False
00045     return (parentDefaultPage == obj.getId())
00046 

Here is the call graph for this function:

Here is the caller graph for this function: