Alberto Valverde <[EMAIL PROTECTED]> writes:

> What I think you're trying to accomplish is to have a list of records  
> in a form and update them all at once when the form is POSTed, right?

What I want is creating "on demand" structures so that users can fill
information.  In this case, this is a price table and it will list all
analysis that can be done to samples.  The idea is getting all analysis from
the database, filling their ID as part of the field name and then doing the
classification on urgent and normal price.

As I said, I used to rely on something like

   8:preco_rotina = value            (standard price for analysis with id 8)
   8:preco_urgente = value           (urgent price for analysis with id 8)
   9:preco_rotina = value
   9:preco_urgente = value
  17:preco_rotina = value
  17:preco_urgente = value

     segmento = value    (hidden field)
     price_table = value (hidden field)

then after getting the hidden fields values, I deleted their entries from the
dictionary I got, sort()ed its keys, split()ed the name at ':', the first part
was the ID, the second part the type of price and then I got the value.  This
is also what I use to dynamically create a table of "n" samples (where the
user tells me how many samples he'll input).  Sharing this code made things
easier -- there are at least 10 pages where I need something like this -- and
solved the problem perfectly for myself.

> Good news is that the filter used to decode the flat dict of request  
> parameters into a nested structure supports the decoding into lists  
> too (look for NestedVariables here http://formencode.org/ 
> Validator.html). This could let you write something like:
>
> form = Form(fields=[
>       RepeatingFieldSet("rotina", repeat=10, fields=[
>                 HiddenField("id", validator=Int()),
>                 TextField("preco", validator=MoneyValidator()),
>                  ...
>           ])
>
> And then at your controller:
>
> def controllermeth(self, rotina):
>       assert rotina == [{'id':45, 'preco':1234}, {'id':74, 'preco': 
> 4321},....]

I don't know beforehand if there will be prices for everything -- there are
three separate tables on the database involved in this specific module.  But,
I could make things less dynamic and count it.  Or I can use some AJAX to
create everything here... 

> Bad news is that that a "repeating" widget which you could use for  
> this is *not* implemented yet.

Hmm...  I see... :-(  I believe, then, that I'll have to resort to JavaScript
again. :-(  To bad that I have to remove this logic from Python.

> If you really *need* to have a "name" overriding field you could try  
> using a custom TextField:

I need to distinguish one pair of fields from another and I use their name to
find out to what they are referring to.  I can have one, two, 300 pairs here
and all of them should be processed at the same time on submit (actually they
are sequentially processed). 

I don't need their names, but I need to distinguish each pair and to what they
are associated with. 

> class MyTextField(TextField):
>       template_vars = ["name"]

And how would I make this 'name' dynamic?  Or I'd have to instantiate 600
textfields before displaying the page to the user?

> I haven't tested it but it will not play nice inside comopund widgets  
> (like FieldSet) and is not recommended.

So I can't use the same solution I used to use before?  :-(  This is really
bad to me since I counted on that to make a hell lot of code simpler.  As I
said, I use that on at least 10 pages... 


-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to