SQLFORM and read-only references

85 views
Skip to first unread message

howesc

unread,
Jan 10, 2011, 6:44:33 PM1/10/11
to web...@googlegroups.com
It seems that in the latest version of web2py (1.91.6 and today's trunk) that if you have a table (say auth_user), with a format string, and then you refer to it in another table as read-only like:
  Field('updated_by', 'reference '+auth.settings.table_user_name,
        default=auth.user_id,update=auth.user_id,writable=False),

when the form is rendered we see 'None' rather than the format of the referenced table.  I can adjust the read-only field to have a represent like:
  Field('created_by', 'reference '+auth.settings.table_user_name,
        default=auth.user_id, writable=False,
        represent=lambda x: auth_user_table[x].first_name + " " + \
          auth_user_table[x].last_name+" ("+str(auth_user_table[x].id)+")" \
          if x else None),
(which matches my format string on my auth_user table).  Is this a regression, or was i making broken assumptions previously?

thanks,

christian

Massimo Di Pierro

unread,
Jan 10, 2011, 9:13:44 PM1/10/11
to web2py-users
Is this in appadmin or your own forms?

howesc

unread,
Jan 11, 2011, 11:22:33 AM1/11/11
to web...@googlegroups.com
my own forms created with SQLFORM.

howesc

unread,
Jan 18, 2011, 12:15:47 AM1/18/11
to web...@googlegroups.com
it seems that upon further testing this is not a problem.  i don't know what i was doing when this showed up.  sorry for the noise.

cfh

Pawel Jasinski

unread,
Jan 26, 2011, 11:37:54 AM1/26/11
to web2py-users
Hi,

I just hit the same problem and can reproduce in trivial case

in model:
db.define_table('foo', Field('x'))
db.define_table('bar', Field('label'), Field('ref',db.foo))

in controller:
def insertone():
id=db.foo.insert(x="xxx")
db.bar.insert(label="label",ref=id)

def index():
record=db.bar(id=1)
form=SQLFORM(db.bar,record,readonly=True)
if form.accepts(request.vars,session):
session.flash="accepted"
return dict(form=form)

this will produce 'None' on the ref field
if I change index to be:

def index():
record=db.bar(id=1)
db.bar.ref.represent=lambda val: db.foo[val].x
form=SQLFORM(db.bar,record,readonly=True)
if form.accepts(request.vars,session):
session.flash="accepted"
return dict(form=form)

everything is tiptop
web2py version: 1.91.6

Cheers,
Pawel

Massimo Di Pierro

unread,
Jan 26, 2011, 12:25:05 PM1/26/11
to web2py-users
I will double check because clearly something is wrong. Meanwhile, how
about this:

db.define_table('foo', Field('x'), format='%(x)s')
db.define_table('bar', Field('label'), Field('ref',db.foo))
in controller:
def insertone():
id=db.foo.insert(x="xxx")
db.bar.insert(label="label",ref=id)
def index():
record=db.bar(id=1)
form=SQLFORM(db.bar,record,readonly=True)
if form.accepts(request.vars,session):
session.flash="accepted"
return dict(form=form)

Pawel Jasinski

unread,
Jan 26, 2011, 1:40:57 PM1/26/11
to web2py-users
hi,

hi,
i had the same idea in a mean time. Same effect :-(
--pawel

On Jan 26, 6:25 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Massimo Di Pierro

unread,
Jan 26, 2011, 2:22:44 PM1/26/11
to web2py-users
Are you sure you want the form readonly? What id you remove readonly?
If you want readonly you do not need accepts

Pawel Jasinski

unread,
Jan 26, 2011, 4:48:52 PM1/26/11
to web2py-users
Hi,

> Are you sure you want the form readonly?
Yes

> What if you remove readonly?
The 'None' changes into drop down with ids or whatever is in the
format argument of the field.

> If you want readonly you do not need accepts
Good point, changed. It does not help with the main problem.

I also have another use case, where form is used on the confirmation
screen. Kind of "are you really sure ..."
All fields are made read only with db.table.filed.writable=False.
The references are also rendered as None.

Cheers,
Pawel

Kenneth

unread,
Feb 4, 2011, 7:46:44 AM2/4/11
to web2py-users
I´m having the same problem. In a SQLFORM I have a Field that is
sometimes writable and sometimes not. If you are admin you can modify
this field but not as user. Field is a reference to and other table,
so admin gets a dropdown but the user gets None but he should get the
selection that admin has made.


Kenneth

Juan Antonio

unread,
Feb 7, 2011, 5:46:23 AM2/7/11
to web2py-users
I have

db.define_table('article', Field('name'),....,format='%(name)s')
db.define_table('lote', Field('name'),...., Field('article',
db.article)
db.lote.article.requires = IS_IN_DB(db, db.article.id, '%(name)s')

And SQLFORM(db.lote,..,readonly=True) shows 'None' in field articulo

I think it is the same proble discussed here, or what am I doing
wrong?

I am using 1.91.6

Cheers,

Juan.

Massimo Di Pierro

unread,
Feb 7, 2011, 9:44:05 AM2/7/11
to web2py-users
Should be fixed in trunk already. Try the nightly built.

Juan Antonio

unread,
Feb 9, 2011, 5:09:06 AM2/9/11
to web2py-users
Yes, the nightly built works fine. Thanks.


On 7 feb, 15:44, Massimo Di Pierro <massimo.dipie...@gmail.com> wrote:
> Should be fixed in trunk already. Try the nightly built.
>
> On Feb 7, 4:46 am, Juan Antonio <juanr...@gmail.com> wrote:
>
> > I have
>
> > db.define_table('article', Field('name'),....,format='%(name)s')
> > db.define_table('lote', Field('name'),...., Field('article',
> > db.article)
> > db.lote.article.requires = IS_IN_DB(db, db.article.id, '%(name)s')
>
> > AndSQLFORM(db.lote,..,readonly=True) shows 'None' in field articulo
>
> > I think it is the same proble discussed here, or what am I doing
> > wrong?
>
> > I am using 1.91.6
>
> > Cheers,
>
> > Juan.
>
> > On 4 feb, 13:46, Kenneth <kenneth.t.lundst...@gmail.com> wrote:
>
> > > I´m having the same problem. In aSQLFORMI have a Field that is
> > > sometimes writable and sometimes not. If you are admin you can modify
> > > this field but not as user. Field is a reference to and other table,
> > > so admin gets a dropdown but the user gets None but he should get the
> > > selection that admin has made.
>
> > > Kenneth
>
> > > On Jan 26, 11:48 pm, Pawel Jasinski <pawel.jasin...@gmail.com> wrote:
>
> > > > Hi,
>
> > > > > Are you sure you want the formreadonly?
>
> > > > Yes
>
> > > > > What if you removereadonly?
>
> > > > The 'None' changes into drop down with ids or whatever is in the
> > > > format argument of the field.
>
> > > > > If you wantreadonlyyou do not need accepts
>
> > > > Good point, changed. It does not help with the main problem.
>
> > > > I also have another use case, where form is used on the confirmation
> > > > screen. Kind of "are you really sure ..."
> > > > All fields are maderead onlywith db.table.filed.writable=False.
> > > > Thereferencesare also rendered as None.
>
> > > > Cheers,
> > > > Pawel
Reply all
Reply to author
Forward
0 new messages