[albatross-users] revisiting checkboxes..

Eric S. Johansson esj at harvee.org
Thu Jun 26 13:26:34 EST 2003


Andrew McNamara wrote:

> Albatross evaluates the resulting name and compares it to the value
> attribute (or evaluated expr/valueexpr) and adds a "checked" attribute
> if they're equal:

I was able to follow the documentation that much.  ;-)

> 
>     >>> import albatross
>     >>> ctx = albatross.SimpleContext('.')
>     >>> ctx.locals.foo = 'yes'
>     >>> ctx.locals.name = 'foo'
>     >>> albatross.Template(ctx, '<magic>', '''<al-input type="checkbox" nameexpr="name" value="yes">''').to_html(ctx)
>     >>> ctx.flush_content()
>     <input type="checkbox" name="foo" value="yes" checked>
> 
> On submission, all the inputs are merged back into ctx.locals. If the
> checkbox is checked, it's value will be whatever the value attribute
> resolves to, if not checked, it's None (from memory).
> 
> So, in the above example, on submission, you would have a variable
> ctx.locals.foo with value 'yes' or None (I think 8-).

this leaves me with (yet another) question.  How do you treat ctx.locals as a 
dictionary/array/whatever makes the easiest to programmatically create entries 
and search on them?  I remember experimenting very early on and it didn't seem 
like __getattr__ and family were present.  Am I just too sleep fogged?

I've been playing around with locals.__dict__  to try and get a feel for what's 
there and at least I can see all of my spamtrap tokens but I wasn't able to 
access them as .local.xxx variables.

  for entry in context.locals.__dict__:
             if entry.find("token") <>-1:
                 syslog.syslog(entry)

yielded:

Jun 25 23:16:42 harvee python2: token925b7d685d2747dd
Jun 25 23:16:42 harvee python2: token9acb26b0dcde7145
Jun 25 23:16:42 harvee python2: token5c78e77ec4cf7748
Jun 25 23:16:42 harvee python2: tokenf2952773fad60176
Jun 25 23:16:42 harvee python2: token633a2b50bd966ad9
Jun 25 23:16:42 harvee python2: token3dc7b80d66e03957
Jun 25 23:16:42 harvee python2: tokenb7a6bc91fa70ef0e
Jun 25 23:16:42 harvee python2: token6212922bbc33af37
Jun 25 23:16:42 harvee python2: token3da28ecf416b681a
Jun 25 23:16:42 harvee python2: token4ca8f5cf8e5b1aee
Jun 25 23:16:42 harvee python2: tokena1b2f2392f7958dd
Jun 25 23:16:42 harvee python2: token18110da55c4e9755
Jun 25 23:16:42 harvee python2: token35894754db05026f
Jun 25 23:16:42 harvee python2: token9b8659411055405c
Jun 25 23:16:42 harvee python2: tokenaeed365de824afd6
Jun 25 23:16:42 harvee python2: token2e782e94ab7b6d0a

I definitely need some sleep.  I'm up early in the morning to take care of an 
elderly aunt in our early summer heat and go purchase her air-conditioning.

---eric





More information about the Albatross-users mailing list