Re: [web2py] Routes help for wordpress style urls

2011-12-24 Thread Anthony

>
> Not sure the below is a problem with routes or not.
> I have a feed() function. If I browse to feed.rss it works fine. But I 
> would like /feed/ as the url (without.rss). How to achieve it?
>

You could do that with the pattern-based rewrite system, but then you 
wouldn't be able to use the parameter-based system as you are now. As a 
simple alternative, you could do:

def feed():
response.view = 'default/feed.rss'  # or 'generic.rss' if you don't 
have a 'default/feed.rss' view

That assumes you always want rss for the feed() function -- otherwise, 
you'll need to add the appropriate logic. See info about response.view 
here: http://web2py.com/books/default/chapter/29/4#response.

Anthony



Re: [web2py] Routes help for wordpress style urls

2011-12-24 Thread Joseph Jude
Hopefully last question on this thread.

routers = dict(
  init= dict(functions = ['index',
'user',
'contact',
'sitemap',
'feed', 
'error']),
)

above works for admin, appadmin & for other entries too

Not sure the below is a problem with routes or not.
I have a feed() function. If I browse to feed.rss it works fine. But I 
would like /feed/ as the url (without.rss). How to achieve it?

Thanks again guys,
Joseph


Re: [web2py] Routes help for wordpress style urls

2011-12-23 Thread Anthony
On Friday, December 23, 2011 12:14:32 PM UTC-5, Joseph Jude wrote:
>
> routers = dict(
>   BASE = dict(default_application = 'init',
> default_controller = 'default',
> default_function = 'index',
> functions = ['index'],
> ),
> )
>
> With the above routes, admin doesn't work. i.e: localhost:8080/admin/index 
> throws a password pg but after that the control goes to /admin/site and it 
> throws an error 'This webpage has a redirect loop'.
>

I guess it's using your functions list for all apps, and you have only 
listed one function ('index') there. Instead, I think functions can be a 
dictionary with a key for each app, so maybe try:

functions = dict(init=['index', plus other functions in 
/init/controllers/default.py])

Not sure if you'll need to bother with an explicit entry for 'admin'.

Anthony 


Re: [web2py] Routes help for wordpress style urls

2011-12-23 Thread Jonathan Lundell
On Dec 23, 2011, at 9:14 AM, Joseph Jude wrote:

> routers = dict(
>   BASE= dict(default_application = 'init',
>   default_controller = 'default',
>   default_function = 'index',
>   functions = ['index'],
> ),
> )
> 
> With the above routes, admin doesn't work. i.e: localhost:8080/admin/index 
> throws a password pg but after that the control goes to /admin/site and it 
> throws an error 'This webpage has a redirect loop'.
> 
> How to resolve this?
> 

Try this (or something like it). Everything you put it BASE applies to all 
apps, so the functions= line in particular needs to go in an app-specific 
router.

I also omitted the init/default/index definitions, since they're already the 
defaults.


routers = dict(
  init  = dict(functions = ['index']),
)



Re: [web2py] Routes help for wordpress style urls

2011-12-23 Thread Joseph Jude
routers = dict(
  BASE = dict(default_application = 'init',
default_controller = 'default',
default_function = 'index',
functions = ['index'],
),
)

With the above routes, admin doesn't work. i.e: localhost:8080/admin/index 
throws a password pg but after that the control goes to /admin/site and it 
throws an error 'This webpage has a redirect loop'.

How to resolve this?
Thx,
Joseph


Re: [web2py] Routes help for wordpress style urls

2011-12-23 Thread Jonathan Lundell
On Dec 23, 2011, at 6:04 AM, Anthony wrote:

> No. The problem is that the router doesn't introspect the controller, and it 
> doesn't know what its function names are. So it assumes that 2011 is a 
> function in the default controller.
> 
> For this to work, it's necessary to provide the router with a list of valid 
> functions in the default controller: functions = [index, whatever, ...].
> 
> Oh, right. I was thinking there was something like controllers='DEFAULT' for 
> functions, but you have to list the functions explicitly. 

It'd be possible to do that, of course, duplicating (or sharing) the dispatch 
logic, but we don't. The overhead to do so would be fairly high in a cgi 
environment, too.

Re: [web2py] Routes help for wordpress style urls

2011-12-23 Thread Anthony

>
> No. The problem is that the router doesn't introspect the controller, and 
> it doesn't know what its function names are. So it assumes that 2011 is a 
> function in the default controller.
>
> For this to work, it's necessary to provide the router with a list of 
> valid functions in the default controller: functions = [index, whatever, 
> ...].
>

Oh, right. I was thinking there was something like controllers='DEFAULT' 
for functions, but you have to list the functions explicitly. 


Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Joseph Jude
Thx Jonathan & Anthony. Following works:

routers = dict(
  BASE = dict(default_application = 'init',
default_controller = 'default',
default_function = 'index',
functions = ['index'],
),
)

Regards,
Joseph


Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Jonathan Lundell
On Dec 22, 2011, at 9:21 PM, Anthony wrote:

> On Thursday, December 22, 2011 9:09:22 PM UTC-5, Joseph Jude wrote:
> I used this the below in routes.in
> 
> (r'^(?P\d{4})/(?P\d{2})/(?P\w+)/$', 
> '/init/default/index/\g/\g'),
> 
> but when I go to a url
> 
> localhost:/2011/11/a-slug
> 
> it returns invalid request error
> 
> then I tried 
> 
> routers = dict(
>   BASE  = dict(default_application = 'init',
>  default_controller = 'default',
>  default_function = 'index',
> ),
> )
> which gives me the error:
> invalid function (default/2011)
> 
> 
> I think that's supposed to work. Jonathan, is that a bug?
> 

No. The problem is that the router doesn't introspect the controller, and it 
doesn't know what its function names are. So it assumes that 2011 is a function 
in the default controller.

For this to work, it's necessary to provide the router with a list of valid 
functions in the default controller: functions = [index, whatever, ...].

Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Anthony
On Thursday, December 22, 2011 9:09:22 PM UTC-5, Joseph Jude wrote:
>
> I used this the below in routes.in
>
> (r'^(?P\d{4})/(?P\d{2})/(?P\w+)/$', 
> '/init/default/index/\g/\g'),
>
> but when I go to a url
>
> localhost:/2011/11/a-slug
>
> it returns invalid request error
>
> then I tried 
>
> routers = dict(
>   BASE  = dict(default_application = 'init',
>default_controller = 'default',
>default_function = 'index',
> ),
> )
> which gives me the error:
> invalid function (default/2011)
>

I think that's supposed to work. Jonathan, is that a bug?

Anthony 


Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Joseph Jude
yes anthony

Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Anthony
Is your application named 'init'?

On Thursday, December 22, 2011 9:09:22 PM UTC-5, Joseph Jude wrote:
>
> I used this the below in routes.in
>
> (r'^(?P\d{4})/(?P\d{2})/(?P\w+)/$', 
> '/init/default/index/\g/\g'),
>
> but when I go to a url
>
> localhost:/2011/11/a-slug
>
> it returns invalid request error
>
> then I tried 
>
> routers = dict(
>   BASE  = dict(default_application = 'init',
>default_controller = 'default',
>default_function = 'index',
> ),
> )
> which gives me the error:
> invalid function (default/2011)
>
> fair enough. I could traverse /index/2011 
> But can I drop index too from the url?
>
> Thx,
> Joseph
>


Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Joseph Jude
I used this the below in routes.in

(r'^(?P\d{4})/(?P\d{2})/(?P\w+)/$', 
'/init/default/index/\g/\g'),

but when I go to a url

localhost:/2011/11/a-slug

it returns invalid request error

then I tried 

routers = dict(
  BASE  = dict(default_application = 'init',
   default_controller = 'default',
   default_function = 'index',
),
)
which gives me the error:
invalid function (default/2011)

fair enough. I could traverse /index/2011 
But can I drop index too from the url?

Thx,
Joseph


Re: [web2py] Routes help for wordpress style urls

2011-12-22 Thread Jonathan Lundell
On Dec 22, 2011, at 9:03 AM, Joseph Jude wrote:

> I am almost complete on a blog engine for myself and have also written import 
> from wordpress. I'm not stuck at mapping the urls. In wordpress I've been 
> using
> 
> domain//mm/slug
> 
> as url for posts and
> 
> domain/page
> 
> for pages.
> 
> How do I translate that in web2py? Can this be achieved via parameter based 
> routes or should it be only by pattern-based?
> 

I think you'd be better off with pattern-based routing here. The only way I can 
think of doing it with the parametric router is to send everything to a default 
controller/function (so that yyy/mm/slug or page ends up in request.args) and 
dispatch from there based on args. 

[web2py] Routes help for wordpress style urls

2011-12-22 Thread Joseph Jude
Hi,
I am almost complete on a blog engine for myself and have also written 
import from wordpress. I'm not stuck at mapping the urls. In wordpress I've 
been using

domain//mm/slug

as url for posts and

domain/page

for pages.

How do I translate that in web2py? Can this be achieved via parameter based 
routes or should it be only by pattern-based?


Thank you,
Joseph