[web2py] Computed field not computed at INSERT ?

2014-12-19 Thread Mirek Zvolský
Web2py book says When a new record is modified, including both insertions and updates, if a value for the field is not provided, web2py tries to compute For me this works well after UPDATE from SQLFORM. However, when I use db.table.insert(sourcefieldforcomputed=value) computed field

[web2py] computed field and reference

2013-05-27 Thread Matteo Luperto
Hi, I want to compute a field based on the value of another field, which is a foreign key, in a way similar to: db.define_table('language', Field('language', 'string', required = True, unique = True, length = 64 ), format='%(language)s' ) db.define_table('problemsHere',

[web2py] Computed field date difference as integer

2013-05-19 Thread Zsolt Szabó
I like to store the difference as integer not char(512) db.define_table( 'mytable', Field('begin_date', type='date', requires=IS_DATE(format='%Y.%m.%d.')), Field('end_date', type='date', requires=IS_DATE(format='%Y.%m.%d.')), Field('difference', compute=lambda r:

[web2py] Computed field does not get updated when creating database entry

2012-08-22 Thread Daniel Gonzalez
Hi, I have defined a database table which has some fields which must be computed: agent_table = 'agent' db.define_table( agent_table, Field('email',unique=True), Field('agent_doc_id', length=128, compute=create_new_agent), Field('password', 'password',

[web2py] computed field

2012-04-20 Thread Annet
I defined a table eventList: db.define_table('EventList', ... Field('description',type='text'), Field('shortdescr',length=128,writable=False,readable=False), migrate=False) db.EventList.description.requires=IS_LENGTH(1536,error_message='length exceeds 1536 characters')

Re: [web2py] computed field

2012-04-20 Thread Richard Vézina
I think you can't use compute since you modify a field where the user as to enter something base on the len of user input, so I think you should transform the code below into function and use onvalidation=function x=len(form.vars.description) if x128: i=128 dots=... else: i=x-1

Re: [web2py] computed field

2012-04-20 Thread Richard Vézina
Also, you could maybe search the book with truncate keyword, there is already a utility if you just want to control the lenght of free text field or other string field. Richard On Fri, Apr 20, 2012 at 11:35 AM, Richard Vézina ml.richard.vez...@gmail.com wrote: I think you can't use compute

Re: [web2py] computed field

2012-04-20 Thread Richard Vézina
http://web2py.com/books/default/chapter/29/6 {{extend 'layout.html'}} h1Records/h1 {{=SQLTABLE(rows, headers='fieldname:capitalize', truncate=100, upload=URL('download')) }} Richard On Fri, Apr 20, 2012 at 11:42 AM, Richard Vézina ml.richard.vez...@gmail.com wrote: Also, you

[web2py] computed field question

2012-04-04 Thread Richard
Hello, I notice that in the book the example shown don't define a field type for compute. In that case web2py default seems to create a char var (512) type field. I had no problem with this for storing the computation of decimal result. It also works well if I define a proper field type, in my

Re: [web2py] Computed field not working

2012-02-29 Thread Richard Vézina
You can't access valor_do_dolar from custo_em_real lambda computed since it is a computed field that get computed un submit... If you want to do that you will have to make a real function that get process on submit with form.process().accepted and the argument onsuccess or onvalidation See

Re: [web2py] Computed field not working

2012-02-29 Thread Tito Garrido
Nice Catch, but I have commented the last field to apply what you suggested and this also doesn't work: db.define_table('compra_produto', Field('compra', 'reference compra'), Field('produto','reference produto'), Field('quantidade','integer'), Field('custo_em_dolar','double'),

Re: [web2py] Computed field not working

2012-02-29 Thread Richard Vézina
You valor_do_dolar field is still a problem in the model down here... Since you can't or your lambda can't accès valor_do_dolar in that example. The field don't exist in the form so the key not exist so web2py return none and custo_em_dolar*none will return none I guest. try this :

Re: [web2py] Computed field not working

2012-02-29 Thread Tito Garrido
Thanks a lot Richard! you were right! I have put the wrong field on the calculation! You are the best! Thank you! On Wed, Feb 29, 2012 at 6:25 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: You valor_do_dolar field is still a problem in the model down here... Since you can't or your

[web2py] Computed field

2011-12-21 Thread Jose Carlos Junior
People, How can I make the field NR_INDISPONIBILIDADE the table below (chamado) in a computed field with the difference between the field dates DT_FECHAMENTO and DT_ABERTURA. Thank you, db.define_table(chamados ,Field('ID_CHAMADOS',type='id',readable=False)

Re: [web2py] Computed field

2011-12-21 Thread Jim Steil
Here's what I would try: Field('difference', compute=lambda u: (u['DT_FECHAMENTO '] - u['DT_ABERTURA ']), label='Difference') This is untested. I haven't used compute fields based on a math function before, but like I said, this is what I'd try first. Hope this helps. -Jim On

[web2py] computed field or is_in_db(query...

2011-12-19 Thread Jose Carlos Junior
Please...I have some dificult in do this in web2py...as follow db.define_table(cidadao ,Field('CD_CIDADAO',type='id', label='Cidadão(PK)') ,Field('CD_MATRICULA',type='integer',notnull=True,label='Matrícula') ,Field('NM_CIDADAO',type='string',notnull=True,label='Nome') ,format =

Re: [web2py] computed field or is_in_db(query...

2011-12-19 Thread Richard Vézina
I have difficulty to understand your models because they are not in english (sorry about that)... I will try to help anyway... By the way you should put , at the end of your lines like this : Field('CD_CIDADAO',type='**string',notnull=True,label='**Matrícula')*,* instead of :

[web2py] computed field or is_in_db(query...

2011-12-19 Thread Nik Go
commas at the beginning of a line is not a common practice, but not necessarily a bad one. I use it myself, having been bitten by too many missing commas too often. ;) On Tuesday, December 20, 2011, Richard Vézina wrote: I have difficulty to understand your models because they are not in

[web2py] computed field: update and images

2011-11-28 Thread Pepe Araya
Hi!! I have 3 computed fields that call a resize_image function to make 3 versions of a uploaded image. The definition of one of these fields: Field('foto_portada_detalle', 'upload', uploadfolder=request.folder+'static/uploads/actividades', compute=lambda r: resize_image(r['foto_portada'],

[web2py] computed field won't hide when select...

2011-07-11 Thread Richard Vézina
Hello, I have this code in a select function that work in command line to display or not a computed field, so I can't figure out why it's not working in app... The computed field in red should not appear in grid view... CONTROLLER : elif auth.has_membership(auth.id_group('admin')):