[Zope-CMF] Re: Finding the current skin name

Alexander Limi limi at plone.org
Tue Nov 1 12:38:41 EST 2005


Can anybody from the CMF team give some guidance to Laurence here?

-- Alexander

On Fri, 28 Oct 2005 06:31:42 -0700, Laurence Rowe <l at lrowe.co.uk> wrote:

> In Plone ResourceRegistries (1.1 branch) I need to get the current skin  
> name so that the resource (a css or js file) is fetched from the correct  
> skin. Unfortunately it seems that there is no easy way to get the  
> current skin name (when it is not set by a cookie in the request). I can  
> work around this like follows, but it's a bit ugly:
>
>
>      security.declareProtected(permissions.View, 'getCurrentSkinName')
>      def getCurrentSkinName(self):
>          """Returns the id of the current skin.
>
>          Ugh, there really should be a better way of doing this. This is
>          depending on internals in CMFCore and should be added there.
>          """
>          skintool = getToolByName(self, 'portal_skins')
>          default_skin_name = skintool.getDefaultSkin()
>          tid = get_ident()
>          if SKINDATA.has_key(tid):
>              skinobj, ignore, resolve = SKINDATA.get(tid)
>              current_skin_path = skinobj.getPhysicalPath()
>
>              #
>              # Perhaps test against default skin first?
>              #
>
>              skinnames = skintool.getSkinSelections()
>
>              # loop through skin names looking for a match
>              for name in skinnames:
>                  skin = skintool.getSkinByName(name)
>                  path = skin.getPhysicalPath()
>                  if current_skin_path == path:
>                      return name
>
>          return default_skin_name
>
> Would it be reasonable to make  
> Skinnable.SkinnableObjectManager.changeSkin set the skin request var  
> name after changing the skin? Such as:
>
>      security.declarePublic('changeSkin')
>      def changeSkin(self, skinname):
>          '''Change the current skin.
>
>          Can be called manually, allowing the user to change
>          skins in the middle of a request.
>          '''
>          skinobj = self.getSkin(skinname)
>          if skinobj is not None:
>              tid = get_ident()
>              SKINDATA[tid] = (skinobj, {}, {})
>              REQUEST = getattr(self, 'REQUEST', None)
>              if REQUEST is not None:
>                  REQUEST._hold(SkinDataCleanup(tid))
>                  sfn = self.getSkinsFolderName()
>                  if sfn is not None:
>                      sf = getattr(self, sfn, None)
>                      if sf is not None:
>                          REQUEST.set(sf.getRequestVarname(), skinname)
>
> Then getSkinNameFromRequest would work happily. Or is the a better way  
> to do this?
>
> Regards,
>
> Laurence
>
> _______________________________________________
> Zope-CMF maillist  -  Zope-CMF at lists.zope.org
> http://mail.zope.org/mailman/listinfo/zope-cmf
>
> See http://collector.zope.org/CMF for bug reports and feature requests
>



-- 
_____________________________________________________________________

      Alexander Limi · Chief Architect · Plone Solutions · Norway

  Consulting · Training · Development · http://www.plonesolutions.com
_____________________________________________________________________

       Plone Co-Founder · http://plone.org · Connecting Content
   Plone Foundation · http://plone.org/foundation · Protecting Plone



More information about the Zope-CMF mailing list