--- a/web/form.py Thu Feb 19 21:35:27 2009 +0100
+++ b/web/form.py Thu Feb 19 21:36:22 2009 +0100
@@ -279,6 +279,10 @@
class FileInput(Input):
type = 'file'
+
+ def _render_attrs(self, form, field):
+ name = form.context[field]['name'] # qualified name
+ return name, None, {}
class HiddenInput(Input):
type = 'hidden'
@@ -293,7 +297,10 @@
return tags.textarea(value, name=name)
return tags.textarea(value, name=name, **attrs)
-class Select:
+class Select(FieldWidget):
+ def __init__(self, vocabulary=()):
+ self.vocabulary = ()
+
def render(self, form, field):
name, value, attrs = self._render_attrs(form, field)
if self.vocabulary:
@@ -308,9 +315,8 @@
return tags.select(name=name, options=options)
return tags.select(name=name, options=options, **attrs)
-class CheckBox: pass
-class Radio: pass
+class CheckBox(FieldWidget):
class DateTimePicker: pass
@@ -376,17 +382,25 @@
self.min = min
self.max = max
-class FloatField(IntField):
+class FloatField(IntField):
+ def format_value(self, req, value):
+ formatstr = entity.req.property_value('ui.float-format')
+ if value is None:
+ return u''
+ return formatstr % float(value)
+
+class DateField(StringField):
+ propname = 'ui.date-format'
def format_value(self, req, value):
- if value is not None:
- return ustrftime(value, req.property_value('ui.float-format'))
- return u''
+ return value and ustrftime(value, req.property_value(self.propname)) or u''
-class DateField(IntField):
+class DateTimeField(DateField):
+ propname = 'ui.datetime-format'
+
- def format_value(self, req, value):
- return value and ustrftime(value, req.property_value('ui.date-format')) or u''
+class FileField(StringField):
+ needs_multipart = True
class HiddenInitialValueField(Field):
def __init__(self, visible_field, name):
@@ -506,7 +520,8 @@
kwargs.setdefault('id', 'entityForm')
super(EntityFieldsForm, self).__init__(*args, **kwargs)
self.fields.append(TextField(name='__type', widget=HiddenInput))
- self.fields.append(TextField(name='eid', widget=HiddenInput))
+ self.fields.append(TextField(name='eid', widget=HiddenInput,
+ eidparam=False))
def form_render(self, entity, **values):
self.entity = entity