Issue #90 new

Subclassed formencode validators do not pass check in tw2.core.widget.Widget

created an issue

I have a custom validator that is a sub-class of a formencode validator. I am getting the error "Validator must be either a tw2 or FormEncode validator".

Class in question: {{{


from formencode.validators import UnicodeString, Validator

class MarkupConverter(UnicodeString): def init(self, kw): UnicodeString.__init__(self, kw)

cleaner = re.compile(r'(\s*<br />\s*)+$').sub
def _to_python(self, value, state=None):
    value = super(MarkupConverter, self)._to_python(value, state)
    if value:
        value = Markup(stripentities(value)).unescape()
        return self.cleaner('', value)


Relavent Stack Trace: {{{


File '/home/greg/Environments/tosca/lib/python2.7/site-packages/tw2.tinymce-2.0.b1dev_20110706-py2.7.egg/tw2/tinymce/', line 1 in <module> from widgets import * File '/home/greg/Environments/tosca/lib/python2.7/site-packages/tw2.tinymce-2.0.b1dev_20110706-py2.7.egg/tw2/tinymce/', line 30 in <module> class Tinymce(TextArea): File '/home/greg/Environments/tosca/lib/python2.7/site-packages/tw2/core/', line 47 in new w.post_define.im_func(widget) File '/home/greg/Environments/tosca/lib/python2.7/site-packages/tw2/core/', line 133 in post_define raise pm.ParameterError("Validator must be either a tw2 or FormEncode validator") ParameterError: Validator must be either a tw2 or FormEncode validator


Comments (3)

  1. paj repo owner

    I think this is because you are passing it a class instead of an instance. Are you doing the following? validator = MarkupConverter

    If so, this will fix it: validator = MarkupConverter()

    I wonder if we should have tw automatically do this for you?

  2. megamahi reporter

    Yup that fixed it.

    To give context, I'm porting a TW1 widget to TW2. TW1 seemed to of accepted just the class rather than an instance so having it accept both would be ideal. Even if that doesn't get changed, the error message should be as it was a little ambiguous as to what the issue was until I dove into the source code.

  3. Log in to comment