Changeset 12327 for main/waeup.ikoba/trunk/src/waeup/ikoba
- Timestamp:
- 26 Dec 2014, 20:18:17 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py
r12310 r12327 213 213 # We have to keep the following two classes here. In products.interfaces they 214 214 # will cause circular imports. 215 class IProductOption Entry(Interface):215 class IProductOption(Interface): 216 216 """A product option entry. 217 217 … … 231 231 ) 232 232 233 class IProductOption EntryField(IObject):233 class IProductOptionField(IObject): 234 234 """A zope.schema-like field for usage in interfaces. 235 235 -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/interfaces.py
r12314 r12327 22 22 ContextualDictSourceFactoryBase) 23 23 from waeup.ikoba.interfaces import MessageFactory as _ 24 from waeup.ikoba.products.productoptions import ProductOption EntryField24 from waeup.ikoba.products.productoptions import ProductOptionField 25 25 26 26 class ConCatSource(ContextualDictSourceFactoryBase): … … 66 66 options = schema.List( 67 67 title = _(u'Options/Fees'), 68 value_type = ProductOption EntryField(),68 value_type = ProductOptionField(), 69 69 required = False, 70 70 readonly = False, -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/productoptions.py
r12323 r12327 24 24 from zope.schema.fieldproperty import FieldProperty 25 25 from zope.schema import Object 26 from waeup.ikoba.interfaces import IProductOption Entry, IProductOptionEntryField26 from waeup.ikoba.interfaces import IProductOption, IProductOptionField 27 27 from waeup.ikoba.widgets.objectwidget import ( 28 28 IkobaObjectWidget, IkobaObjectDisplayWidget 29 29 ) 30 30 31 class ProductOption Entry(grok.Model):31 class ProductOption(grok.Model): 32 32 """A product option entry contains a title, fee and currency. 33 33 """ 34 grok.implements(IProductOption Entry)35 title = FieldProperty(IProductOption Entry['title'])36 fee = FieldProperty(IProductOption Entry['fee'])37 currency = FieldProperty(IProductOption Entry['currency'])34 grok.implements(IProductOption) 35 title = FieldProperty(IProductOption['title']) 36 fee = FieldProperty(IProductOption['fee']) 37 currency = FieldProperty(IProductOption['currency']) 38 38 39 39 def __init__(self, title=None, fee=None, currency=None): 40 super(ProductOption Entry, self).__init__()40 super(ProductOption, self).__init__() 41 41 if title is not None: 42 42 self.title = title … … 58 58 @classmethod 59 59 def from_string(cls, string): 60 """Create new ProductOption Entryinstance based on `string`.60 """Create new ProductOption instance based on `string`. 61 61 62 62 The string is expected to be in format as delivered by … … 65 65 This is a classmethod. This means, you normally will call:: 66 66 67 ProductOption Entry.from_string(mystring)67 ProductOption.from_string(mystring) 68 68 69 i.e. use the `ProductOption Entry` class, not an instance thereof.69 i.e. use the `ProductOption` class, not an instance thereof. 70 70 """ 71 71 string = string.replace("u''", "None") … … 77 77 return cls(title, fee, currency) 78 78 79 class ProductOption EntryField(Object):79 class ProductOptionField(Object): 80 80 """A zope.schema-like field for usage in interfaces. 81 81 … … 84 84 85 85 class IMyInterface(Interface): 86 my_option_entry = ProductOption EntryField()86 my_option_entry = ProductOptionField() 87 87 88 88 Default widgets are registered to render product option entry fields. 89 89 """ 90 grok.implements(IProductOption EntryField)90 grok.implements(IProductOptionField) 91 91 92 92 def __init__(self, **kw): 93 super(ProductOption EntryField, self).__init__(IProductOptionEntry, **kw)93 super(ProductOptionField, self).__init__(IProductOption, **kw) 94 94 return 95 95 96 # register IkobaObjectWidgets as default widgets for IProductOption EntryFields97 @grok.adapter(IProductOption EntryField, IBrowserRequest)96 # register IkobaObjectWidgets as default widgets for IProductOptionFields 97 @grok.adapter(IProductOptionField, IBrowserRequest) 98 98 @grok.implementer(IInputWidget) 99 def option_ entry_input_widget(obj, req):100 return IkobaObjectWidget(obj, req, ProductOption Entry)99 def option_input_widget(obj, req): 100 return IkobaObjectWidget(obj, req, ProductOption) 101 101 102 # register a display widget for IProductOption EntryFields103 @grok.adapter(IProductOption EntryField, IBrowserRequest)102 # register a display widget for IProductOptionFields 103 @grok.adapter(IProductOptionField, IBrowserRequest) 104 104 @grok.implementer(IDisplayWidget) 105 def option_ entry_display_widget(obj, req):106 return IkobaObjectDisplayWidget(obj, req, ProductOption Entry)105 def option_display_widget(obj, req): 106 return IkobaObjectDisplayWidget(obj, req, ProductOption) -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_batching.py
r12315 r12327 38 38 from waeup.ikoba.products.batching import ProductProcessor 39 39 from waeup.ikoba.products.product import Product 40 from waeup.ikoba.products.productoptions import ProductOption Entry40 from waeup.ikoba.products.productoptions import ProductOption 41 41 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase 42 42 … … 83 83 product = Product() 84 84 product.product_id = u'LIC' 85 options = ProductOption Entry()85 options = ProductOption() 86 86 options.title = u'Base Fee' 87 87 options.fee = Decimal('800.6') -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_browser.py
r12318 r12327 44 44 from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase 45 45 from waeup.ikoba.browser.tests.test_pdf import samples_dir 46 from waeup.ikoba.products.productoptions import ProductOption Entry46 from waeup.ikoba.products.productoptions import ProductOption 47 47 48 48 def lookup_submit_value(name, value, browser): … … 218 218 219 219 def test_product_options(self): 220 prodoptions = ProductOption Entry()220 prodoptions = ProductOption() 221 221 prodoptions.title = u'My option' 222 222 prodoptions.fee = Decimal('99.9') -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_productoptions.py
r12309 r12327 5 5 from zope.interface.verify import verifyObject, verifyClass 6 6 from zope.schema.interfaces import ConstraintNotSatisfied, WrongType 7 from waeup.ikoba.interfaces import IProductOption Entry, IProductOptionEntryField, IIkobaUtils8 from waeup.ikoba.products.productoptions import ProductOption Entry, ProductOptionEntryField7 from waeup.ikoba.interfaces import IProductOption, IProductOptionField, IIkobaUtils 8 from waeup.ikoba.products.productoptions import ProductOption, ProductOptionField 9 9 from waeup.ikoba.utils.utils import IkobaUtils 10 10 11 class ProductOption EntryTests(unittest.TestCase):11 class ProductOptionTests(unittest.TestCase): 12 12 13 13 def setUp(self): … … 26 26 def test_ifaces(self): 27 27 # make sure we implement the promised interfaces. 28 obj = ProductOption Entry()29 verifyObject(IProductOption Entry, obj)30 verifyClass(IProductOption Entry, ProductOptionEntry)28 obj = ProductOption() 29 verifyObject(IProductOption, obj) 30 verifyClass(IProductOption, ProductOption) 31 31 return 32 32 33 33 def test_init(self): 34 34 # we can pass initial values 35 item1 = ProductOption Entry()36 item2 = ProductOption Entry(35 item1 = ProductOption() 36 item2 = ProductOption( 37 37 self.valid_title, self.valid_fee, self.valid_currency) 38 38 self.assertTrue(item1.title is None) … … 46 46 def test_illegal_value(self): 47 47 # we do not accept values which do not meet the interface 48 item = ProductOption Entry()48 item = ProductOption() 49 49 self.assertRaises( 50 WrongType, ProductOption Entry, 6, 500, 'invalid')50 WrongType, ProductOption, 6, 500, 'invalid') 51 51 return 52 52 53 53 def test_to_string(self): 54 54 # the string representation is handy for export 55 item1 = ProductOption Entry()56 item2 = ProductOption Entry(55 item1 = ProductOption() 56 item2 = ProductOption( 57 57 self.valid_title, self.valid_fee, self.valid_currency) 58 58 self.assertEqual(item1.to_string(), u"(None, None, None)") … … 65 65 myinput = u"(u'%s',u'%s',u'%s')" % ( 66 66 self.valid_title, self.valid_fee, self.valid_currency) 67 item1 = ProductOption Entry.from_string(myinput)68 item2 = ProductOption Entry.from_string(u"(u'', u'', u'')")69 item3 = ProductOption Entry.from_string(u"(None, None, None)")67 item1 = ProductOption.from_string(myinput) 68 item2 = ProductOption.from_string(u"(u'', u'', u'')") 69 item3 = ProductOption.from_string(u"(None, None, None)") 70 70 self.assertEqual(item1.title, self.valid_title) 71 71 self.assertEqual(item1.fee, self.valid_fee) … … 79 79 return 80 80 81 class ProductOption EntryFieldTests(unittest.TestCase):81 class ProductOptionFieldTests(unittest.TestCase): 82 82 83 83 def test_ifaces(self): 84 84 # make sure we implement the promised interfaces. 85 obj = ProductOption EntryField()86 verifyObject(IProductOption EntryField, obj)87 verifyClass(IProductOption EntryField, ProductOptionEntryField)85 obj = ProductOptionField() 86 verifyObject(IProductOptionField, obj) 87 verifyClass(IProductOptionField, ProductOptionField) 88 88 return 89 89 -
main/waeup.ikoba/trunk/src/waeup/ikoba/utils/converters.py
r12309 r12327 30 30 from zope.schema.interfaces import IList 31 31 from waeup.ikoba.interfaces import ( 32 IObjectConverter, IProductOption EntryField, IFieldConverter,32 IObjectConverter, IProductOptionField, IFieldConverter, 33 33 DELETION_MARKER, IGNORE_MARKER) 34 34 from waeup.ikoba.schema.interfaces import IPhoneNumber 35 from waeup.ikoba.products.productoptions import ProductOption Entry35 from waeup.ikoba.products.productoptions import ProductOption 36 36 37 37 class ExtendedCheckBoxWidget(CheckBoxWidget): … … 175 175 return result 176 176 177 class ProductOption EntryConverter(grok.Adapter):178 grok.context(IProductOption EntryField)177 class ProductOptionConverter(grok.Adapter): 178 grok.context(IProductOptionField) 179 179 grok.implements(IFieldConverter) 180 180 181 181 def request_data(self, name, value, schema_field, prefix='', 182 182 mode='create'): 183 """Turn CSV values into ProductOption Entry-compatible form data.183 """Turn CSV values into ProductOption-compatible form data. 184 184 185 185 Expects as `value` a _string_ like ``(u'mytitle', … … 194 194 where the values are tokens from appropriate sources. 195 195 196 Such dicts can be transformed into real ProductOption Entryobjects by196 Such dicts can be transformed into real ProductOption objects by 197 197 input widgets used in converters. 198 198 """ 199 199 try: 200 entry = ProductOption Entry.from_string(value)200 entry = ProductOption.from_string(value) 201 201 title, fee, currency = entry.title, entry.fee, entry.currency 202 202 except: -
main/waeup.ikoba/trunk/src/waeup/ikoba/utils/tests/test_converters.py
r12309 r12327 38 38 SimpleIkobaVocabulary, IFieldConverter, 39 39 DELETION_MARKER, IGNORE_MARKER) 40 from waeup.ikoba.products.productoptions import ProductOption EntryField40 from waeup.ikoba.products.productoptions import ProductOptionField 41 41 from waeup.ikoba.utils.converters import ( 42 42 IObjectConverter, IFieldConverter, DefaultFieldConverter, 43 ListFieldConverter, PhoneNumberFieldConverter, ProductOption EntryConverter,43 ListFieldConverter, PhoneNumberFieldConverter, ProductOptionConverter, 44 44 DefaultObjectConverter) 45 45 from waeup.ikoba.utils.helpers import attrs_to_fields … … 94 94 options = schema.List( 95 95 title = u'Options', 96 value_type = ProductOption EntryField(),96 value_type = ProductOptionField(), 97 97 required = True, 98 98 default = [], … … 137 137 obj2 = ListFieldConverter(None) 138 138 obj3 = PhoneNumberFieldConverter(None) 139 obj4 = ProductOption EntryConverter(None)139 obj4 = ProductOptionConverter(None) 140 140 verify.verifyObject(IFieldConverter, obj1) 141 141 verify.verifyObject(IFieldConverter, obj2) … … 145 145 verify.verifyClass(IFieldConverter, ListFieldConverter) 146 146 verify.verifyClass(IFieldConverter, PhoneNumberFieldConverter) 147 verify.verifyClass(IFieldConverter, ProductOption EntryConverter)147 verify.verifyClass(IFieldConverter, ProductOptionConverter) 148 148 return 149 149 -
main/waeup.ikoba/trunk/src/waeup/ikoba/widgets/objectwidget.py
r12316 r12327 82 82 83 83 def _getView(self, request): 84 if self.context.schema.__name__ == 'IProductOption Entry':84 if self.context.schema.__name__ == 'IProductOption': 85 85 return IProductOptionWidgetDisplayView(self, request) 86 86 return IkobaObjectWidgetView(self, request)
Note: See TracChangeset for help on using the changeset viewer.