I think I do not understant your options very well,

but now I am working on the way I mentioned.

My SQLTABLE receives a parameter called rd (represent dictionary) and I can
pass any string with placeholders and fields to fetch the value.

I dont want to change the 'represent' at the model level, because I need
different represent to forms and tables,
I think it is better to define an exclusive represent dictionary to use in
SQLTABLE that do not affects the representation in forms.

I will create a slice as soon as I finish that.

2010/12/9 mdipierro <[email protected]>

> Other options:
>
> 1)
>
> db.table.field.represent=lambda row='row': ...
>
> if field.represent.func_defaults[0]=='row': ...
>
>
> 2)
>
> db.table.field.represent=lambda row={}: ...
>
> if isinstance(field.represent.func_defaults[0],dict): ...
>
> 3)
>
> if field.represent.func_code.co_varnames[0]=='row': ...
>
>
>
>
>
> this is used in SQLTABLE, FIELD, crud.read, crud.update.
>
> Massimo
>
> On Dec 8, 11:58 pm, Bruno Rocha <[email protected]> wrote:
> > 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 Rochahttp://about.me/rochacbruno/bio
>



-- 

Bruno Rocha
http://about.me/rochacbruno/bio

Reply via email to