Re: [web2py] Re: New 'represent' syntax

2011-09-02 Thread Johann Spies
On 26 August 2011 17:07, Martín Mulone mulone.mar...@gmail.com wrote:

 To debug the problem, start passing one by one the fields:


The following models work:

db.define_table('journal',
Field('title'),
Field('issn'),
Field('subject'),
Field('heading'),
)

db.define_table('article',
Field('title'),
Field('year'),
Field('journal', type = 'reference journal'),
Field('authors', 'list:reference'))

and as soon as I add ',
  requires = IS_IN_DB('journal_id', 'title)%s',
  zero = None)

to the field 'journal' in the table 'article' I get

File /home/js/web2py/applications/isi_proef/models/isi.py
http://localhost:8000/admin/default/edit/isi_proef/models/isi.py,
line 13, in module
zero = None)),
  File /home/js/web2py/gluon/validators.py, line 385, in __init__
(ktable, kfield) = str(self.field).split('.')
ValueError: need more than 1 value to unpack


It is a bit frustrating to guess what should be done.  Is there
documentation somewhere?

Regards
Johann
-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Re: New 'represent' syntax

2011-09-02 Thread Johann Spies
Sorry,

   requires = IS_IN_DB('journal_id', 'title)%s',
   zero = None)


must be
requires = IS_IN_DB(db,'journal_id', '%(title)s',
  zero = None)),

With the same result.
Johann

-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Re: New 'represent' syntax

2011-09-02 Thread Anthony
On Friday, September 2, 2011 10:47:42 AM UTC-4, spyker wrote:

 On 26 August 2011 17:07, Martín Mulone mulone...@gmail.com wrote:

 To debug the problem, start passing one by one the fields:


 The following models work:

 db.define_table('journal',
 Field('title'),
 Field('issn'),
 Field('subject'),
 Field('heading'),
 )

 db.define_table('article',
 Field('title'),
 Field('year'),
 Field('journal', type = 'reference journal'),
 Field('authors', 'list:reference'))

 and as soon as I add ',
   requires = IS_IN_DB('journal_id', 'title)%s',
   zero = None)

 to the field 'journal' in the table 'article' I get 

 File /home/js/web2py/applications/isi_proef/models/isi.py 
 http://localhost:8000/admin/default/edit/isi_proef/models/isi.py, line 13, 
 in module

 zero = None)),
   File /home/js/web2py/gluon/validators.py, line 385, in __init__

 (ktable, kfield) = str(self.field).split('.')
 ValueError: need more than 1 value to unpack


 It is a bit frustrating to guess what should be done.  Is there 
 documentation somewhere?

 Regards
 Johann
 -- 
  May grace and peace be yours in abundance through the full knowledge of 
 God and of Jesus our Lord!  His divine power has given us everything we need 
 for life and godliness through the full knowledge of the one who called us 
 by his own glory and excellence. 
 2 Pet. 1:2b,3a


Shouldn't it be IS_IN_DB(db, 'journal.id', ...) -- note 'journal.id' rather 
than 'journal_id'? Also, your list:reference has to refer to a referenced 
table.

Anthony 


Re: [web2py] Re: New 'represent' syntax

2011-09-02 Thread Johann Spies
 Shouldn't it be IS_IN_DB(db, 'journal.id', ...) -- note 'journal.id'
 rather than 'journal_id'? Also, your list:reference has to refer to a
 referenced table.


Well spotted!  Thanks.  That  was my mistake.

Regards
Johann


-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Re: New 'represent' syntax

2011-08-26 Thread Johann Spies
Thanks.

It will be very helpful if somebody can update these lines in the book
because  it still not clear to me how to use the new syntax in each of these
instances.  I still do not know how 'record' is defined here.

db.mytable.name.represent = lambda name: name.capitalize()

db.mytable.other_id.represent = lambda id: db.other(id).myfield


db.mytable.some_uploadfield.represent = lambda value: \


A http://web2py.com/book/default/docstring/A('get it', _href=URL
http://web2py.com/book/default/docstring/URL('download',
args=value))


I have no idea how to use 'record' e.g. in your example of the new grid:

db.dog.owner.represent = lambda x,record: db.person[x].name

is not correct

Regards
Johann
-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Re: New 'represent' syntax

2011-08-26 Thread Martín Mulone
db.dog.owner.represent = lambda value, row: db.person(value).name

Value is the value of the current field, in this example dog owner is
an id of the person for example 1, so to display person name I have
to pass this value to search a person with this id:
db.person(value).name.

Row is the all row of the current record, perhaps for this example is
not need it. But for example suppose I have to list dogs name blast
his age.


db.dog.name.represent = lambda value, row: '%s (%s)'%(value, row.age)

Result:

Name
---
doggy (2)
gog (12)



2011/8/26 Johann Spies johann.sp...@gmail.com

 Thanks.

 It will be very helpful if somebody can update these lines in the book
 because  it still not clear to me how to use the new syntax in each of these
 instances.  I still do not know how 'record' is defined here.

 db.mytable.name.represent = lambda name: name.capitalize()


 db.mytable.other_id.represent = lambda id: db.other(id).myfield



 db.mytable.some_uploadfield.represent = lambda value: \



 A http://web2py.com/book/default/docstring/A('get it', _href=URL 
 http://web2py.com/book/default/docstring/URL('download', args=value))



 I have no idea how to use 'record' e.g. in your example of the new grid:

 db.dog.owner.represent = lambda x,record: db.person[x].name

 is not correct

 Regards
 Johann
 --
  May grace and peace be yours in abundance through the full knowledge of
 God and of Jesus our Lord!  His divine power has given us everything we need
 for life and godliness through the full knowledge of the one who called us
 by his own glory and excellence.
 2 Pet. 1:2b,3a




-- 
 http://martin.tecnodoc.com.ar


Re: [web2py] Re: New 'represent' syntax

2011-08-26 Thread Martín Mulone
Another thing when you are using SQLFORM.grid and .smartgrid this notation
is required:

db.dog.owner.represent = lambda value, row: db.person(value).name

*because this notation raise an error:*


db.dog.owner.represent = lambda value: db.person(value).name

(take this in consideration or you are going to get mad)

2011/8/26 Martín Mulone mulone.mar...@gmail.com

 db.dog.owner.represent = lambda value, row: db.person(value).name

 Value is the value of the current field, in this example dog owner is an id 
 of the person for example 1, so to display person name I have to pass this 
 value to search a person with this id: db.person(value).name.

 Row is the all row of the current record, perhaps for this example is not 
 need it. But for example suppose I have to list dogs name blast his age.


 db.dog.name.represent = lambda value, row: '%s (%s)'%(value, row.age)

 Result:

 Name
 ---
 doggy (2)
 gog (12)



 2011/8/26 Johann Spies johann.sp...@gmail.com

 Thanks.

 It will be very helpful if somebody can update these lines in the book
 because  it still not clear to me how to use the new syntax in each of these
 instances.  I still do not know how 'record' is defined here.

 db.mytable.name.represent = lambda name: name.capitalize()



 db.mytable.other_id.represent = lambda id: db.other(id).myfield




 db.mytable.some_uploadfield.represent = lambda value: \




 A http://web2py.com/book/default/docstring/A('get it', _href=URL 
 http://web2py.com/book/default/docstring/URL('download', args=value))




 I have no idea how to use 'record' e.g. in your example of the new grid:


 db.dog.owner.represent = lambda x,record: db.person[x].name


 is not correct

 Regards
 Johann
 --
  May grace and peace be yours in abundance through the full knowledge of
 God and of Jesus our Lord!  His divine power has given us everything we need
 for life and godliness through the full knowledge of the one who called us
 by his own glory and excellence.
 2 Pet. 1:2b,3a




 --
  http://martin.tecnodoc.com.ar




-- 
 http://martin.tecnodoc.com.ar


Re: [web2py] Re: New 'represent' syntax

2011-08-26 Thread Johann Spies
Hallo Martín,

Thanks for your reply.

Unfortunately the problem persists:

I have in Massimo's demo code for the SQLFORM.smartgrid/grid:

def index():
db.define_table('person',Field('name'),format='%(name)s')

db.define_table('dog',Field('name'),Field('owner',db.person),format='%(name)s')
db.define_table('comment',Field('body'),Field('dog',db.dog))
#db.dog.owner.represent = lambda x, record: db.person(x).name
db.dog.owner.represent = lambda value, row: db.person(value).name

and I still get:

TypeError: lambda() takes exactly 2 arguments (1 given)


This is a bit frustrating and I have wasted a lot of time trying to get it
to work.

Regards
Johann

-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Re: New 'represent' syntax

2011-08-26 Thread Bruno Rocha
Do you have some field.of type list:... ?

I am having trouble with it in grid.

http://zerp.ly/rochacbruno
Em 26/08/2011 10:54, Johann Spies johann.sp...@gmail.com escreveu:
 Hallo Martín,

 Thanks for your reply.

 Unfortunately the problem persists:

 I have in Massimo's demo code for the SQLFORM.smartgrid/grid:

 def index():
 db.define_table('person',Field('name'),format='%(name)s')


db.define_table('dog',Field('name'),Field('owner',db.person),format='%(name)s')
 db.define_table('comment',Field('body'),Field('dog',db.dog))
 #db.dog.owner.represent = lambda x, record: db.person(x).name
 db.dog.owner.represent = lambda value, row: db.person(value).name

 and I still get:

 TypeError: lambda() takes exactly 2 arguments (1 given)


 This is a bit frustrating and I have wasted a lot of time trying to get it
 to work.

 Regards
 Johann

 --
 May grace and peace be yours in abundance through the full knowledge of
God
 and of Jesus our Lord! His divine power has given us everything we need
for
 life and godliness through the full knowledge of the one who called us by
 his own glory and excellence.
 2 Pet. 1:2b,3a


Re: [web2py] Re: New 'represent' syntax

2011-08-26 Thread Martín Mulone
To debug the problem, start passing one by one the fields:

fields = [db.dog.id,
  db.dog.owner
  ]

SQLFORM.grid(
...
fields=fields,
...
)



2011/8/26 Bruno Rocha rochacbr...@gmail.com

 Do you have some field.of type list:... ?

 I am having trouble with it in grid.

 http://zerp.ly/rochacbruno
 Em 26/08/2011 10:54, Johann Spies johann.sp...@gmail.com escreveu:

  Hallo Martín,
 
  Thanks for your reply.
 
  Unfortunately the problem persists:
 
  I have in Massimo's demo code for the SQLFORM.smartgrid/grid:
 
  def index():
  db.define_table('person',Field('name'),format='%(name)s')
 
 
 db.define_table('dog',Field('name'),Field('owner',db.person),format='%(name)s')
  db.define_table('comment',Field('body'),Field('dog',db.dog))
  #db.dog.owner.represent = lambda x, record: db.person(x).name
  db.dog.owner.represent = lambda value, row: db.person(value).name
 
  and I still get:
 
  TypeError: lambda() takes exactly 2 arguments (1 given)
 
 
  This is a bit frustrating and I have wasted a lot of time trying to get
 it
  to work.
 
  Regards
  Johann
 
  --
  May grace and peace be yours in abundance through the full knowledge of
 God
  and of Jesus our Lord! His divine power has given us everything we need
 for
  life and godliness through the full knowledge of the one who called us by
  his own glory and excellence.
  2 Pet. 1:2b,3a




-- 
 http://martin.tecnodoc.com.ar


[web2py] Re: New 'represent' syntax

2011-08-25 Thread Massimo Di Pierro
You just change this:

def rp(author):
an =
db(db.akb_reprint.uuid==author).select(db.akb_reprint.rp_author)
if len(an):
a_name = an.first()['rp_author']
else:
a_name = 'No rp_author'
return a_name

into this:

def rp(author,record):
an =
db(db.akb_reprint.uuid==author).select(db.akb_reprint.rp_author)
if len(an):
a_name = an.first()['rp_author']
else:
a_name = 'No rp_author'
return a_name

or

def rp(author,record):
row =
db(db.akb_reprint.uuid==author).select(db.akb_reprint.rp_author).first()
return row and row.rp_author or 'No author'

and use it as

db.akb_articles.rp_author.represent = rp


In this case you would not need record.

On Aug 25, 6:39 am, Johann Spies johann.sp...@gmail.com wrote:
 Please help me to understand how to use the new syntax.  How do I have to
 change the following code to work?

 def rp(author):
     an =  db(db.akb_reprint.uuid==author).select(db.akb_reprint.rp_author)
     if len(an):
         a_name = an.first()['rp_author']
     else:
         a_name = 'No rp_author'
     return a_name

 db.akb_articles.rp_author.represent = lambda x,record: rp(x),record

 How do I define and use 'record' in this case?

 The ticket says:

  db.akb_articles.rp_author.represent = lambda x,record: rp(x),record
 NameError: name 'record' is not defined

 Regards
 Johann

 --
  May grace and peace be yours in abundance through the full knowledge of God
 and of Jesus our Lord!  His divine power has given us everything we need for
 life and godliness through the full knowledge of the one who called us by
 his own glory and excellence.
                                                     2 Pet. 1:2b,3a