Mercurial > kallithea
annotate rhodecode/lib/base.py @ 1177:b3f48216e55e beta
frozen version of python dateutil since series 2.X are not python 2.X compatible
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 27 Mar 2011 01:34:14 +0100 |
parents | 6eb5bb24a948 |
children | 6832ef664673 |
rev | line source |
---|---|
0 | 1 """The base Controller API |
2 | |
3 Provides the BaseController class for subclassing. | |
4 """ | |
185
3380ca40cdba
added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents:
169
diff
changeset
|
5 from pylons import config, tmpl_context as c, request, session |
0 | 6 from pylons.controllers import WSGIController |
7 from pylons.templating import render_mako as render | |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
8 from rhodecode import __version__ |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
9 from rhodecode.lib.auth import AuthUser |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
10 from rhodecode.lib.utils import get_repo_slug |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
11 from rhodecode.model import meta |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
12 from rhodecode.model.scm import ScmModel |
710
e2f3c8e6939d
Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
13 from rhodecode import BACKENDS |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
14 |
0 | 15 class BaseController(WSGIController): |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
16 |
185
3380ca40cdba
added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents:
169
diff
changeset
|
17 def __before__(self): |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
18 c.rhodecode_version = __version__ |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
19 c.rhodecode_name = config.get('rhodecode_title') |
891
cca7286401b3
fixes for #89 ga code
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
20 c.ga_code = config.get('rhodecode_ga_code') |
185
3380ca40cdba
added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents:
169
diff
changeset
|
21 c.repo_name = get_repo_slug(request) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
22 c.backends = BACKENDS.keys() |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
23 self.cut_off_limit = int(config.get('cut_off_limit')) |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
891
diff
changeset
|
24 |
784
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
25 self.sa = meta.Session() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
26 self.scm_model = ScmModel(self.sa) |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
27 c.cached_repo_list = self.scm_model.get_repos() |
784
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
28 #c.unread_journal = scm_model.get_unread_journal() |
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
29 |
0 | 30 def __call__(self, environ, start_response): |
31 """Invoke the Controller""" | |
32 # WSGIController.__call__ dispatches to the Controller method | |
33 # the request is routed to. This routing information is | |
34 # available in environ['pylons.routes_dict'] | |
35 try: | |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
362
diff
changeset
|
36 #putting this here makes sure that we update permissions every time |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
37 api_key = request.GET.get('api_key') |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
38 user_id = getattr(session.get('rhodecode_user'), 'user_id', None) |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
39 self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key) |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
40 self.rhodecode_user.set_authenticated( |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
41 getattr(session.get('rhodecode_user'), |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
42 'is_authenticated', False)) |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
43 session['rhodecode_user'] = self.rhodecode_user |
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
44 session.save() |
0 | 45 return WSGIController.__call__(self, environ, start_response) |
46 finally: | |
51 | 47 meta.Session.remove() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
48 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
49 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
50 class BaseRepoController(BaseController): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
51 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
52 Base class for controllers responsible for loading all needed data |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
53 for those controllers, loaded items are |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
54 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
55 c.rhodecode_repo: instance of scm repository (taken from cache) |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
56 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
57 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
58 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
59 def __before__(self): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
60 super(BaseRepoController, self).__before__() |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
61 if c.repo_name: |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
62 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
63 c.rhodecode_repo, dbrepo = self.scm_model.get(c.repo_name, |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
64 retval='repo') |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
65 if c.rhodecode_repo: |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
66 c.repository_followers = self.scm_model.get_followers(c.repo_name) |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
67 c.repository_forks = self.scm_model.get_forks(c.repo_name) |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
68 else: |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
69 c.repository_followers = 0 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
70 c.repository_forks = 0 |