1 | from urlparse import urlsplit |
---|
2 | |
---|
3 | from Products.CMFCore.utils import getToolByName |
---|
4 | |
---|
5 | from config import * |
---|
6 | |
---|
7 | def 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) |
---|