You might have to do both, if there is a way to determine if the script is being called, then use compute, and if it is a form submission use the onvalidation of the form.
-Thadeus On Wed, Feb 17, 2010 at 6:31 AM, JAY <[email protected]> wrote: > Hi, > > yes i think it is an requirement... > because in my scenario the input for the first field is entered either > by user via the form or by an script which only inserts this single > value and the other field vlaues should be automatic generated by the > functions in my Model. > > But may i be wrong? and there is another way to do this? > > The way from above works for automatic operations: > def _compute(): > return request.vars.field1.split(" ")[:1] > > Field("field2", "string", compute=_compute) > > But as i said, its not visible in the form for the user..... > > Thanks, > JAY > > On 17 Feb., 13:00, Tiago Almeida <[email protected]> wrote: >> Why does everything need to work from model? Is it some requirement? >> Can't you do a function that takes the form and implements that logic? you >> can probably make it so that you pass that function to the onvalidation (or >> something like that) of the form.accepts.. >> >> Regards, >> Tiago >> ---- >> >> On Wed, Feb 17, 2010 at 11:07 AM, JAY <[email protected]> wrote: >> > Execute functions in Model >> >> > Hi Guys, >> >> > first i´ve to say i am n(oob)ew to Python and Database things, so >> > please be patient. >> >> > Is there any general way to execute custom functions in Model, which >> > not only validate and how to implement them? >> >> > I´ll try to explain with a few examples: >> >> > First the simple one: >> >> > I have a table with 2 fields: >> > db.define_table("table1", >> > Field("field1", "string"), >> > Field("field2", "string")) >> >> > field1 is required so there should be two options: >> > 1. the user enters something in field1 and field2 >> > 2. the user enters something in field1 and leaves field2 blank >> >> > In the second case i want to use a function that takes the value from >> > field1 splits the first word and then stores it in field2. >> > something like: >> > def function(): >> > field1_value="word1 word2 word3" >> > valuesplit= field1_value.split(" ")[:1] >> > joinvalue= " ".join(valuesplit) >> > return joinvalue >> >> > Everthing should work from model... >> >> > I have already tried the solution from the thread "Populate field >> > based no other fields": >> > def _compute(): >> > return request.vars.field1 >> >> > Field("field2", "string", compute=_compute >> >> > It works but field2 wont be visible in appadmin. >> >> > Second Example: >> >> > I have 2 tables with 2 fields: >> > db.define_table("table1", >> > Field("field1", "string"), >> > Field("field2", "string")) >> >> > db.define_table("table2", >> > Field("field1", "string"), >> > Field("field2", "string")) >> >> > Now user enters value in table1.field1 >> > then funktion should split first part of the value >> > then looking up if value is present in table2.field1 (.like(%value)) >> > and if true store the table2.field2 value in table1.field2 >> >> > Can anybuddy help? >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "web2py-users" group. >> > To post to this group, send email to [email protected]. >> > To unsubscribe from this group, send email to >> > [email protected]<web2py%[email protected]> >> > . >> > For more options, visit this group at >> >http://groups.google.com/group/web2py?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" 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/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" 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/web2py?hl=en.

