##// END OF EJS Templates
pyramid: moved add_route_requirements into pyramid base app....
marcink -
r1928:d7d26d76 default
parent child Browse files
Show More
@@ -37,6 +37,19 b' log = logging.getLogger(__name__)'
37 ADMIN_PREFIX = '/_admin'
37 ADMIN_PREFIX = '/_admin'
38 STATIC_FILE_PREFIX = '/_static'
38 STATIC_FILE_PREFIX = '/_static'
39
39
40 URL_NAME_REQUIREMENTS = {
41 # group name can have a slash in them, but they must not end with a slash
42 'group_name': r'.*?[^/]',
43 'repo_group_name': r'.*?[^/]',
44 # repo names can have a slash in them, but they must not end with a slash
45 'repo_name': r'.*?[^/]',
46 # file path eats up everything at the end
47 'f_path': r'.*',
48 # reference types
49 'source_ref_type': '(branch|book|tag|rev|\%\(source_ref_type\)s)',
50 'target_ref_type': '(branch|book|tag|rev|\%\(target_ref_type\)s)',
51 }
52
40
53
41 def add_route_with_slash(config,name, pattern, **kw):
54 def add_route_with_slash(config,name, pattern, **kw):
42 config.add_route(name, pattern, **kw)
55 config.add_route(name, pattern, **kw)
@@ -44,6 +57,17 b' def add_route_with_slash(config,name, pa'
44 config.add_route(name + '_slash', pattern + '/', **kw)
57 config.add_route(name + '_slash', pattern + '/', **kw)
45
58
46
59
60 def add_route_requirements(route_path, requirements=URL_NAME_REQUIREMENTS):
61 """
62 Adds regex requirements to pyramid routes using a mapping dict
63 e.g::
64 add_route_requirements('{repo_name}/settings')
65 """
66 for key, regex in requirements.items():
67 route_path = route_path.replace('{%s}' % key, '{%s:%s}' % (key, regex))
68 return route_path
69
70
47 def get_format_ref_id(repo):
71 def get_format_ref_id(repo):
48 """Returns a `repo` specific reference formatter function"""
72 """Returns a `repo` specific reference formatter function"""
49 if h.is_svn(repo):
73 if h.is_svn(repo):
@@ -51,19 +51,6 b' URL_NAME_REQUIREMENTS = {'
51 }
51 }
52
52
53
53
54 def add_route_requirements(route_path, requirements):
55 """
56 Adds regex requirements to pyramid routes using a mapping dict
57
58 >>> add_route_requirements('/{action}/{id}', {'id': r'\d+'})
59 '/{action}/{id:\d+}'
60
61 """
62 for key, regex in requirements.items():
63 route_path = route_path.replace('{%s}' % key, '{%s:%s}' % (key, regex))
64 return route_path
65
66
67 class JSRoutesMapper(Mapper):
54 class JSRoutesMapper(Mapper):
68 """
55 """
69 Wrapper for routes.Mapper to make pyroutes compatible url definitions
56 Wrapper for routes.Mapper to make pyroutes compatible url definitions
@@ -20,9 +20,8 b''
20
20
21 import logging
21 import logging
22
22
23 from rhodecode.apps._base import ADMIN_PREFIX, add_route_requirements
23 from rhodecode.model.db import Repository, Integration, RepoGroup
24 from rhodecode.model.db import Repository, Integration, RepoGroup
24 from rhodecode.config.routing import (
25 ADMIN_PREFIX, add_route_requirements, URL_NAME_REQUIREMENTS)
26 from rhodecode.integrations import integration_type_registry
25 from rhodecode.integrations import integration_type_registry
27
26
28 log = logging.getLogger(__name__)
27 log = logging.getLogger(__name__)
@@ -76,14 +75,12 b' def includeme(config):'
76 config.add_route('repo_group_integrations_home',
75 config.add_route('repo_group_integrations_home',
77 add_route_requirements(
76 add_route_requirements(
78 '{repo_group_name}/settings/integrations',
77 '{repo_group_name}/settings/integrations',
79 URL_NAME_REQUIREMENTS
80 ),
78 ),
81 custom_predicates=(valid_repo_group,)
79 custom_predicates=(valid_repo_group,)
82 )
80 )
83 config.add_route('repo_group_integrations_list',
81 config.add_route('repo_group_integrations_list',
84 add_route_requirements(
82 add_route_requirements(
85 '{repo_group_name}/settings/integrations/{integration}',
83 '{repo_group_name}/settings/integrations/{integration}',
86 URL_NAME_REQUIREMENTS
87 ),
84 ),
88 custom_predicates=(valid_repo_group, valid_integration))
85 custom_predicates=(valid_repo_group, valid_integration))
89 for route_name in ['repo_group_integrations_home', 'repo_group_integrations_list']:
86 for route_name in ['repo_group_integrations_home', 'repo_group_integrations_list']:
@@ -96,7 +93,6 b' def includeme(config):'
96 config.add_route('repo_group_integrations_new',
93 config.add_route('repo_group_integrations_new',
97 add_route_requirements(
94 add_route_requirements(
98 '{repo_group_name}/settings/integrations/new',
95 '{repo_group_name}/settings/integrations/new',
99 URL_NAME_REQUIREMENTS
100 ),
96 ),
101 custom_predicates=(valid_repo_group,))
97 custom_predicates=(valid_repo_group,))
102 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
98 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
@@ -108,13 +104,11 b' def includeme(config):'
108 config.add_route('repo_group_integrations_create',
104 config.add_route('repo_group_integrations_create',
109 add_route_requirements(
105 add_route_requirements(
110 '{repo_group_name}/settings/integrations/{integration}/new',
106 '{repo_group_name}/settings/integrations/{integration}/new',
111 URL_NAME_REQUIREMENTS
112 ),
107 ),
113 custom_predicates=(valid_repo_group, valid_integration))
108 custom_predicates=(valid_repo_group, valid_integration))
114 config.add_route('repo_group_integrations_edit',
109 config.add_route('repo_group_integrations_edit',
115 add_route_requirements(
110 add_route_requirements(
116 '{repo_group_name}/settings/integrations/{integration}/{integration_id}',
111 '{repo_group_name}/settings/integrations/{integration}/{integration_id}',
117 URL_NAME_REQUIREMENTS
118 ),
112 ),
119 custom_predicates=(valid_repo_group, valid_integration))
113 custom_predicates=(valid_repo_group, valid_integration))
120 for route_name in ['repo_group_integrations_edit', 'repo_group_integrations_create']:
114 for route_name in ['repo_group_integrations_edit', 'repo_group_integrations_create']:
@@ -134,13 +128,11 b' def includeme(config):'
134 config.add_route('repo_integrations_home',
128 config.add_route('repo_integrations_home',
135 add_route_requirements(
129 add_route_requirements(
136 '{repo_name}/settings/integrations',
130 '{repo_name}/settings/integrations',
137 URL_NAME_REQUIREMENTS
138 ),
131 ),
139 custom_predicates=(valid_repo,))
132 custom_predicates=(valid_repo,))
140 config.add_route('repo_integrations_list',
133 config.add_route('repo_integrations_list',
141 add_route_requirements(
134 add_route_requirements(
142 '{repo_name}/settings/integrations/{integration}',
135 '{repo_name}/settings/integrations/{integration}',
143 URL_NAME_REQUIREMENTS
144 ),
136 ),
145 custom_predicates=(valid_repo, valid_integration))
137 custom_predicates=(valid_repo, valid_integration))
146 for route_name in ['repo_integrations_home', 'repo_integrations_list']:
138 for route_name in ['repo_integrations_home', 'repo_integrations_list']:
@@ -153,7 +145,6 b' def includeme(config):'
153 config.add_route('repo_integrations_new',
145 config.add_route('repo_integrations_new',
154 add_route_requirements(
146 add_route_requirements(
155 '{repo_name}/settings/integrations/new',
147 '{repo_name}/settings/integrations/new',
156 URL_NAME_REQUIREMENTS
157 ),
148 ),
158 custom_predicates=(valid_repo,))
149 custom_predicates=(valid_repo,))
159 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
150 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
@@ -165,13 +156,11 b' def includeme(config):'
165 config.add_route('repo_integrations_create',
156 config.add_route('repo_integrations_create',
166 add_route_requirements(
157 add_route_requirements(
167 '{repo_name}/settings/integrations/{integration}/new',
158 '{repo_name}/settings/integrations/{integration}/new',
168 URL_NAME_REQUIREMENTS
169 ),
159 ),
170 custom_predicates=(valid_repo, valid_integration))
160 custom_predicates=(valid_repo, valid_integration))
171 config.add_route('repo_integrations_edit',
161 config.add_route('repo_integrations_edit',
172 add_route_requirements(
162 add_route_requirements(
173 '{repo_name}/settings/integrations/{integration}/{integration_id}',
163 '{repo_name}/settings/integrations/{integration}/{integration_id}',
174 URL_NAME_REQUIREMENTS
175 ),
164 ),
176 custom_predicates=(valid_repo, valid_integration))
165 custom_predicates=(valid_repo, valid_integration))
177 for route_name in ['repo_integrations_edit', 'repo_integrations_create']:
166 for route_name in ['repo_integrations_edit', 'repo_integrations_create']:
@@ -223,7 +212,6 b' def valid_integration(info, request):'
223 if repo_name and repo_group:
212 if repo_name and repo_group:
224 raise Exception('Either repo or repo_group can be set, not both')
213 raise Exception('Either repo or repo_group can be set, not both')
225
214
226
227 if integration_id:
215 if integration_id:
228 integration = Integration.get(integration_id)
216 integration = Integration.get(integration_id)
229 if not integration:
217 if not integration:
General Comments 0
You need to be logged in to leave comments. Login now