def test_clean(self): inner = forms.DecimalField() f = LookupTypeField(inner, [('gt', 'gt'), ('lt', 'lt')], required=False) self.assertEqual( f.clean(['12.34', 'lt']), Lookup(to_d(12.34), 'lt')) self.assertEqual( f.clean([]), Lookup(value=None, lookup_type='exact'))
def test_clean(self): inner = forms.DecimalField() f = LookupTypeField(inner, [('gt', 'gt'), ('lt', 'lt')], required=False) self.assertEqual( f.clean(['12.34', 'lt']), Lookup(to_d(12.34), 'lt')) self.assertEqual( f.clean([]), Lookup(value=None, lookup_type='exact'))
def field(self): if not hasattr(self, '_field'): if self.lookup_type is None or isinstance(self.lookup_type, (list, tuple)): if self.lookup_type is None: lookup = [(x, x) for x in LOOKUP_TYPES] else: lookup = [(x, x) for x in LOOKUP_TYPES if x in self.lookup_type] self._field = LookupTypeField(self.field_class( required=self.required, widget=self.widget, **self.extra), lookup, required=self.required, label=self.label) else: self._field = self.field_class(required=self.required, label=self.label, widget=self.widget, **self.extra) return self._field
def test_render_used_html5(self): inner = forms.DecimalField() f = LookupTypeField(inner, [('gt', 'gt'), ('lt', 'lt')]) self.assertHTMLEqual(f.widget.render('price', ''), """ <input type="number" step="any" name="price_0" /> <select name="price_1"> <option value="gt">gt</option> <option value="lt">lt</option> </select>""") self.assertHTMLEqual(f.widget.render('price', ['abc', 'lt']), """ <input type="number" step="any" name="price_0" value="abc" /> <select name="price_1"> <option value="gt">gt</option> <option selected="selected" value="lt">lt</option> </select>""")
def test_clean(self): inner = forms.DecimalField() f = LookupTypeField(inner, [('gt', 'gt'), ('lt', 'lt')]) self.assertEqual(f.clean(['12.34', 'lt']), [to_d(12.34), 'lt'])
def test_field(self): inner = forms.DecimalField() f = LookupTypeField(inner, [('gt', 'gt'), ('lt', 'lt')]) self.assertEqual(len(f.fields), 2)
def test_clean(self): inner = forms.DecimalField() f = LookupTypeField(inner, [('gt', 'gt'), ('lt', 'lt')]) self.assertEqual( f.clean(['12.34', 'lt']), [to_d(12.34), 'lt'])