On Sun, Sep 27, 2009 at 11:32 AM, cd34 <[email protected]> wrote:
>
> I originally posted this in toscawidgets-discuss, but, in looking a
> little further, the error occurs in core.py in Pylons, but, I am not
> quite sure where to start poking.
>
> import tw.forms as twf
> movie_form = twf.TableForm('movie_form', action='save', children=[
...
>
> class TestController(BaseController):
>
> def index(self, **kw):
> tmpl_context.form = movie_form
> return render('/test_test.mako')
>
> �...@validate(movie_form, error_handler=index)
> def save(self, **kw):
> return str(kw)
>
> results in:
>
> URL: http://test:8080/test/save
...
> File '/var/www/pylons/lib/python2.5/site-packages/Pylons-0.9.7-
> py2.5.egg/pylons/controllers/core.py', line 160 in _dispatch_call
> action_method = action.replace('-', '_')
> AttributeError: 'function' object has no attribute 'replace'
>
> If I disable validation, the form is able to post and does return kw
> on the screen.
The validate args seem to be wrong, though I'm not sure because I've
only used ToscaWidgets once. The normal syntax is
@validate(schema=MY_FORMENCODE_SCHEMA, form="index")
You're passing the TW form instead of the schema, and you're not
setting 'form'. 'form' is normally the name of the action that
displays the form. 'error_handler' is not a validate argument, so
it's passed to ``htmlfill.render()`` However, the argument is not
defined there either so I would expect a TypeError when you call it.
Is this a current ToscaWidgets/Pylons tutorial? There have been
problems with obsolete tutorials being left around before. The
@validate args seem to be wrong, but I've only used ToscaWidgets once
a year ago.
There is one place in validate where it recursively dispatches.
However, I'm not sure it's related to this problem because validate
does not appear in the traceback. Lines 155-161 in
pylons/decorators/__init__.py) are:
# If there's no form supplied, just continue with the current
# function call.
if not form:
return func(self, *args, **kwargs)
request.environ['pylons.routes_dict']['action'] = form
response = self._dispatch_call()
This says if there's no 'form' argument, call the wrapped function
(the original action) and return. Otherwise change the action to the
'form' arg and dispatch to it. In your case, I would expect 'form' to
be None. But maybe it's a function somehow?
You can introspect the function object in the interactive traceback.
If we know what the function is, that may help explain how it got
there. Try ``vars(action)`` and ``action.__name__``, and
``action.func_name``.
You can also insert "raise RuntimeError" just before the dispatch call
to verify whether this code path is being executed.
--
Mike Orr <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---