I am overriding SQLTABLE class, here is my idea, let me know if this is a
stupid idea :P
I want to pass to SQLTABLE a represent_dictionary which I call 'rd', so if I
have a table:
<table>
db.define_table('person',
Field('name'),
Field('city'),
Field('state'),
Field('email')
)
</table>
My rd will be:
<code>
rd =
dict(person.email={'repr_string':A(_href=URL('changemail',vars=dict(person_id='%s'))),
'fetch':'person.id'})
# I want to pass rd to SQLTABLE
<code>
mytable = SQLTABLE(Rows,rd=rd)
</code>
Now in SQLTABLE for each column name, I will check if there is a entry for
this key in 'rd', if True:
<code>
for i,row in enumerate(sqlrows):
field.represent = rd[columnname]['repr_string'] % row[rd['fetch']]
</code>
This way, I can always pass a dict containing a string with placeholders to
override the represent for any column in the table, and this dict will
contains which column value will be fetched for every row.
I am making some tests, I just need a way to include some html tags
including another field values, as ID for every column.
Is that a stupid idea? :P
Thanks
epresent: lambda row:
2010/12/9 mdipierro <[email protected]>
> Sorry. Cannot be done this way. Represent takes the field value, not
> the entire row.
> The reason is that when web2py tries to represent a field in a
> SQLTABLE or in a FORM, only that field is guaranteed to be there. the
> other fields may not have been fetched from the database.
>
> Anyway... I will think this can be improved.
> Let us know if you have any idea.
>
> Massimo
>
> On Dec 8, 10:13 pm, Bruno Rocha <[email protected]> wrote:
> > I Know this is an VERY OLD post, but I was searching the group and I
> > now have the same need as weheh in this thread.
> >
> > db.define_table('person',
> > Field('name'),
> > Field('city'),
> > Field('state'),
> > Field('email',represent: lambda row:
> > A(_href=URL('changemail',vars=dict(person_id=row.id))))
> > )
> >
> > But, lambda in this case is getting row as str() with the mail adress
> > stored in 'email' field, I need to have the row id.
> >
> > another easy way?
> >
> > I am thinking about override the SQLTABLE class to include this kind of
> > option if I can't find an easy solution.
>
--
Bruno Rocha
http://about.me/rochacbruno/bio