Author: jmorliaguet
Date: Wed Jun 28 20:26:09 2006
New Revision: 3543

Modified:
   cpsskins/branches/paris-sprint-2006/locations/configure.zcml
   cpsskins/branches/paris-sprint-2006/locations/interfaces.py
   cpsskins/branches/paris-sprint-2006/locations/sources.txt
   cpsskins/branches/paris-sprint-2006/setup/io/fields.py
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py

Log:

- moved sources to a a separate file

- disabled the validation of Choice fields during XML imports since their
  sources depend on a context which doesn't exist yet.



Modified: cpsskins/branches/paris-sprint-2006/locations/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/configure.zcml        
(original)
+++ cpsskins/branches/paris-sprint-2006/locations/configure.zcml        Wed Jun 
28 20:26:09 2006
@@ -25,7 +25,7 @@
 
   <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
-     component=".interfaces.scopesVocabulary"
+     component=".sources.scopesVocabulary"
      name="location scopes"
   />
 

Modified: cpsskins/branches/paris-sprint-2006/locations/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/interfaces.py (original)
+++ cpsskins/branches/paris-sprint-2006/locations/interfaces.py Wed Jun 28 
20:26:09 2006
@@ -17,75 +17,15 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.interface import Interface, alsoProvides, Attribute, implements
+from zope.interface import Interface, Attribute
 from zope.i18nmessageid import MessageFactory
-from zope.schema import TextLine, Tuple, Choice, Int
-from zope.schema.interfaces import ISource
-from zope.schema.interfaces import IVocabularyFactory, IContextSourceBinder
-from zope.schema.interfaces import IBaseVocabulary, IContextSourceBinder
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from zope.schema import  TextLine, Choice
 
-from cpsskins.utils import getThemeManager
+from cpsskins.locations.sources import data_source_binder
 from cpsskins.schema import IntCoupleChoice
 
 _ = 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()
-    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)
-
 class ILocation(Interface):
     """Location"""
 

Modified: cpsskins/branches/paris-sprint-2006/locations/sources.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/sources.txt   (original)
+++ cpsskins/branches/paris-sprint-2006/locations/sources.txt   Wed Jun 28 
20:26:09 2006
@@ -15,7 +15,7 @@
     >>> themes = addThemeSkeleton(tmutil)
 
     >>> from zope.schema import Choice
-    >>> from cpsskins.locations.interfaces import DataSource
+    >>> from cpsskins.locations.sources import DataSource
     >>> data_choice = Choice(
     ...     title=u"Data",
     ...     source=DataSource(),
@@ -27,7 +27,7 @@
 
 let us create a source binder and bind the field to the context:
 
-    >>> from cpsskins.locations.interfaces import data_source_binder
+    >>> from cpsskins.locations.sources import data_source_binder
 
     >>> data_choice_in_context = Choice(
     ...     title=u"Data",

Modified: cpsskins/branches/paris-sprint-2006/setup/io/fields.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io/fields.py      (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io/fields.py      Wed Jun 28 
20:26:09 2006
@@ -140,3 +140,10 @@
     adapts(zope.schema.interfaces.IChoice)
     implements(IFieldIO)
 
+    def load(self, text):
+        self.field._init_field = True
+        value = self.field.fromUnicode(text)
+        self.field._init_field = False
+        return value
+
+

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py 
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py Wed Jun 
28 20:26:09 2006
@@ -144,7 +144,6 @@
         locations = tmutil.getLocationStorage()
 
         scopes_factory = getUtility(IVocabularyFactory, u'location scopes')
-        data_choices_factory = getUtility(IVocabularyFactory, u'location data')
 
         info = {}
         for root in locations.getRoots():
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to