Mercurial > kallithea
comparison pylons_app/config/routing.py @ 300:8f7b8e965fe4
fixed 404s added extra validator for magic repo_name path in routes
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 28 Jun 2010 18:09:56 +0200 |
parents | d303aacb3349 |
children | 752675cdd167 |
comparison
equal
deleted
inserted
replaced
299:d303aacb3349 | 300:8f7b8e965fe4 |
---|---|
3 The more specific and detailed routes should be defined first so they | 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 | 4 may take precedent over the more generic routes. For more information |
5 refer to the routes manual at http://routes.groovie.org/docs/ | 5 refer to the routes manual at http://routes.groovie.org/docs/ |
6 """ | 6 """ |
7 from routes import Mapper | 7 from routes import Mapper |
8 from pylons_app.lib.utils import check_repo as cr | |
8 | 9 |
9 def make_map(config): | 10 def make_map(config): |
10 """Create, configure and return the routes Mapper""" | 11 """Create, configure and return the routes Mapper""" |
11 map = Mapper(directory=config['pylons.paths']['controllers'], | 12 map = Mapper(directory=config['pylons.paths']['controllers'], |
12 always_scan=config['debug']) | 13 always_scan=config['debug']) |
19 map.connect('/error/{action}/{id}', controller='error') | 20 map.connect('/error/{action}/{id}', controller='error') |
20 | 21 |
21 # CUSTOM ROUTES HERE | 22 # CUSTOM ROUTES HERE |
22 map.connect('hg_home', '/', controller='hg', action='index') | 23 map.connect('hg_home', '/', controller='hg', action='index') |
23 | 24 |
24 | 25 def check_repo(environ, match_dict): |
26 """ | |
27 check for valid repository for proper 404 handling | |
28 @param environ: | |
29 @param match_dict: | |
30 """ | |
31 repo_name = match_dict.get('repo_name') | |
32 return not cr(repo_name, config['base_path']) | |
33 | |
25 #REST routes | 34 #REST routes |
26 with map.submapper(path_prefix='/_admin', controller='repos') as m: | 35 with map.submapper(path_prefix='/_admin', controller='repos') as m: |
27 m.connect("repos", "/repos", | 36 m.connect("repos", "/repos", |
28 action="create", conditions=dict(method=["POST"])) | 37 action="create", conditions=dict(method=["POST"])) |
29 m.connect("repos", "/repos", | 38 m.connect("repos", "/repos", |
34 m.connect("new_repo", "/repos/new", | 43 m.connect("new_repo", "/repos/new", |
35 action="new", conditions=dict(method=["GET"])) | 44 action="new", conditions=dict(method=["GET"])) |
36 m.connect("formatted_new_repo", "/repos/new.{format}", | 45 m.connect("formatted_new_repo", "/repos/new.{format}", |
37 action="new", conditions=dict(method=["GET"])) | 46 action="new", conditions=dict(method=["GET"])) |
38 m.connect("/repos/{repo_name:.*}", | 47 m.connect("/repos/{repo_name:.*}", |
39 action="update", conditions=dict(method=["PUT"])) | 48 action="update", conditions=dict(method=["PUT"], |
49 function=check_repo)) | |
40 m.connect("/repos/{repo_name:.*}", | 50 m.connect("/repos/{repo_name:.*}", |
41 action="delete", conditions=dict(method=["DELETE"])) | 51 action="delete", conditions=dict(method=["DELETE"], |
52 function=check_repo)) | |
42 m.connect("edit_repo", "/repos/{repo_name:.*}/edit", | 53 m.connect("edit_repo", "/repos/{repo_name:.*}/edit", |
43 action="edit", conditions=dict(method=["GET"])) | 54 action="edit", conditions=dict(method=["GET"], |
55 function=check_repo)) | |
44 m.connect("formatted_edit_repo", "/repos/{repo_name:.*}.{format}/edit", | 56 m.connect("formatted_edit_repo", "/repos/{repo_name:.*}.{format}/edit", |
45 action="edit", conditions=dict(method=["GET"])) | 57 action="edit", conditions=dict(method=["GET"], |
58 function=check_repo)) | |
46 m.connect("repo", "/repos/{repo_name:.*}", | 59 m.connect("repo", "/repos/{repo_name:.*}", |
47 action="show", conditions=dict(method=["GET"])) | 60 action="show", conditions=dict(method=["GET"], |
61 function=check_repo)) | |
48 m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", | 62 m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", |
49 action="show", conditions=dict(method=["GET"])) | 63 action="show", conditions=dict(method=["GET"], |
64 function=check_repo)) | |
50 #ajax delete repo perm user | 65 #ajax delete repo perm user |
51 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", | 66 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", |
52 action="delete_perm_user", conditions=dict(method=["DELETE"])) | 67 action="delete_perm_user", conditions=dict(method=["DELETE"], |
68 function=check_repo)) | |
53 | 69 |
54 map.resource('user', 'users', path_prefix='/_admin') | 70 map.resource('user', 'users', path_prefix='/_admin') |
55 map.resource('permission', 'permissions', path_prefix='/_admin') | 71 map.resource('permission', 'permissions', path_prefix='/_admin') |
56 | 72 |
57 #ADMIN | 73 #ADMIN |
60 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', | 76 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
61 action='add_repo') | 77 action='add_repo') |
62 | 78 |
63 #FEEDS | 79 #FEEDS |
64 map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', | 80 map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', |
65 controller='feed', action='rss') | 81 controller='feed', action='rss', |
82 conditions=dict(function=check_repo)) | |
66 map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', | 83 map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', |
67 controller='feed', action='atom') | 84 controller='feed', action='atom', |
85 conditions=dict(function=check_repo)) | |
68 | 86 |
69 map.connect('login_home', '/login', controller='login') | 87 map.connect('login_home', '/login', controller='login') |
70 map.connect('logout_home', '/logout', controller='login', action='logout') | 88 map.connect('logout_home', '/logout', controller='login', action='logout') |
71 | 89 |
72 map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', | 90 map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', |
73 controller='changeset', revision='tip') | 91 controller='changeset', revision='tip', |
92 conditions=dict(function=check_repo)) | |
74 map.connect('summary_home', '/{repo_name:.*}/summary', | 93 map.connect('summary_home', '/{repo_name:.*}/summary', |
75 controller='summary') | 94 controller='summary', conditions=dict(function=check_repo)) |
76 map.connect('shortlog_home', '/{repo_name:.*}/shortlog', | 95 map.connect('shortlog_home', '/{repo_name:.*}/shortlog', |
77 controller='shortlog') | 96 controller='shortlog', conditions=dict(function=check_repo)) |
78 map.connect('branches_home', '/{repo_name:.*}/branches', | 97 map.connect('branches_home', '/{repo_name:.*}/branches', |
79 controller='branches') | 98 controller='branches', conditions=dict(function=check_repo)) |
80 map.connect('tags_home', '/{repo_name:.*}/tags', | 99 map.connect('tags_home', '/{repo_name:.*}/tags', |
81 controller='tags') | 100 controller='tags', conditions=dict(function=check_repo)) |
82 map.connect('changelog_home', '/{repo_name:.*}/changelog', | 101 map.connect('changelog_home', '/{repo_name:.*}/changelog', |
83 controller='changelog') | 102 controller='changelog', conditions=dict(function=check_repo)) |
84 map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', | 103 map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', |
85 controller='files', revision='tip', f_path='') | 104 controller='files', revision='tip', f_path='', |
105 conditions=dict(function=check_repo)) | |
86 map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}', | 106 map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}', |
87 controller='files', action='diff', revision='tip', f_path='') | 107 controller='files', action='diff', revision='tip', f_path='', |
108 conditions=dict(function=check_repo)) | |
88 map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}', | 109 map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}', |
89 controller='files', action='rawfile', revision='tip', f_path='') | 110 controller='files', action='rawfile', revision='tip', f_path='', |
111 conditions=dict(function=check_repo)) | |
90 map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', | 112 map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', |
91 controller='files', action='annotate', revision='tip', f_path='') | 113 controller='files', action='annotate', revision='tip', f_path='', |
114 conditions=dict(function=check_repo)) | |
92 map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', | 115 map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', |
93 controller='files', action='archivefile', revision='tip') | 116 controller='files', action='archivefile', revision='tip', |
117 conditions=dict(function=check_repo)) | |
94 return map | 118 return map |