[albatross-users] check boxes again.

Eric S. Johansson esj at harvee.org
Sat Jul 5 11:07:49 EST 2003


Gregory Bond wrote:

>>Q: how do I get a complete list of all checkboxes checked and unchecked just 
>>like you can with ordinary CGI
> 
> 
> Presumably, you get this list from the same place you get the list of all the 
> items you are adding to the form.  (i.e. you need exactly this information to 
> display the page in the first place, so it can't be that hard!!)

I do.  When I build the display list, I start out first by scanning the entire 
set of files in the spamtrap.  Then, I pass each file (containing a single 
e-mail message) to an object which extracts necessary information from the 
headers and if any errors occur, fill in with appropriate defaults.  This object 
defines" a line" in the display.

Each of these line objects are placed on a dictionary.  In the process of 
putting line objects in a dictionary, I build a another list (AKA sort list) 
containing token and some value to sort on.  After sorting, the top N entries 
are are extracted from the sort list and the token values are used to extract 
line objects from the dictionary.  These line objects are then placed on a list 
which is given to locals for use in the display template.  Simple as 3.14159.

> 
> 
>>what is the best way to store a chunk of data (i.e. a list) client side?
> 
> 
> If you add a variable to the session (with ctx.add_session_vars()), then it
> will be there for you next time the page_process() function is called. You can
> add (almost) any Python datatype to the session, so a vector of strings is
> easy.  This can be expensive in bandwith if you use client-side sessions,
> depending on how much data you add.  We use file-based server sessions with up
> to 100k of session data to do this sort of thing with no problems at all.

this is good to know.  It shouldn't be bad.  I only expect to see 20 or 30 20 
byte entries.

> 
> Perhaps the model you want is something like this (warning: untested):

thanks for the clue.  not only did it teach me more about when to use 
page_display and page_process, but it also gave me a clue on how to handle the data.

here's my working test fragment.  All_tokens is a complete list of all tokens 
entered into the display list.  Albatross_tokens is a list return by the 
checkbox list of checkboxes checked:

             for token in context.locals.all_tokens:
                 #syslog.syslog("working on %s"% token)
                 if token in context.locals.albatross_token:
                     syslog.syslog("token is spam %s"% token)
                 else:
                     syslog.syslog("token is NOT spam %s"% token)

cool thing is I get a usable data set and since the data set is expected to be 
in the sub 100 entry range, it shouldn't suck too bad.  The worst bit is 
processing every single piece of e-mail in the spamtrap for headers etc. I 
shudder to think how bad as it going to be when processing the dumpster (where 
spamtrap entries go to die) according to age.

tomorrow, I'm going to complete moving over the Bayesian discriminator 
correction code from ad hoc CGI to albatross and declare victory.

Many thanks to all you who have helped.  I could not have done without you and I 
hope my commentary helped improve documentation.  If there's interest, I will 
continue the cognitive disconnect series on subsequent chapters.

---eric






More information about the Albatross-users mailing list