Author: jmorliaguet
Date: Wed Jun 28 21:01:08 2006
New Revision: 3545

Added:
   cpsskins/branches/paris-sprint-2006/locations/sources.py   (contents, props 
changed)

Log:

- added missing file



Added: cpsskins/branches/paris-sprint-2006/locations/sources.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/locations/sources.py    Wed Jun 28 
21:01:08 2006
@@ -0,0 +1,86 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.interface import alsoProvides, implements
+from zope.i18nmessageid import MessageFactory
+from zope.schema.interfaces import ISource
+from zope.schema.interfaces import IVocabularyFactory, IContextSourceBinder
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+
+from cpsskins.utils import getThemeManager
+
+_ = MessageFactory("cpsskins")
+
+def scopesVocabulary(context):
+    """A vocabulary that contains a list of scopes
+    """
+    return SimpleVocabulary(
+        [SimpleTerm(value, token, title) for value, token, title in (
+            ((0, 0), u'0-0', _(u"there and in all sub-folders")),
+            ((0, 1), u'0-1', _(u"only there")),
+            ((1, 0), u'1-0', _(u"in all sub-folders")),
+        )])
+
+alsoProvides(scopesVocabulary, IVocabularyFactory)
+
+class DataSource(object):
+    """Source for the 'data' field
+    """
+    implements(ISource)
+
+    def __init__(self):
+        self.context = None
+
+    def __iter__(self):
+        context = self.context
+        if context is None:
+            return iter([])
+        tmutil = getThemeManager(context)
+        root = context.root
+        choices = {}
+
+        if root == u'pages':
+            for theme in tmutil.getThemes():
+                theme_name = theme.name
+                for page in theme.getPages():
+                    page_id = u'%s:%s' % (theme_name, page.name)
+                    choices[page_id] = u'%s / %s' % (theme.title, page.title)
+
+        elif root == u'perspectives':
+            for perspective in tmutil.listPerspectives():
+                choices[perspective.name] = perspective.title
+
+        elif root == u'engines':
+            # FIXME
+            choices[u'default'] = u'default'
+
+        return iter(
+            [SimpleTerm(value=k, title=v) for k, v in choices.items()])
+
+def data_source_binder(context):
+    source = DataSource()
+    from cpsskins.locations.interfaces import ILocation
+    if not ILocation.providedBy(context):
+        raise ValueError("The data source must be bound with a location as a "
+                         "context.")
+    source.context = context
+    return source
+
+alsoProvides(data_source_binder, IContextSourceBinder)
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to