Author: jmorliaguet Date: Wed Jun 28 22:31:56 2006 New Revision: 3552 Modified: cpsskins/branches/paris-sprint-2006/locations/sources.py cpsskins/branches/paris-sprint-2006/tests/test_locations.py cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log: - added __contains__ to the data source. working implementation 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:31:56 2006 @@ -45,6 +45,11 @@ class DataSource(object): """Source for the 'data' field + + >>> from zope.interface.verify import verifyClass + >>> verifyClass(IDataSource, DataSource) + True + """ implements(IDataSource) @@ -77,6 +82,15 @@ return iter( [SimpleTerm(value=k, title=v) for k, v in choices.items()]) + def __len__(self): + return len(list(self)) + + def __contains__(self, value): + for term in self: + if term.value == value: + return True + return False + def data_source_binder(context): source = DataSource() from cpsskins.locations.interfaces import ILocation @@ -89,8 +103,13 @@ alsoProvides(data_source_binder, IContextSourceBinder) class DataTerms(object): - """ITerms adapter for the data source""" + """ITerms adapter for the data source + + >>> from zope.interface.verify import verifyClass + >>> verifyClass(ITerms, DataTerms) + True + """ implements(ITerms) def __init__(self, source, request): Modified: cpsskins/branches/paris-sprint-2006/tests/test_locations.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/tests/test_locations.py (original) +++ cpsskins/branches/paris-sprint-2006/tests/test_locations.py Wed Jun 28 22:31:56 2006 @@ -19,11 +19,12 @@ import unittest -from zope.testing.doctestunit import DocFileSuite +from zope.testing.doctestunit import DocFileSuite, DocTestSuite def test_suite(): return unittest.TestSuite(( DocFileSuite('../locations/README.txt'), + DocTestSuite('cpsskins.locations.sources'), )) if __name__ == '__main__': 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 22:31:56 2006 @@ -206,8 +206,7 @@ context = self.context for form_field in self.form_fields: field = form_field.field.bind(context) - name = form_field.__name__ - value = data[u'%s.%s' % (self.prefix, name)] + value = data[u'%s.%s' % (self.prefix, form_field.__name__)] value = field.fromUnicode(value) field.set(context, value) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins