##// END OF EJS Templates
core: added supports of repo based views via pyramid.
marcink -
r1554:8ba8e355 default
parent child Browse files
Show More
@@ -25,7 +25,9 b' from pyramid.httpexceptions import HTTPF'
25
25
26 from rhodecode.lib import helpers as h
26 from rhodecode.lib import helpers as h
27 from rhodecode.lib.utils2 import StrictAttributeDict, safe_int
27 from rhodecode.lib.utils2 import StrictAttributeDict, safe_int
28 from rhodecode.model import repo
28 from rhodecode.model.db import User
29 from rhodecode.model.db import User
30 from rhodecode.model.scm import ScmModel
29
31
30 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
31
33
@@ -110,3 +112,52 b' class BaseAppView(object):'
110 """
112 """
111 raise NotImplementedError('Needs implementation in view class')
113 raise NotImplementedError('Needs implementation in view class')
112
114
115
116 class RepoAppView(BaseAppView):
117
118 def __init__(self, context, request):
119 super(RepoAppView, self).__init__(context, request)
120 self.db_repo = request.db_repo
121 self.db_repo_name = self.db_repo.repo_name
122 self.db_repo_pull_requests = ScmModel().get_pull_requests(self.db_repo)
123
124 def _get_local_tmpl_context(self):
125 c = super(RepoAppView, self)._get_local_tmpl_context()
126 # register common vars for this type of view
127 c.rhodecode_db_repo = self.db_repo
128 c.repo_name = self.db_repo_name
129 c.repository_pull_requests = self.db_repo_pull_requests
130 return c
131
132
133 class RepoRoutePredicate(object):
134 def __init__(self, val, config):
135 self.val = val
136
137 def text(self):
138 return 'repo_route = %s' % self.val
139
140 phash = text
141
142 def __call__(self, info, request):
143 repo_name = info['match']['repo_name']
144 repo_model = repo.RepoModel()
145 by_name_match = repo_model.get_by_repo_name(repo_name, cache=True)
146 # if we match quickly from database, short circuit the operation,
147 # and validate repo based on the type.
148 if by_name_match:
149 # register this as request object we can re-use later
150 request.db_repo = by_name_match
151 return True
152
153 by_id_match = repo_model.get_repo_by_id(repo_name)
154 if by_id_match:
155 request.db_repo = by_id_match
156 return True
157
158 return False
159
160
161 def includeme(config):
162 config.add_route_predicate(
163 'repo_route', RepoRoutePredicate)
@@ -283,6 +283,8 b' def includeme(config):'
283 config.include('rhodecode.integrations')
283 config.include('rhodecode.integrations')
284
284
285 # apps
285 # apps
286 config.include('rhodecode.apps._base')
287
286 config.include('rhodecode.apps.admin')
288 config.include('rhodecode.apps.admin')
287 config.include('rhodecode.apps.channelstream')
289 config.include('rhodecode.apps.channelstream')
288 config.include('rhodecode.apps.login')
290 config.include('rhodecode.apps.login')
General Comments 0
You need to be logged in to leave comments. Login now