# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1239126745 -7200 # Node ID 53f35db66f8863df795857c6733e93da0d1713dd # Parent 94a5c30575c07cac7c0a6c9633e6387456943dfa raise specific exception diff -r 94a5c30575c0 -r 53f35db66f88 web/form.py --- a/web/form.py Tue Apr 07 19:51:35 2009 +0200 +++ b/web/form.py Tue Apr 07 19:52:25 2009 +0200 @@ -178,8 +178,13 @@ allfields.append(field) classdict['_fields_'] = allfields return super(metafieldsform, mcs).__new__(mcs, name, bases, classdict) + - +class FieldNotFound(Exception): + """raised by field_by_name when a field with the given name has not been + found + """ + class FieldsForm(FormMixIn, AppRsetObject): __metaclass__ = metafieldsform __registry__ = 'forms' @@ -221,6 +226,7 @@ @iclassmethod def field_by_name(cls_or_self, name, role='subject'): + """return field with the given name and role""" if isinstance(cls_or_self, type): fields = cls_or_self._fields_ else: @@ -228,7 +234,7 @@ for field in fields: if field.name == name and field.role == role: return field - raise Exception('field %s not found' % name) + raise FieldNotFound(name) @iclassmethod def remove_field(cls_or_self, field):