source: products/quintagroup.skin.switcher/branches/domain_or_path/quintagroup/skin/switcher/skinswitcher.py

Last change on this file was 1839, checked in by mylan, 14 years ago

Added possibility to switch by path also

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1from urlparse import urlsplit
2
3from Products.CMFCore.utils import getToolByName
4
5from config import *
6
7def setSkin(site, event):
8    ps = getToolByName(site,'portal_skins')
9
10    if USE_FS_CONFIG:
11        do_switch = DO_SWITCH
12        pref = SKIN_SWITCH_PREFIX
13        switch_theme = SWITCH_THEME
14    else:
15        pp = getToolByName(site,'portal_properties')
16        ss = getattr(pp,'skin_switcher',None)
17        if not ss:
18            return
19        pref = ss.getProperty('theme_switch_prefix', SKIN_SWITCH_PREFIX)
20        switch_theme = ss.getProperty('switch_theme', SWITCH_THEME)
21        do_switch = ss.getProperty('do_switch', DO_SWITCH)
22
23    if not do_switch:
24        return
25
26    avail_skins = ps.getSkinSelections()
27    if not (pref and switch_theme and switch_theme in avail_skins):
28       return
29
30    scheme, netloc, path, query, fragm = urlsplit(event.request.ACTUAL_URL)
31    if netloc.startswith(pref):
32        site.changeSkin(switch_theme, event.request)
33    elif path.startswith(pref):
34        site.changeSkin(switch_theme, event.request)
Note: See TracBrowser for help on using the repository browser.