Re: computing url for view registered by name

2011-03-05 Thread Michael Merickel
By leaving out the context you are effectively registering those views to
*any* context, which is almost always undesirable.

Regardless, my previous reply remains correct, if you want the path hanging
off of /, simply use resource_url(request.root, request) and
resource_url(request.root, request, 'history').

request.root is the root context, thus the context used for views hanging
off of /.

Michael


On Fri, Mar 4, 2011 at 12:56 PM, Chris Withers ch...@simplistix.co.ukwrote:

 On 02/03/2011 00:48, Michael Merickel wrote:

 I noticed in your example you aren't specifying a context= or for_= in
 the view_config, implying you maybe intended to use route_name instead
 of name with url dispatch.


 Nope, no routes here, these are just views hanging off /, not registered
 against any context...


 cheers,

 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk


-- 
You received this message because you are subscribed to the Google Groups 
pylons-devel group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: computing url for view registered by name

2011-03-04 Thread Chris Withers

On 01/03/2011 16:59, Jean-Philippe wrote:

First off, I believe your views need to be named for this to work.


But views don't need to have names ;-)


That being said, the following would work from within a view callable:

url  = request.route_path('history')


...not if I'm not using a route...


route_path is similar to route_url but generates a path (aka a
‘relative URL’, a URL minus the host, scheme, and port)


_path generation is for the brave, you should stick to the _url methods 
unless you're really certain you should be heading to _path.


I ended up just adding the following on my view class:

def url_for(self,name):
return self.request.application_url+'/'+name

I'm fairly sure there's a ui equivalent for this...

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
pylons-devel group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



computing url for view registered by name

2011-03-01 Thread Chris Withers

Hi All,

I have two views:

@view_config(renderer='templates/index.pt')
class IndexView(..):
   ...

@view_config(name='history',renderer='templates/history.pt')
class HistoryView(..):
   ...

How should I generate urls to these?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
pylons-devel group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: computing url for view registered by name

2011-03-01 Thread Michael Merickel
I noticed in your example you aren't specifying a context= or for_= in the
view_config, implying you maybe intended to use route_name instead of name
with url dispatch.

If you are using traversal your application basically assumes a resource
tree, and so to get the url you provide a resource object that defines
__name__ and __parent__. The URL is then generated based on that resource's
location in the tree... the actual name of the view on that resource is
computed using the *elements on resource_url(). In the case of not defining
a context, you probably mean the root context object (although it could be
attached anywhere since you didn't specify). Assuming you wanted the root
context, you could do

resource_url(request.root, request)
and
resource_url(request.root, request, 'history')

HTH,
Michael

-- 
You received this message because you are subscribed to the Google Groups 
pylons-devel group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.