Logo Search packages:      
Sourcecode: zope-cpsskins version File versions  Download package

def CPSSkins::PortalThemesTool::PortalThemesTool::getLocalThemeName (   self,
  kw 
)

Return the name of a local theme in a given context.

   Local themes are obtained from folder attributes, i.e.
   - as the property of a folder (one theme per line)
   - as an object located in the folder that is callable and
     that returns a tuple.

   Local themes are computed by collecting all theme information
   from the portal to the context folder.

   The format for describing themes is:
   - simply a string containing the theme id.

   - 'n-m:theme'

   where:
   - 'theme' is the theme id
   - (n, m) is a couple with n <= m that describes the interval
     inside which the theme will be used.
     (0, 0) means the current folder and all subfolders
     (1, 0) means all subfolders below the current folder
     (1, 1) means the subfolders of level 1
     (0, 1) means the folder and the subfolders of level 1
     (n, n) means the subfolders of level n
     ...

   Examples:
   * with a folder property called '.cpsskins_theme':

     - lines with intervals:

       0-1:theme1
       2-4:theme2
       6-0:theme3

     - string with interval:

       0-1:theme1

     - string without interval:

       theme1

   * with a script called '.cpsskins_theme.py' placed in a folder:

     - tuple with intervals:

       return ('0-1:theme1', '2-4:theme2', '6-0:theme3')

     - string with interval:

       return '0-1:theme'

     - string without interval:

       return 'theme'

Definition at line 488 of file PortalThemesTool.py.

00488                                      :
        """Return the name of a local theme in a given context.

           Local themes are obtained from folder attributes, i.e.
           - as the property of a folder (one theme per line)
           - as an object located in the folder that is callable and
             that returns a tuple.

           Local themes are computed by collecting all theme information
           from the portal to the context folder.

           The format for describing themes is:
           - simply a string containing the theme id.

           - 'n-m:theme'

           where:
           - 'theme' is the theme id
           - (n, m) is a couple with n <= m that describes the interval
             inside which the theme will be used.
             (0, 0) means the current folder and all subfolders
             (1, 0) means all subfolders below the current folder
             (1, 1) means the subfolders of level 1
             (0, 1) means the folder and the subfolders of level 1
             (n, n) means the subfolders of level n
             ...

           Examples:
           * with a folder property called '.cpsskins_theme':

             - lines with intervals:

               0-1:theme1
               2-4:theme2
               6-0:theme3

             - string with interval:

               0-1:theme1

             - string without interval:

               theme1

           * with a script called '.cpsskins_theme.py' placed in a folder:

             - tuple with intervals:

               return ('0-1:theme1', '2-4:theme2', '6-0:theme3')

             - string with interval:

               return '0-1:theme'

             - string without interval:

               return 'theme'

        """

        context = kw.get('context_obj')
        if context is None:
            return None

        # Find bottom-most folder:
        obj = context
        bmf = None
        while 1:
            if obj.isPrincipiaFolderish and \
                not obj.getId().startswith('.'):
                bmf = obj
                break
            parent = aq_parent(aq_inner(obj))
            if not obj or parent == obj:
                break
            obj = parent
        if bmf is None:
            bmf = context

        # get themes from the root to current path
        utool = getToolByName(self, 'portal_url')
        portal = utool.getPortalObject()
        level = len(utool.getRelativeContentPath(bmf))

        ob = bmf
        objs = [ob]
        while True:
            # move to the parent
            ob = aq_parent(aq_inner(ob))
            if ob is None:
                break
            objs.append(ob)
            if ob is portal:
                break

        # we revert the list since we want to start from the portal and move
        # to the current object, i.e. local themes if they apply to a given
        # folder override the themes set in the folders above.
        objs.reverse()

        # get the local theme
        localtheme = None
        for obj in objs:
            theme = self._getLocalTheme(folder=obj, level=level)
            level -= 1
            if theme is not None:
                localtheme = theme
            # we continue since the local theme can be still be overriden.
        return localtheme

    security.declarePublic('getLocalThemes')
    def getLocalThemes(self, folder=None, **kw):


Generated by  Doxygen 1.6.0   Back to index