##// END OF EJS Templates
reverted copy of cached instance:...
marcink -
r1340:cbdd583f beta
parent child Browse files
Show More
@@ -1,81 +1,74
1 """The base Controller API
1 """The base Controller API
2
2
3 Provides the BaseController class for subclassing.
3 Provides the BaseController class for subclassing.
4 """
4 """
5 import copy
6
7 from pylons import config, tmpl_context as c, request, session
5 from pylons import config, tmpl_context as c, request, session
8 from pylons.controllers import WSGIController
6 from pylons.controllers import WSGIController
9 from pylons.templating import render_mako as render
7 from pylons.templating import render_mako as render
10
8
11 from rhodecode import __version__
9 from rhodecode import __version__
12 from rhodecode.lib.auth import AuthUser
10 from rhodecode.lib.auth import AuthUser
13 from rhodecode.lib.utils import get_repo_slug
11 from rhodecode.lib.utils import get_repo_slug
14 from rhodecode.model import meta
12 from rhodecode.model import meta
15 from rhodecode.model.scm import ScmModel
13 from rhodecode.model.scm import ScmModel
16 from rhodecode import BACKENDS
14 from rhodecode import BACKENDS
17
15
18
16
19 class BaseController(WSGIController):
17 class BaseController(WSGIController):
20
18
21 def __before__(self):
19 def __before__(self):
22 c.rhodecode_version = __version__
20 c.rhodecode_version = __version__
23 c.rhodecode_name = config.get('rhodecode_title')
21 c.rhodecode_name = config.get('rhodecode_title')
24 c.ga_code = config.get('rhodecode_ga_code')
22 c.ga_code = config.get('rhodecode_ga_code')
25 c.repo_name = get_repo_slug(request)
23 c.repo_name = get_repo_slug(request)
26 c.backends = BACKENDS.keys()
24 c.backends = BACKENDS.keys()
27 self.cut_off_limit = int(config.get('cut_off_limit'))
25 self.cut_off_limit = int(config.get('cut_off_limit'))
28
26
29 self.sa = meta.Session()
27 self.sa = meta.Session()
30 self.scm_model = ScmModel(self.sa)
28 self.scm_model = ScmModel(self.sa)
31 c.cached_repo_list = self.scm_model.get_repos()
29 c.cached_repo_list = self.scm_model.get_repos()
32 #c.unread_journal = scm_model.get_unread_journal()
30 #c.unread_journal = scm_model.get_unread_journal()
33
31
34 def __call__(self, environ, start_response):
32 def __call__(self, environ, start_response):
35 """Invoke the Controller"""
33 """Invoke the Controller"""
36 # WSGIController.__call__ dispatches to the Controller method
34 # WSGIController.__call__ dispatches to the Controller method
37 # the request is routed to. This routing information is
35 # the request is routed to. This routing information is
38 # available in environ['pylons.routes_dict']
36 # available in environ['pylons.routes_dict']
39 try:
37 try:
40 # putting this here makes sure that we update permissions each time
38 # putting this here makes sure that we update permissions each time
41 api_key = request.GET.get('api_key')
39 api_key = request.GET.get('api_key')
42 user_id = getattr(session.get('rhodecode_user'), 'user_id', None)
40 user_id = getattr(session.get('rhodecode_user'), 'user_id', None)
43 self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key)
41 self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key)
44 self.rhodecode_user.set_authenticated(
42 self.rhodecode_user.set_authenticated(
45 getattr(session.get('rhodecode_user'),
43 getattr(session.get('rhodecode_user'),
46 'is_authenticated', False))
44 'is_authenticated', False))
47 session['rhodecode_user'] = self.rhodecode_user
45 session['rhodecode_user'] = self.rhodecode_user
48 session.save()
46 session.save()
49 return WSGIController.__call__(self, environ, start_response)
47 return WSGIController.__call__(self, environ, start_response)
50 finally:
48 finally:
51 meta.Session.remove()
49 meta.Session.remove()
52
50
53
51
54 class BaseRepoController(BaseController):
52 class BaseRepoController(BaseController):
55 """
53 """
56 Base class for controllers responsible for loading all needed data
54 Base class for controllers responsible for loading all needed data
57 for those controllers, loaded items are
55 for those controllers, loaded items are
58
56
59 c.rhodecode_repo: instance of scm repository (taken from cache)
57 c.rhodecode_repo: instance of scm repository (taken from cache)
60
58
61 """
59 """
62
60
63 def __before__(self):
61 def __before__(self):
64 super(BaseRepoController, self).__before__()
62 super(BaseRepoController, self).__before__()
65 if c.repo_name:
63 if c.repo_name:
66
64
67 r, dbrepo = self.scm_model.get(c.repo_name, retval='repo')
65 c.rhodecode_repo, dbrepo = self.scm_model.get(c.repo_name, retval='repo')
68
66
69 if r is not None:
67 if c.rhodecode_repo is not None:
70 c.repository_followers = \
68 c.repository_followers = \
71 self.scm_model.get_followers(c.repo_name)
69 self.scm_model.get_followers(c.repo_name)
72 c.repository_forks = self.scm_model.get_forks(c.repo_name)
70 c.repository_forks = self.scm_model.get_forks(c.repo_name)
73 else:
71 else:
74 c.repository_followers = 0
72 c.repository_followers = 0
75 c.repository_forks = 0
73 c.repository_forks = 0
76
74
77 # Since RhodeCode uses heavy memory caching we make a deepcopy
78 # of object taken from cache. This way we lose reference to cached
79 # instance in memory and keep it relatively small even for
80 # very large number of changesets
81 c.rhodecode_repo = copy.copy(r)
General Comments 0
You need to be logged in to leave comments. Login now