No problem. For this interested, in trunk, you can now do:
rows = db(query).select()
repr_row = rows.repr(0)
The .repr() method of the Rows object takes an index and returns a copy of
the indexed row, but for fields with "represent" attributes, the
"represent" function is applied to the value in the row. If you don't
specify an index, you get a generator to iterate over all the rows:
for row in rows.repr():
print row.myfield
Can also be applied to slices:
for row in rows[0:10].repr():
print row.myfield
Note, you should take the slice of the Rows object first, and then apply
the .repr() method, as you cannot slice a generator.
If you only want to transform selected fields via their "represent"
attribute (e.g., some fields may have expensive "represent" functions
involving database hits, so you want to avoid running those functions), you
can list them in the "fields" argument:
repr_row = row.repr(0, fields=[db.mytable.myfield])
Note, because .repr() returns a transformed copy of the original Row,
there's no .update_record() (which you wouldn't want anyway) or
.delete_record() methods for the row.
Also, there has been some discussion of changing the name of this method to
avoid confusion with the Python built-in repr() function, so consider this
experimental for now.
Anthony
On Friday, June 21, 2013 4:45:17 PM UTC-4, anonymouse wrote:
>
> :D
>
> Looks good! I'll have to check out trunk and try it out.
>
> Thanks for the answers (makes me feel like I'm getting pretty good with
> web2py) and especially for the code!
>
> -C
>
> On Thursday, 20 June 2013 22:08:27 UTC-5, Anthony wrote:
>>
>> FYI, see possible solution here:
>> https://groups.google.com/d/msg/web2py-developers/kMMG1wH6Xxg/pCYZfJGHVckJ
>>
>> Anthony
>>
>> On Thursday, June 20, 2013 8:22:54 PM UTC-4, Anthony wrote:
>>>
>>>
>>> Not a bad idea. Maybe have a look at how SQLTABLE and SQLFORM.grid (both
>>>> in gluon.sqlhtml.py) handle field representation. Very simply, we
>>>> might add a method to the Row class allowing something like:
>>>>
>>>> row.represent('myfield')
>>>>
>>>
>>> Actually, Row objects don't know about their db/table, so you'd have to
>>> pass that in somehow. Rows objects do know their db, so it would be easier
>>> for an entire Rows object.
>>>
>>> Anthony
>>>
>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.