35 '''''''''''' |
35 '''''''''''' |
36 |
36 |
37 .. autoclass:: cubicweb.web.formfields.StringField() |
37 .. autoclass:: cubicweb.web.formfields.StringField() |
38 .. autoclass:: cubicweb.web.formfields.PasswordField() |
38 .. autoclass:: cubicweb.web.formfields.PasswordField() |
39 .. autoclass:: cubicweb.web.formfields.IntField() |
39 .. autoclass:: cubicweb.web.formfields.IntField() |
|
40 .. autoclass:: cubicweb.web.formfields.BigIntField() |
40 .. autoclass:: cubicweb.web.formfields.FloatField() |
41 .. autoclass:: cubicweb.web.formfields.FloatField() |
41 .. autoclass:: cubicweb.web.formfields.BooleanField() |
42 .. autoclass:: cubicweb.web.formfields.BooleanField() |
42 .. autoclass:: cubicweb.web.formfields.DateField() |
43 .. autoclass:: cubicweb.web.formfields.DateField() |
43 .. autoclass:: cubicweb.web.formfields.DateTimeField() |
44 .. autoclass:: cubicweb.web.formfields.DateTimeField() |
44 .. autoclass:: cubicweb.web.formfields.TimeField() |
45 .. autoclass:: cubicweb.web.formfields.TimeField() |
828 # file modified using a text widget |
829 # file modified using a text widget |
829 return Binary(value.encode(self.encoding(form))) |
830 return Binary(value.encode(self.encoding(form))) |
830 return super(EditableFileField, self)._process_form_value(form) |
831 return super(EditableFileField, self)._process_form_value(form) |
831 |
832 |
832 |
833 |
833 class IntField(Field): |
834 class BigIntField(Field): |
834 """Use this field to edit integers (`Int` yams type). This field additionaly |
835 """Use this field to edit big integers (`BigInt` yams type). This field |
835 support `min` and `max` attributes that specify a minimum and/or maximum |
836 additionaly support `min` and `max` attributes that specify a minimum and/or |
836 value for the integer (`None` meaning no boundary). |
837 maximum value for the integer (`None` meaning no boundary). |
837 |
838 |
838 Unless explicitly specified, the widget for this field will be a |
839 Unless explicitly specified, the widget for this field will be a |
839 :class:`~cubicweb.web.formwidgets.TextInput`. |
840 :class:`~cubicweb.web.formwidgets.TextInput`. |
840 """ |
841 """ |
|
842 default_text_input_size = 10 |
|
843 |
841 def __init__(self, min=None, max=None, **kwargs): |
844 def __init__(self, min=None, max=None, **kwargs): |
842 super(IntField, self).__init__(**kwargs) |
845 super(BigIntField, self).__init__(**kwargs) |
843 self.min = min |
846 self.min = min |
844 self.max = max |
847 self.max = max |
|
848 |
|
849 def init_widget(self, widget): |
|
850 super(BigIntField, self).init_widget(widget): |
845 if isinstance(self.widget, fw.TextInput): |
851 if isinstance(self.widget, fw.TextInput): |
846 self.widget.attrs.setdefault('size', 5) |
852 self.widget.attrs.setdefault('size', self.default_text_input_size) |
847 self.widget.attrs.setdefault('maxlength', 15) |
|
848 |
853 |
849 def _ensure_correctly_typed(self, form, value): |
854 def _ensure_correctly_typed(self, form, value): |
850 if isinstance(value, basestring): |
855 if isinstance(value, basestring): |
851 value = value.strip() |
856 value = value.strip() |
852 if not value: |
857 if not value: |
854 try: |
859 try: |
855 return int(value) |
860 return int(value) |
856 except ValueError: |
861 except ValueError: |
857 raise ProcessFormError(form._cw._('an integer is expected')) |
862 raise ProcessFormError(form._cw._('an integer is expected')) |
858 return value |
863 return value |
|
864 |
|
865 |
|
866 class IntField(BigIntField): |
|
867 """Use this field to edit integers (`Int` yams type). Similar to |
|
868 :class:`~cubicweb.web.formfields.BigIntField` but set max length when text |
|
869 input widget is used (the default). |
|
870 """ |
|
871 default_text_input_size = 5 |
|
872 |
|
873 def init_widget(self, widget): |
|
874 super(IntField, self).init_widget(widget): |
|
875 if isinstance(self.widget, fw.TextInput): |
|
876 self.widget.attrs.setdefault('maxlength', 15) |
859 |
877 |
860 |
878 |
861 class BooleanField(Field): |
879 class BooleanField(Field): |
862 """Use this field to edit booleans (`Boolean` yams type). |
880 """Use this field to edit booleans (`Boolean` yams type). |
863 |
881 |
1206 'Bytes': FileField, |
1224 'Bytes': FileField, |
1207 'Password': PasswordField, |
1225 'Password': PasswordField, |
1208 |
1226 |
1209 'Boolean': BooleanField, |
1227 'Boolean': BooleanField, |
1210 'Int': IntField, |
1228 'Int': IntField, |
|
1229 'BigInt': BigIntField, |
1211 'Float': FloatField, |
1230 'Float': FloatField, |
1212 'Decimal': StringField, |
1231 'Decimal': StringField, |
1213 |
1232 |
1214 'Date': DateField, |
1233 'Date': DateField, |
1215 'Datetime': DateTimeField, |
1234 'Datetime': DateTimeField, |