[albatross-users] Form Field Value Storage Changed?

Dave Cole djc at object-craft.com.au
Tue Jan 14 10:57:21 EST 2003


>>>>> "Michael" == Michael Barrett <mike at daboyz.org> writes:

Michael> Ok, after doing a little troubleshooting based on what you
Michael> told me below I've found that it seems to be the fault of the
Michael> <al-form> tags.  IE: what you said below seems to be the
Michael> culprit.  When there's an __albform__ field in the req then
Michael> it does a whole lot of stuff that I haven't even started to
Michael> try to understand.

It tries to do a few things which simplify your code.  If you have a
form which looks like this:

        <form>
         <input name="field1">
         <input name="field2">
        </form>

and the user only supplies input to field1 then the browser will not
mention field2 in the request.

When you use <al-form> and <al-input> the form will get an additional
hidden field called __albform__ which describes the content of the
form which was sent to the browser.  Upon reception of the request
Albatross decodes the __albform__ and does the following:

1) Any field not present in the browser request is set to None in
   ctx.locals.  This allows you to assume that all field in the form
   as always present, even if they have the value None.

2) If you had multiple instances of field2 in the form, Albatross will
   always return the value of field2 as a list.  This saves you from
   having to constantly write code like this:

        if hasattr(ctx.locals, 'field2'):
            if type(ctx.locals.field2) is type([]):
                # something
            else:
                # something
        else:
            # something

   you are able to just do this:

        for value in ctx.locals.field2:
            # something

Michael> Does anyone know why this is?  Is there supposed to be a time
Michael> and a place (such as mine) when you shouldn't be using
Michael> <al-form> instead of just <form> calls?

If you use <form> and <input> then the request merging will be merge
all fields presented by the browser.  This might be what you want.

The reason why Albatross uses <al-*> tags is purely for performance
reasons.  The template parser treats all template content as plain
text which is delimited by <al-*> tags.  The alternative would have a
huge performance impact --- all of a sudden every tag, attribute, and
value would be a new Python object.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list