On Oct 21, 2010, at 6:25 PM, ron_m wrote:
> 
> I would like to clarify one thing for my own work in this area. If I
> take one of the menu lines out of the "Edit" menu in the Welcome
> application menu.py as an example the URL for item Controller is
> 
> URL('admin', 'default', 'edit/%s/controllers/%s.py' \
>     % (request.application,request.controller=='appadmin' and
>     'default' or request.controller))),
> 
> then that is application admin, controller default and then function
> and args are put together in a formatted string.
> 
> I presume that is safe because all apache and routes magic would apply
> before application in the final "path to resource" the browser will
> get and come back with on the next request. I think there is no strong
> requirement to distinguish function and args because only web2py logic
> will act on that part of the path. I pass everything intended as an
> address through URL() in the application I am working on.

Rewrite is called at the very end, so it doesn't usually matter how you put it 
together. args is treated somewhat differently from the function, in that it's 
urllib.quote'd, but that won't make a difference here. If it did, you could 
also write:

URL('admin', 'default', 'edit', args=[request.application, 'controllers', 
    '%s.py' % request.controller=='appadmin' and 'default' or 
request.controller])

The effect would be the same, unless (as is not the case here) quoting args 
made a difference.

Minor point: I don't think there's any need to escape the newline inside parens.

> 
> Thanks, sorry to extend the discussion if it is clear to everyone
> else.
> 
> Ron
> 
> 
> On Oct 21, 8:03 am, mdipierro <[email protected]> wrote:
>> I think it is very important to use URL and not hard-code any url.
>> 
>> If you deploy the app under apache for example, in a subfolder, you
>> need to add the /subfoldername/ prefix to all paths. It will break all
>> urls. URL and routes will take care of this.
>> 
>> On Oct 21, 9:38 am, Jonathan Lundell <[email protected]> wrote:
>> 
>>> On Oct 20, 2010, at 11:18 PM, ron_m wrote:
>> 
>>>> Certainly the way you describe is in the book and is right, what I
>>>> suggest is something I have done that works. However it could be one
>>>> of things that bites later because I am depending on the current
>>>> mapping of args to additional path elements and am essentially
>>>> bypassing what the API should be doing for me. I need to reconsider
>>>> how I am doing this part of my menus - still learning this framework.
>>>> Being a former Java head and for a while PHP it sure is nice to work
>>>> with both Python and web2py.
>> 
>>>> Thanks for the pointer.
>> 
>>> It's largely a matter of style. The only compelling reason to use URL() at 
>>> all is if you're rewriting your URLs via routes.py. In that case, URL does 
>>> the outgoing rewrites. Otherwise, it's just a helper, and the only reason 
>>> to use the flavor I suggested is for readability. If you're not doing 
>>> rewrites, you could just as well say:
>> 
>>> '/appname/default/products/used'
>> 
>>> or
>> 
>>> '/%s/default/products/used' % request.application
>> 
>>> if you don't want to embed the appname into the code.
>> 
>>> But you (or someone else) might want to add rewriting later on, for some 
>>> reason or other (maybe mapping domains to applications), so I'm *not* 
>>> advocating that anyone actually do that.
>> 
>>>> Ron
>> 
>>>> On Oct 20, 10:55 pm, Jonathan Lundell <[email protected]> wrote:
>>>>> On Oct 20, 2010, at 10:44 PM, ron_m wrote:
>> 
>>>>>> This works
>> 
>>>>>> URL(request.application,'default','products/used'), [])
>> 
>>>>> You can also do something like this, which to my mind is more readable:
>> 
>>>>> URL('default', 'products', args=['used'])
>> 
>>>>> or equivalently, and even more readable:
>> 
>>>>> URL(c='default', f='products', args=['used'])
>> 
>>>>> I say "something like" because I didn't explicitly test it.
>> 
>>>>>> On Oct 20, 7:40 pm, Jason Brower <[email protected]> wrote:
>>>>>>> response.menu = [
>>>>>>>     (T('Home'), False, URL(request.application,'default','index'), []),
>>>>>>>     (T('Products'), False,
>>>>>>> URL(request.application,'default','products'), []),
>>>>>>>     (T('Used Products'), False,
>>>>>>> URL(request.application,'default','products'), []),
>>>>>>>     (T('Company'), False, URL(request.application,'default','company'),
>>>>>>> [])
>>>>>>>     ]
>>>>>>> Notice I have to products pages... basically they are they same but they
>>>>>>> have some feilds I want different in them... one will go to
>>>>>>> default/products and the other to default/products/used.
>>>>>>> BR,
>>>>>>> Jason
>> 
>>>>>>> On Wed, 2010-10-20 at 11:26 -0700, mdipierro wrote:
>>>>>>>> ?
>> 
>>>>>>>> On Oct 20, 12:26 pm, Jason Brower <[email protected]> wrote:
>>>>>>>>> Are there no arg in response.menu?  If not I can build it different, 
>>>>>>>>> but
>>>>>>>>> I thought it would so I can do some special menu items.
>>>>>>>>> :/ Innerestin'
>>>>>>>>> ---
>>>>>>>>> BR,
>>>>>>>>> Jason
>> 
>>>>>>>>>  face-uncertain.png
>>>>>>>>> 1KViewDownload
>> 
>> 


Reply via email to