Massimo,

Maybe the problem with .compute in my table is that implements "audit trail'
pattern (web2pyslices). I don't know how 'compute' works, but the fact of
'audit trail' tables the id is not unique can make it fail.


thanks for the help, but the proposed solution  returns a invalid sintax

Error traceback

1.
2.
3.
4.
5.
6.
7.

Traceback (most recent call last):
  File "gluon/restricted.py", line 171, in restricted
  File "D:/servico/web2py/applications/convenios/controllers/convenios.py"
<http://127.0.0.1:8000/admin/default/edit/convenios/controllers/convenios.py>,
line 215
    if form.accepts(request.vars, session,onvalidation=lambda form:
form.vars.valor_total = form.vars.valor_custeio_concedente +
form.vars.valor_investimento_concedente +
form.vars.valor_custeio_contrapartida +
form.vars.valor_investimento_contrapartida):

                   ^
SyntaxError: invalid syntax


However,

             row = db((db.cronograma_desembolso.id == form.vars.id) &
(db.cronograma_desembolso.active==True)).select()[0]
             total = row.valor_custeio_concedente +
row.valor_investimento_concedente + row.valor_custeio_contrapartida +
row.valor_investimento_contrapartida
             row.update_record(valor_total = total)

works with audit trail



2010/1/14 mdipierro <mdipie...@cs.depaul.edu>

> OK. You can also do:
>
>       if form.accepts(request.vars, session,
> onvalidation=lambda form: form.vars.valor_total =
> form.vars.valor_custeio_concedente +
> form.vars.valor_investimento_concedente +
> form.vars.valor_custeio_contrapartida +
> form.vars.valor_investimento_contrapartida):
>
> which is 2 db queries less.
>
> On Jan 14, 2:42 pm, Alexandre Andrade <alexandrema...@gmail.com>
> wrote:
> > Solved without jquery
> >
> >        if form.accepts(request.vars, session):
> >              row = db.cronograma_desembolso[form.vars.id]
> >              total = row.valor_custeio_concedente +
> > row.valor_investimento_concedente + row.valor_custeio_contrapartida +
> > row.valor_investimento_contrapartida
> >              row.update_record(valor_total = total)
> >
> > 2010/1/14 mdipierro <mdipie...@cs.depaul.edu>
> >
> >
> >
> > > Try Field('total','double') (compute=None, writable=True,
> > > readable=True) and
> >
> > > jQuery("input[name='quantity'],input[name='price']").keyup(function()
> > > {
> > > jQuery("input[name='total']").val(parseFloat(jQuery("input
> > > [name='price']").val())*parseInt(jQuery("input[name='quantity']"));
> > > });
> >
> > > Use firebug in to debug the JS. compute should not be used if the
> > > field is shown.
> >
> > > On Jan 14, 2:18 pm, Alexandre Andrade <alexandrema...@gmail.com>
> > > wrote:
> > > > 1. The total is not showed when editing. I don't need in this moment.
> > > When I
> > > > set .compute, its hide (like writable=False and readable=False) the
> field
> > > in
> > > > the form.
> > > > 2. the main problem is .compute is not inserting/updating the field
> on
> > > db,
> > > > and neither acting as represent when showing
> >
> > > > 2010/1/14 mdipierro <mdipie...@cs.depaul.edu>
> >
> > > > > I see the problem. I can find a way around it but I feel it would
> be
> > > > > wrong.
> >
> > > > > When you submit a form, what you see is what should go in the DB,
> even
> > > > > if some fields are readonly.
> >
> > > > > If you have quantity, price and total you should not display the
> same
> > > > > total that is in DB before submission as readonly, because has you
> > > > > change quantity or price the total should change but it does not.
> To a
> > > > > user this is confusing. To the user it looks like they submit a
> form
> > > > > with the wrong total (the previous one, not the one reflacing the
> > > > > change in the other fields).
> >
> > > > > You should not use compute.
> >
> > > > > You should use JS
> >
> > > > > <script>
> > > > >
> jQuery("input[name='quantity'],input[name='price']").change(function()
> > > > > {
> > > > > jQuery("input[name='total']").val(parseFloat(jQuery("input
> > > > > [name='price']").val())*parseInt(jQuery("input[name='quantity']"));
> > > > > });
> > > > > </script>
> >
> > > > > when use a custom validator to make sure the user did not mess up
> this
> > > > > field somehow.
> > > > > there are many options.
> >
> > > > > On Jan 14, 12:57 pm, Alexandre Andrade <alexandrema...@gmail.com>
> > > > > wrote:
> > > > > > It don't show at form, without readable=False.
> >
> > > > > > I set readable=False, but it don't show the updated value.
> >
> > > > > > 2010/1/14 mdipierro <mdipie...@cs.depaul.edu>
> >
> > > > > > > Can you also try set readable=False?
> >
> > > > > > > On Jan 14, 9:52 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > > > > > > > Make sure Field(...,default=None, update=None)
> >
> > > > > > > > On Jan 14, 9:47 am, Alexandre Andrade <
> alexandrema...@gmail.com>
> > > > > > > > wrote:
> >
> > > > > > > > > db.order_detail.total.compute=lambda r: r['qtd']*r['price']
> >
> > > > > > > > > don't work on updates
> >
> > > > > > > > > 2010/1/14 mdipierro <mdipie...@cs.depaul.edu>
> >
> > > > > > > > > > with 1.74.5 and later you only need
> >
> > > > > > > > > > db.order_detail.total.compute=lambda r:
> r['qtd']*r['price']
> >
> > > > > > > > > > On Jan 14, 8:51 am, Alexandre Andrade <
> > > alexandrema...@gmail.com>
> > > > > > > > > > wrote:
> > > > > > > > > > > What is the best solution to automatically calculate a
> > > total
> > > > > field?
> >
> > > > > > > > > > > db.define_table ('order_detail',
> > > > > > > > > > >               Field('product_name'),
> > > > > > > > > > >               Field('qtd', 'integer'),
> > > > > > > > > > >               Field('price', 'integer'),
> > > > > > > > > > >               Field('total', 'integer', writable=False)
> > > > > > > > > > > )
> >
> > > > > > > > > > > Where  total = qtd * price
> >
> > > > > > > > > > > requires and a custom validator? how to do?
> > > > > > > > > > > onvalidation on form? how to do?
> >
> > > > > > > > > > > --
> > > > > > > > > > > Atenciosamente
> >
> > > > > > > > > > > --
> > > > > > > > > > > =========================
> > > > > > > > > > > Alexandre Andrade
> > > > > > > > > > > Hipercenter.com
> >
> > > > > > > > > > --
> > > > > > > > > > You received this message because you are subscribed to
> the
> > > > > Google
> > > > > > > Groups
> > > > > > > > > > "web2py-users" group.
> > > > > > > > > > To post to this group, send email to
> web2py@googlegroups.com
> > > .
> > > > > > > > > > To unsubscribe from this group, send email to
> > > > > > > > > > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> >
> > > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> >
> >
> > > > > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> >
> > > <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> <web2py%25252bunsubscr...@googlegroups.com<web2py%2525252bunsubscr...@googlegroups.com>
> >
> >
> > > > > > > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> >
> > > <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> <web2py%25252bunsubscr...@googlegroups.com<web2py%2525252bunsubscr...@googlegroups.com>
> >
> >
> > > > > <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> <web2py%25252bunsubscr...@googlegroups.com<web2py%2525252bunsubscr...@googlegroups.com>
> >
> > > <web2py%25252bunsubscr...@googlegroups.com<web2py%2525252bunsubscr...@googlegroups.com>
> <web2py%2525252bunsubscr...@googlegroups.com<web2py%252525252bunsubscr...@googlegroups.com>
> >
> >
> > > > > > > > > > .
> > > > > > > > > > For more options, visit this group at
> > > > > > > > > >http://groups.google.com/group/web2py?hl=en.
> >
> > > > > > > > > --
> > > > > > > > > Atenciosamente
> >
> > > > > > > > > --
> > > > > > > > > =========================
> > > > > > > > > Alexandre Andrade
> > > > > > > > > Hipercenter.com
> >
> > > > > > > --
> > > > > > > You received this message because you are subscribed to the
> Google
> > > > > Groups
> > > > > > > "web2py-users" group.
> > > > > > > To post to this group, send email to web...@googlegroups.com.
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> >
> > > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> >
> >
> > > > > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> >
> > > <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> <web2py%25252bunsubscr...@googlegroups.com<web2py%2525252bunsubscr...@googlegroups.com>
> >
> >
> > > > > > > .
> > > > > > > For more options, visit this group at
> > > > > > >http://groups.google.com/group/web2py?hl=en.
> >
> > > > > > --
> > > > > > Atenciosamente
> >
> > > > > > --
> > > > > > =========================
> > > > > > Alexandre Andrade
> > > > > > Hipercenter.com
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "web2py-users" group.
> > > > > To post to this group, send email to web...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> >
> > > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> <web2py%252bunsubscr...@googlegroups.com<web2py%25252bunsubscr...@googlegroups.com>
> >
> >
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/web2py?hl=en.
> >
> > > > --
> > > > Atenciosamente
> >
> > > > --
> > > > =========================
> > > > Alexandre Andrade
> > > > Hipercenter.com
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "web2py-users" group.
> > > To post to this group, send email to web...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/web2py?hl=en.
> >
> > --
> > Atenciosamente
> >
> > --
> > =========================
> > Alexandre Andrade
> > Hipercenter.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to
> web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/web2py?hl=en.
>
>
>
>


-- 
Atenciosamente

-- 
=========================
Alexandre Andrade
Hipercenter.com
--
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

Reply via email to