Author: jmorliaguet Date: Wed Jun 28 22:36:46 2006 New Revision: 3553 Added: cpsskins/branches/paris-sprint-2006/schema.py (contents, props changed) Modified: cpsskins/branches/paris-sprint-2006/locations/sources.py cpsskins/branches/paris-sprint-2006/locations/sources.txt
Log: - fixed infinite recursion - test updates Modified: cpsskins/branches/paris-sprint-2006/locations/sources.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/sources.py (original) +++ cpsskins/branches/paris-sprint-2006/locations/sources.py Wed Jun 28 22:36:46 2006 @@ -83,7 +83,7 @@ [SimpleTerm(value=k, title=v) for k, v in choices.items()]) def __len__(self): - return len(list(self)) + return len([t for t in self]) def __contains__(self, value): for term in self: 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 22:36:46 2006 @@ -22,9 +22,12 @@ ... ) if the field is not bound to a context, no choices will be made available: - >>> print list(data_choice.source) + >>> list(data_choice.source) [] + >>> len(data_choice.source) + 0 + let us create a source binder and bind the field to the context: >>> from cpsskins.locations.sources import data_source_binder @@ -52,6 +55,15 @@ in the context of the location the data source returns a list of pages: >>> data_choice_in_context = data_choice_in_context.bind(l) - >>> print [t.value for t in data_choice_in_context.source] + >>> [t.value for t in data_choice_in_context.source] [u'Theme:ThemePage'] + >>> len(data_choice_in_context.source) + 1 + + >>> u'Theme:ThemePage' in data_choice_in_context.source + True + + >>> u'unknown' in data_choice_in_context.source + False + Added: cpsskins/branches/paris-sprint-2006/schema.py ============================================================================== --- (empty file) +++ cpsskins/branches/paris-sprint-2006/schema.py Wed Jun 28 22:36:46 2006 @@ -0,0 +1,38 @@ +############################################################################## +# +# 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 implements +from zope.schema.interfaces import IField +from zope.schema import Choice + +class IIntCoupleChoice(IField): + """A choice field containing couples of integers e.g. (0, 1)""" + +class IntCoupleChoice(Choice): + implements(IIntCoupleChoice) + + def fromUnicode(self, text): + self.validate(text) + a, b = text[1:-1].split(u', ') + return (int(a), int(b)) + + def validate(self, value): + # FIXME + return True + -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins