--- a/web/formfields.py Mon Dec 21 19:45:24 2009 +0100
+++ b/web/formfields.py Mon Dec 21 19:52:21 2009 +0100
@@ -13,6 +13,7 @@
from logilab.mtconverter import xml_escape
from logilab.common.decorators import cached
+from yams.schema import KNOWN_METAATTRIBUTES
from yams.constraints import (SizeConstraint, StaticVocabularyConstraint,
FormatConstraint)
@@ -570,6 +571,7 @@
def process_form_value(self, form):
return int(Field.process_form_value(self, form))
+
class BooleanField(Field):
widget = Radio
@@ -581,6 +583,7 @@
def process_form_value(self, form):
return bool(Field.process_form_value(self, form))
+
class FloatField(IntField):
def format_single_value(self, req, value):
formatstr = req.property_value('ui.float-format')
@@ -594,6 +597,7 @@
def process_form_value(self, form):
return float(Field.process_form_value(self, form))
+
class DateField(StringField):
format_prop = 'ui.date-format'
widget = DateTimePicker
@@ -613,6 +617,7 @@
date = form.parse_date(wdgdate, 'Date')
return date
+
class DateTimeField(DateField):
format_prop = 'ui.datetime-format'
@@ -625,6 +630,7 @@
date = form.parse_datetime(date, 'Datetime')
return date
+
class TimeField(DateField):
format_prop = 'ui.time-format'
widget = TextInput
@@ -639,16 +645,6 @@
return time
class RelationField(Field):
- # XXX (syt): iirc, we originaly don't sort relation vocabulary since we want
- # to let entity.unrelated_rql control this, usually to get most recently
- # modified entities in the select box instead of by alphabetical order. Now,
- # we first use unrelated_rql to get the vocabulary, which may be limited
- # (hence we get the latest modified entities) and we can sort here for
- # better readability
- #
- # def __init__(self, **kwargs):
- # kwargs.setdefault('sort', False)
- # super(RelationField, self).__init__(**kwargs)
@staticmethod
def fromcardinality(card, **kwargs):
@@ -657,7 +653,6 @@
def vocabulary(self, form):
entity = form.edited_entity
- req = entity._cw
# first see if its specified by __linkto form parameters
linkedto = entity.linked_to(self.name, self.role)
if linkedto:
@@ -767,7 +762,7 @@
kwargs['max_length'] = cstr.max
return StringField(**kwargs)
if fieldclass is FileField:
- for metadata in ('format', 'encoding', 'name'):
+ for metadata in KNOWN_METAATTRIBUTES:
metaschema = eschema.has_metadata(rschema, metadata)
if metaschema is not None:
kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,