Author: jmorliaguet Date: Mon Jun 26 22:54:40 2006 New Revision: 3529 Modified: cpsskins/branches/paris-sprint-2006/locations/configure.zcml cpsskins/branches/paris-sprint-2006/locations/interfaces.py cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log: - using a vocabulary for location data too 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 Mon Jun 26 22:54:40 2006 @@ -22,4 +22,10 @@ name="location scopes" /> + <utility + provides="zope.schema.interfaces.IVocabularyFactory" + component=".interfaces.DataVocabulary" + name="location data" + /> + </configure> 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 Mon Jun 26 22:54:40 2006 @@ -23,6 +23,8 @@ from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm +from cpsskins.utils import getThemeManager + _ = MessageFactory("cpsskins") class ILocation(Interface): @@ -41,8 +43,9 @@ vocabulary="location scopes", ) - data = TextLine( + data = Choice( title=u"Data", + vocabulary="location data", ) def __call__(): @@ -56,10 +59,37 @@ """ return SimpleVocabulary( [SimpleTerm(value, token, title) for value, token, title in ( - ((0, 0), u'0-0', _(u"In this folder and all sub-folders")), - ((0, 1), u'0-1', _(u"Only in this folder")), - ((1, 0), u'1-0', _(u"In all sub-folders")), + ((0, 0), u'0-0', _(u"here and in all sub-folders")), + ((0, 1), u'0-1', _(u"only here")), + ((1, 0), u'1-0', _(u"in all sub-folders")), )]) alsoProvides(ScopesVocabulary, IVocabularyFactory) +def DataVocabulary(context): + """A vocabulary for the 'data' field + """ + location = context + tmutil = getThemeManager(context) + root = location.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 SimpleVocabulary( + [SimpleTerm(value=k, title=v) for k, v in choices.items()]) + +alsoProvides(DataVocabulary, IVocabularyFactory) 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 Mon Jun 26 22:54:40 2006 @@ -21,6 +21,7 @@ from zope.formlib import form from zope.schema import getFields from zope.schema.interfaces import IVocabularyFactory, IVocabularyTokenized +from zope.schema.interfaces import ConstraintNotSatisfied from cpsskins import minjson as json from cpsskins.locations import Location @@ -143,15 +144,17 @@ locations = tmutil.getLocationStorage() scopes_factory = getUtility(IVocabularyFactory, u'location scopes') + data_choices_factory = getUtility(IVocabularyFactory, u'location data') info = {} for root in locations.getRoots(): info[root] = {} for location in locations.getLocations(root): scopes = scopes_factory(location) + data_choices = data_choices_factory(location) info[root][location.path] = { 'path': location.path, - 'data': location.data, + 'data': location.data, # FIXME: get the title 'scope': scopes.getTerm(location.scope).title, 'object': location, } @@ -202,7 +205,9 @@ def submit(self, data): context = self.context scopes_factory = getUtility(IVocabularyFactory, u'location scopes') + data_choices_factory = getUtility(IVocabularyFactory, u'location data') scopes = scopes_factory(context) + data_choices = data_choices_factory(context) for form_field in self.form_fields: field = form_field.field name = form_field.__name__ @@ -210,6 +215,9 @@ if name == u'scope': value = scopes.getTermByToken(value).value field.validate(value) + elif name == u'data': + if value not in data_choices: + raise ConstraintNotSatisfied(value) else: value = field.fromUnicode(value) field.set(context, value) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins