Show More
@@ -37,6 +37,19 b' log = logging.getLogger(__name__)' | |||
|
37 | 37 | ADMIN_PREFIX = '/_admin' |
|
38 | 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 | 54 | def add_route_with_slash(config,name, pattern, **kw): |
|
42 | 55 | config.add_route(name, pattern, **kw) |
@@ -44,6 +57,17 b' def add_route_with_slash(config,name, pa' | |||
|
44 | 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 | 71 | def get_format_ref_id(repo): |
|
48 | 72 | """Returns a `repo` specific reference formatter function""" |
|
49 | 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 | 54 | class JSRoutesMapper(Mapper): |
|
68 | 55 | """ |
|
69 | 56 | Wrapper for routes.Mapper to make pyroutes compatible url definitions |
@@ -20,9 +20,8 b'' | |||
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 | 22 | |
|
23 | from rhodecode.apps._base import ADMIN_PREFIX, add_route_requirements | |
|
23 | 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 | 25 | from rhodecode.integrations import integration_type_registry |
|
27 | 26 | |
|
28 | 27 | log = logging.getLogger(__name__) |
@@ -76,14 +75,12 b' def includeme(config):' | |||
|
76 | 75 | config.add_route('repo_group_integrations_home', |
|
77 | 76 | add_route_requirements( |
|
78 | 77 | '{repo_group_name}/settings/integrations', |
|
79 | URL_NAME_REQUIREMENTS | |
|
80 | 78 | ), |
|
81 | 79 | custom_predicates=(valid_repo_group,) |
|
82 | 80 | ) |
|
83 | 81 | config.add_route('repo_group_integrations_list', |
|
84 | 82 | add_route_requirements( |
|
85 | 83 | '{repo_group_name}/settings/integrations/{integration}', |
|
86 | URL_NAME_REQUIREMENTS | |
|
87 | 84 | ), |
|
88 | 85 | custom_predicates=(valid_repo_group, valid_integration)) |
|
89 | 86 | for route_name in ['repo_group_integrations_home', 'repo_group_integrations_list']: |
@@ -96,7 +93,6 b' def includeme(config):' | |||
|
96 | 93 | config.add_route('repo_group_integrations_new', |
|
97 | 94 | add_route_requirements( |
|
98 | 95 | '{repo_group_name}/settings/integrations/new', |
|
99 | URL_NAME_REQUIREMENTS | |
|
100 | 96 | ), |
|
101 | 97 | custom_predicates=(valid_repo_group,)) |
|
102 | 98 | config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView', |
@@ -108,13 +104,11 b' def includeme(config):' | |||
|
108 | 104 | config.add_route('repo_group_integrations_create', |
|
109 | 105 | add_route_requirements( |
|
110 | 106 | '{repo_group_name}/settings/integrations/{integration}/new', |
|
111 | URL_NAME_REQUIREMENTS | |
|
112 | 107 | ), |
|
113 | 108 | custom_predicates=(valid_repo_group, valid_integration)) |
|
114 | 109 | config.add_route('repo_group_integrations_edit', |
|
115 | 110 | add_route_requirements( |
|
116 | 111 | '{repo_group_name}/settings/integrations/{integration}/{integration_id}', |
|
117 | URL_NAME_REQUIREMENTS | |
|
118 | 112 | ), |
|
119 | 113 | custom_predicates=(valid_repo_group, valid_integration)) |
|
120 | 114 | for route_name in ['repo_group_integrations_edit', 'repo_group_integrations_create']: |
@@ -134,13 +128,11 b' def includeme(config):' | |||
|
134 | 128 | config.add_route('repo_integrations_home', |
|
135 | 129 | add_route_requirements( |
|
136 | 130 | '{repo_name}/settings/integrations', |
|
137 | URL_NAME_REQUIREMENTS | |
|
138 | 131 | ), |
|
139 | 132 | custom_predicates=(valid_repo,)) |
|
140 | 133 | config.add_route('repo_integrations_list', |
|
141 | 134 | add_route_requirements( |
|
142 | 135 | '{repo_name}/settings/integrations/{integration}', |
|
143 | URL_NAME_REQUIREMENTS | |
|
144 | 136 | ), |
|
145 | 137 | custom_predicates=(valid_repo, valid_integration)) |
|
146 | 138 | for route_name in ['repo_integrations_home', 'repo_integrations_list']: |
@@ -153,7 +145,6 b' def includeme(config):' | |||
|
153 | 145 | config.add_route('repo_integrations_new', |
|
154 | 146 | add_route_requirements( |
|
155 | 147 | '{repo_name}/settings/integrations/new', |
|
156 | URL_NAME_REQUIREMENTS | |
|
157 | 148 | ), |
|
158 | 149 | custom_predicates=(valid_repo,)) |
|
159 | 150 | config.add_view('rhodecode.integrations.views.RepoIntegrationsView', |
@@ -165,13 +156,11 b' def includeme(config):' | |||
|
165 | 156 | config.add_route('repo_integrations_create', |
|
166 | 157 | add_route_requirements( |
|
167 | 158 | '{repo_name}/settings/integrations/{integration}/new', |
|
168 | URL_NAME_REQUIREMENTS | |
|
169 | 159 | ), |
|
170 | 160 | custom_predicates=(valid_repo, valid_integration)) |
|
171 | 161 | config.add_route('repo_integrations_edit', |
|
172 | 162 | add_route_requirements( |
|
173 | 163 | '{repo_name}/settings/integrations/{integration}/{integration_id}', |
|
174 | URL_NAME_REQUIREMENTS | |
|
175 | 164 | ), |
|
176 | 165 | custom_predicates=(valid_repo, valid_integration)) |
|
177 | 166 | for route_name in ['repo_integrations_edit', 'repo_integrations_create']: |
@@ -223,7 +212,6 b' def valid_integration(info, request):' | |||
|
223 | 212 | if repo_name and repo_group: |
|
224 | 213 | raise Exception('Either repo or repo_group can be set, not both') |
|
225 | 214 | |
|
226 | ||
|
227 | 215 | if integration_id: |
|
228 | 216 | integration = Integration.get(integration_id) |
|
229 | 217 | if not integration: |
General Comments 0
You need to be logged in to leave comments.
Login now