On Nov 5, 2010, at 12:11 PM, villas wrote:
> 
> @Jonathan
> I think you are right about the /<function>/<table>/<id> convention
> for SQLTABLE linkto.
> But by using linkto=URL() I should be able specify whichever URL I
> want rather than have to work around an unnecessary convention?

Probably not, at least not the way I read SQLTABLE. I'm not certain, but I 
think that in your example, this is the way SQLTABLE is generating the href:

                        href = '%s/%s/%s' % (linkto, tablename, r_old)

Since linkto is the result of URL(), it'll have the function name, and the 
above logic is always appending the table name to it (r_old is, I assume, the 
id, but maybe not).

That line of code is part of this:

                elif linkto and field.type == 'id':
                    try:
                        href = linkto(r, 'table', tablename)
                    except TypeError:
                        href = '%s/%s/%s' % (linkto, tablename, r_old)
                    r = A(r, _href=href)

(I'm not 100% sure how r gets built, but as you see it's the link text, so you 
should be able to look and see what it is.)

It looks like you can make linkto a lambda function, in which case you'll have 
complete control over the href.

> 
> @Richard
> I played around a little,  but I couldn't make that work for me, but
> maybe I'm missing something.
> 
> On Nov 5, 6:33 pm, Jonathan Lundell <jlund...@pobox.com> wrote:
>> On Nov 5, 2010, at 11:00 AM, villas wrote:
>> 
>> 
>> 
>>> Does SQLTABLE  linkto work properly?
>> 
>>> If I use:
>>> SQLTABLE(mytablerows,linkto=URL())
>> 
>>> I get URLs  like this:   myapp/default/mytable/mytable/id
>> 
>>> Note the duplication of "mytable".
>> 
>> I wonder if this is really a "duplication". As web2py interprets a URL, the 
>> first mytable is a function name, and the second (in this case) is a table 
>> name, right? They happen to have the same name here.
>> 
>> (That said, SQLTABLE's linkto logic is distinctly non-trivial; I'm not at 
>> all sure what's going on in several of the cases.)
>> 
>>> I have tried with URL('mytable')  and URL(f='mytable'),  but it's the
>>> same.
>> 
>>> Of course I can work around the issue specifying:
>>>    db.mytable.id.represent = lambda id:
>>> A('edit:',id,_href=URL(args=(id)))
>> 
>>> ...which gives the URL that I expect,  but that is not the question
>>> here...
>> 
>>> --D
>> 
>> 


Reply via email to