[Zope3-checkins] SVN: Zope3/trunk/ Added a small demo for preferences that allows the user to select his/her

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Apr 1 21:15:44 EST 2005


Log message for revision 29828:
  Added a small demo for preferences that allows the user to select his/her 
  favorite skin to use.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  A   Zope3/trunk/package-includes/zope.app.demo.skinpref-configure.zcml
  A   Zope3/trunk/src/zope/app/demo/skinpref/
  A   Zope3/trunk/src/zope/app/demo/skinpref/__init__.py
  A   Zope3/trunk/src/zope/app/demo/skinpref/configure.zcml
  A   Zope3/trunk/src/zope/app/demo/skinpref/interfaces.py
  A   Zope3/trunk/src/zope/app/demo/skinpref/skin.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-04-02 02:09:15 UTC (rev 29827)
+++ Zope3/trunk/doc/CHANGES.txt	2005-04-02 02:15:43 UTC (rev 29828)
@@ -40,6 +40,9 @@
 
             http://localhost:8080/++preferences++/zmi
 
+        * Provided a demo that demonstrates how preferences can be used to
+          select the user's skin.
+
       - Added virtual host support in xml and static tree. The tree will
         switch the root to the virtualhost base.
 

Added: Zope3/trunk/package-includes/zope.app.demo.skinpref-configure.zcml
===================================================================
--- Zope3/trunk/package-includes/zope.app.demo.skinpref-configure.zcml	2005-04-02 02:09:15 UTC (rev 29827)
+++ Zope3/trunk/package-includes/zope.app.demo.skinpref-configure.zcml	2005-04-02 02:15:43 UTC (rev 29828)
@@ -0,0 +1 @@
+<include package="zope.app.demo.skinpref" />


Property changes on: Zope3/trunk/package-includes/zope.app.demo.skinpref-configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/demo/skinpref/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/demo/skinpref/__init__.py	2005-04-02 02:09:15 UTC (rev 29827)
+++ Zope3/trunk/src/zope/app/demo/skinpref/__init__.py	2005-04-02 02:15:43 UTC (rev 29828)
@@ -0,0 +1 @@
+# Make folder a package.


Property changes on: Zope3/trunk/src/zope/app/demo/skinpref/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/demo/skinpref/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/demo/skinpref/configure.zcml	2005-04-02 02:09:15 UTC (rev 29827)
+++ Zope3/trunk/src/zope/app/demo/skinpref/configure.zcml	2005-04-02 02:15:43 UTC (rev 29828)
@@ -0,0 +1,31 @@
+<configure
+  xmlns="http://namespaces.zope.org/zope"
+  i18n_domain="zope">
+
+  <subscriber
+      for="zope.app.publication.interfaces.IBeforeTraverseEvent"
+      handler=".skin.applySkin"
+      />
+
+  <vocabulary
+      name="Skins"
+      factory="zope.app.component.vocabulary.UtilityVocabulary"
+      interface="zope.publisher.interfaces.browser.ISkin" />
+
+  <preferenceGroup
+      id="zmi"
+      title="ZMI Settings"
+      description="
+        In this category you will find all preferences related to the Zope
+        Management Interface (ZMI).
+        "
+      category="true"
+      />
+
+  <preferenceGroup
+      id="zmi.skin"
+      title="Skin Selection"
+      schema=".interfaces.ISkinSelection"
+      />
+
+</configure>


Property changes on: Zope3/trunk/src/zope/app/demo/skinpref/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/demo/skinpref/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/demo/skinpref/interfaces.py	2005-04-02 02:09:15 UTC (rev 29827)
+++ Zope3/trunk/src/zope/app/demo/skinpref/interfaces.py	2005-04-02 02:15:43 UTC (rev 29828)
@@ -0,0 +1,34 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Interfaces for Skin settings
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.schema
+
+class ISkinSelection(zope.interface.Interface):
+    """User Settings for the Skin Selection"""
+
+    skin = zope.schema.Choice(
+        title=u"Skin",
+        description=u"""
+            This is the skin that will be used by default.
+
+            Note: You have to reload the page again for the setting to show an
+            effect.
+            """,
+        vocabulary="Skins")


Property changes on: Zope3/trunk/src/zope/app/demo/skinpref/interfaces.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/demo/skinpref/skin.py
===================================================================
--- Zope3/trunk/src/zope/app/demo/skinpref/skin.py	2005-04-02 02:09:15 UTC (rev 29827)
+++ Zope3/trunk/src/zope/app/demo/skinpref/skin.py	2005-04-02 02:15:43 UTC (rev 29828)
@@ -0,0 +1,47 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Skin Preferences Realization
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+from zope.publisher.interfaces.browser import ISkin
+from zope.app.component.interfaces import ISite
+from zope.app.preference.interfaces import IUserPreferences
+
+def applySkin(event):
+    # We only want to look for a new skin to set, if we entered a new site.
+    if not ISite.providedBy(event.object):
+        return
+    
+    # Find the user's skin
+    prefs = IUserPreferences(event.object)
+    skin = prefs.zmi.skin.skin
+
+    # Only change the skin, if request does not have this skin
+    if not skin or skin.providedBy(event.request):
+        return
+
+    # Remove the old skin
+    for iface in zope.interface.directlyProvidedBy(event.request):
+        if ISkin.providedBy(iface):
+            zope.interface.directlyProvides(
+                event.request,
+                zope.interface.directlyProvidedBy(event.request)-iface)
+            break
+
+    # Add the new skin
+    zope.interface.alsoProvides(event.request, skin)


Property changes on: Zope3/trunk/src/zope/app/demo/skinpref/skin.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list