I don't have a use case that interesting, but I have made use of changeSkin with and wished there was a way to easily find out which skin I've ended up with for debugging and testing purposes. So I'm +1 on the feature idea, don't really care how it's implemented.
On 11/3/05, Florent Guillaume <[EMAIL PROTECTED]> wrote: > Laurence Rowe wrote: > > The basic use case is to have sections of the site with different skins. > > I implement this with a call to changeSkin in > > __before_publishing_traverse__ of a folderish type. As these folders may > > be nested changeSkin could be called several times during the request. > > The correct skin is that specified by the last call to changeSkin. > > > > The skin name is needed afterwards by Plone's ResourceRegistries so that > > the correct resource (css or js file) is returned. In answer to Tres' > > question, different css or js is required because it is a relatively > > easy way for site managers to customise their site's appearance. (RR > > ends up returning resources with urls like <site url>/<skin > > name>/<resource name>). > > > > I'll follow Tres' suggestion and supply a patch shortly. > > I think Tres's solution is overkill, and that your original solution is > better. > > The point of SKINDATA is that, as a module global, it is accessible even by > code paths that don't have any way of getting an acquisition context to get > to REQUEST. > > However in your case, both changeSkin and the places where you'll need to > know the current skin name have access to REQUEST, so, as you proposed, you > can just add the skin name back in REQUEST, using > REQUEST.set(sf.getRequestVarname(), skinname). > > Florent > > > > > > > > Laurence > > > > > > > > Florent Guillaume wrote: > > > >> Could you expand a bit on the use case ? I'm not sure I get what you > >> want do to, do you change skins several times in the middle of the > >> request ? In what way is this skin needed afterward, at what point ? > >> What's a "correct" skin ? > >> > >> Florent > >> > >> Laurence Rowe 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 - > >>> [EMAIL PROTECTED] > >>> http://mail.zope.org/mailman/listinfo/zope-cmf > >>> > >>> See http://collector.zope.org/CMF for bug reports and feature requests > >>> > >> > >> > > > > _______________________________________________ > > Zope-CMF maillist - [EMAIL PROTECTED] > > http://mail.zope.org/mailman/listinfo/zope-cmf > > > > See http://collector.zope.org/CMF for bug reports and feature requests > > > > > -- > Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D > +33 1 40 33 71 59 http://nuxeo.com [EMAIL PROTECTED] > _______________________________________________ > Zope-CMF maillist - Zope-CMF@lists.zope.org > http://mail.zope.org/mailman/listinfo/zope-cmf > > See http://collector.zope.org/CMF for bug reports and feature requests > -- http://www.slinkp.com _______________________________________________ Zope-CMF maillist - Zope-CMF@lists.zope.org http://mail.zope.org/mailman/listinfo/zope-cmf See http://collector.zope.org/CMF for bug reports and feature requests