[Twisted-web] How to pass invisible values with annotate.TypedInterface

Michael Wilson michael.wilson at gmail.com
Sat Dec 25 01:09:03 MST 2004


I took your advice, but I've run into a snag:

My URLs look like this: "/admin/" is a menu of options,
"/admin/edit/2" is, as you suggest, a page to edit something with an
id of 2. The code looks something like this:

class Admin(rend.page):
def locateChild(self, ctx, childsegments):
  function, id = map(str, childSegments)
  if function == "edit":
    return Edit(id), []


class Edit(rend.page):

class IEdit(annotate.TypedInterface):
    def edit(
        ctx = annotate.Context(),
        name = annotate.String(required=True, label="Name",
          requiredFailMessage="Please enter the name")

        Please enter information. """
    edit = annotate.autocallable(edit)

class Edit(rend.Page):
    """Render a custom and normal form for an ISomething.
    __implements__ = IEditSchool, rend.Page.__implements__
    addSlash = False
    child_webform_css = webform.defaultCSS
    def __init__(self,  id):
      self.id = int(float(id))
   docfactory = webform.renderForms()[aform]

The problem is this: when the child form is redered, the post URL is
"edit/freeform_post!!edit", rather than "./freeform_post!edit", as it
is when I don't use locateChild.

Second, the post is getting routed through the parent's locateChild,
and I'm not quite sure what to do with the "freeform_post".

I can provide a more complete example, but it's very puzzling. I think
what I need to do is:

1. Get the form post URL to NOT include the parent(s), and/or
2. Get the form post routed correctly to the child's code (which is
where the form came from anyway).

Any ideas? 

P.S. Merry Christmas/Happy Holidays/etc :-)

On Fri, 24 Dec 2004 13:35:56 +0000, Matt Goodall <matt at pollenation.net> wrote:
> On Fri, 2004-12-24 at 00:35 -0800, Michael Wilson wrote:
> > My forms are modeled after the examples in examples/customform.py, and
> > I try and use this standard form definition in multiple places.
> >
> > In some cases, I would like to pass an invisible value with the form.
> > I know of two ways to do this:
> >
> > 1. By adding arguments to the form URL (
> > action="./freeform_post!!doSomething?myarg1=...")
> > 2. By adding invisible fields to the form.
> >
> > What's the best way to do this?
> >
> > P.S. I've looked at the examples and the code, can't find the answer.
> The renderer annotate.String tests for a hidden attribute. You can use
> that to include a hidden field, i.e. foo=annotate.String(hidden=True).
> However, hidden fields are not often that useful; perhaps you could make
> better use of the URL?
> A common use of hidden form fields is to include some object id in the
> form so that, when the form is posted, you get the id back again. If
> that's why you want a hidden field then you should seriously look at
> using a URL like "http://foo.com/news/1" instead of
> "http://foo.com/news?id=1". Request parameters are not a good way to
> identify resources, IMHO.
> Of course, if you have a different use case for a hidden form field then
> please post an example. Perhaps it's something that formless/webform
> should support in a more obvious way.
> Cheers, Matt

More information about the Twisted-web mailing list