src/ztfy/baseskin/skin.py
changeset 0 747fc65e13e2
equal deleted inserted replaced
-1:000000000000 0:747fc65e13e2
       
     1 ### -*- coding: utf-8 -*- ####################################################
       
     2 ##############################################################################
       
     3 #
       
     4 # Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
       
     5 # All Rights Reserved.
       
     6 #
       
     7 # This software is subject to the provisions of the Zope Public License,
       
     8 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
    10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    12 # FOR A PARTICULAR PURPOSE.
       
    13 #
       
    14 ##############################################################################
       
    15 
       
    16 
       
    17 # import standard packages
       
    18 
       
    19 # import Zope3 interfaces
       
    20 from zope.publisher.interfaces.browser import IBrowserRequest, IBrowserSkinType
       
    21 from zope.traversing.interfaces import IBeforeTraverseEvent
       
    22 
       
    23 # import local interfaces
       
    24 from ztfy.baseskin.interfaces import ISkinnable
       
    25 
       
    26 # import Zope3 packages
       
    27 from zope.component import adapter, queryUtility
       
    28 from zope.publisher.skinnable import applySkin
       
    29 
       
    30 # import local packages
       
    31 
       
    32 
       
    33 @adapter(ISkinnable, IBeforeTraverseEvent)
       
    34 def handleSkinTraversal(object, event):
       
    35     if IBrowserRequest.providedBy(event.request):
       
    36         path = event.request.get('PATH_INFO', '')
       
    37         if '++skin++' not in path:
       
    38             skin_name = ISkinnable(object).getSkin()
       
    39             if not skin_name:
       
    40                 skin_name = 'ZMI'
       
    41             skin = queryUtility(IBrowserSkinType, skin_name)
       
    42             if skin is not None:
       
    43                 applySkin(event.request, skin)