7f46a2c62acb2b8e0c40d775a28d56f6c76a3eeb
1 """Routes configuration
3 The more specific and detailed routes should be defined first so they
4 may take precedent over the more generic routes. For more information
5 refer to the routes manual at http://routes.groovie.org/docs/
7 from pylons
import config
8 from routes
import Mapper
11 """Create, configure and return the routes Mapper"""
12 map = Mapper(directory
=config
['pylons.paths']['controllers'],
13 always_scan
=config
['debug'], explicit
=True)
14 map.minimization
= False
16 # explicit = True disables a broken feature called "route memory",
17 # where it adds everything matched in the current request as default variables
18 # for the next one. This is wrong because it doesn't invalidate things lower down in
19 # the hierarchy when higher up things change. Rails port failure.
20 # NOTE: this also disables actions defaulting to index, sorry.
22 require_POST
= dict(conditions
={'method': ['POST']})
24 # get rid of trailing slashes
25 map.redirect('/*(url)/', '/{url}',
26 _redirect_code
='301 Moved Permanently')
29 # The ErrorController route (handles 404/500 error pages); it should
30 # likely stay at the top, ensuring it can always be resolved
31 map.connect('/error/{action}', controller
='error')
32 map.connect('/error/{action}/{id}', controller
='error')
34 map.connect('/', controller
='main', action
='index')
37 map.connect('/account/login', controller
='account', action
='login')
38 map.connect('/account/login_begin', controller
='account', action
='login_begin', **require_POST
)
39 map.connect('/account/login_finish', controller
='account', action
='login_finish')
40 map.connect('/account/logout', controller
='account', action
='logout', **require_POST
)
41 map.connect('/account/register', controller
='account', action
='register')
42 map.connect('/account/register_finish', controller
='account', action
='register_finish', **require_POST
)
44 map.connect('/users', controller
='users', action
='list')
45 map.connect('user_page', '/users/{name}', controller
='users', action
='view')
48 art
= map.resource('art','art', controller
="art", member
={'rate':'PUT'})
49 # wow, it even works if you name the plural and singular the same thing.
50 # Resources documented here: http://routes.groovie.org/manual.html#restful-services
51 # It seems the first parameter (singular) is only ever used in route names, e.g. url('kitten', id=5).
52 # The second parameter, plural, is used everywhere else by default: in the url, controller name,
53 # and the route name for the collection. e.g. url('kittens') -> '/kittens' -> kittens.index().
54 # Since our controllers have singular names, we'll have to override this every time with the 'controller' parameter.
55 # Even singular routes use the plural in urls. url('kitten', id=5) -> '/kittens/5'.
56 # And it appears that if the singular and plural are the same, either will match, so no harm done.
57 # It does mean, however, that if you have a None id accidentally, url('art', id=None) you'll get the same thing
58 # as url('art'). I mean, you might have wanted a singular but you got a plural route instead.
60 map.resource('tag','tags', controller
="tag",
61 parent_resource
=dict(member_name
='art', collection_name
='art'))
62 # Yeah, parent resources are specified kinda dumb-ly. Would be better if you could pass in the
63 # real parent resource instead of mocking it up with a silly dict. We should file a feature request.
65 # I think resources is the right way to go for most things. It ensures all of our actions have the right
66 # methods on them, at least. It does require the use of silly _method="delete" post parameters though.
68 # One sticking point though is, it'll happily allow you to add any formatting string you want, like art/1.json
69 # I wonder if there's a way to place requirements on that, or disable it until we actually have formats.
70 # It just serves the same action as usual but with a format argument in the context.
72 # map.connect('/art/new', controller='art', action='new')
73 # map.connect('/art/upload', controller='art', action='upload')
74 # map.connect('show_art', '/art/{id}', controller='art', action='show')
75 # map.connect('/art/{id}/tag', controller='art', action='tag')
77 # map.connect('/tag/{id}/delete', controller='tag', action='delete')
79 map.connect('search', '/search', controller
='search', action
='index')
80 # map.connect( '/search/{query}', controller='search', action='index')
81 map.connect('saved_searches', '/search/list', controller
='search', action
='list')
84 # default routing is back so we can test stuff.
85 # please don't take it away until we have some more core features in.
86 map.connect('/{controller}/{action}')
87 map.connect('/{controller}/{action}/{id}')