Mercurial > kallithea
annotate rhodecode/lib/base.py @ 1614:59ae82850e76 beta
Merge with upstream
author | Liad Shani <liadff@gmail.com> |
---|---|
date | Sun, 09 Oct 2011 23:49:00 +0200 |
parents | 6cab36e31f09 04027bdb876c |
children | cf128ced8c85 |
rev | line source |
---|---|
0 | 1 """The base Controller API |
2 | |
3 Provides the BaseController class for subclassing. | |
4 """ | |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
5 import logging |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
6 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
7 from pylons import config, tmpl_context as c, request, session, url |
0 | 8 from pylons.controllers import WSGIController |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
9 from pylons.controllers.util import redirect |
0 | 10 from pylons.templating import render_mako as render |
1304
5a96551ee9c0
gui-improvments
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
11 |
1613
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
12 from paste.deploy.converters import asbool |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
13 from paste.httpheaders import REMOTE_USER |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
14 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
15 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
|
16 from rhodecode.lib.auth import AuthUser |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
17 from rhodecode.lib.utils import get_repo_slug |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
18 from rhodecode.model import meta |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
19 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
|
20 from rhodecode import BACKENDS |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1351
diff
changeset
|
21 from rhodecode.model.db import Repository |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
22 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
23 log = logging.getLogger(__name__) |
1307 | 24 |
0 | 25 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
|
26 |
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
|
27 def __before__(self): |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
28 c.rhodecode_version = __version__ |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
29 c.rhodecode_name = config.get('rhodecode_title') |
891
cca7286401b3
fixes for #89 ga code
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
30 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
|
31 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
|
32 c.backends = BACKENDS.keys() |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
33 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
|
34 |
784
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
35 self.sa = meta.Session() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
36 self.scm_model = ScmModel(self.sa) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1351
diff
changeset
|
37 |
784
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
38 #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
|
39 |
0 | 40 def __call__(self, environ, start_response): |
41 """Invoke the Controller""" | |
42 # WSGIController.__call__ dispatches to the Controller method | |
43 # the request is routed to. This routing information is | |
44 # available in environ['pylons.routes_dict'] | |
45 try: | |
1307 | 46 # putting this here makes sure that we update permissions each 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
|
47 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
|
48 user_id = getattr(session.get('rhodecode_user'), 'user_id', None) |
1613
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
49 if asbool(config.get('container_auth_enabled', False)): |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
50 username = REMOTE_USER(environ) |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
51 else: |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
52 username = None |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
53 |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
54 self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key, username) |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
55 if not self.rhodecode_user.is_authenticated: |
6cab36e31f09
Added container-based authentication support
Liad Shani <liadff@gmail.com>
parents:
1373
diff
changeset
|
56 self.rhodecode_user.set_authenticated( |
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
|
57 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
|
58 '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
|
59 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
|
60 session.save() |
0 | 61 return WSGIController.__call__(self, environ, start_response) |
62 finally: | |
51 | 63 meta.Session.remove() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
64 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
65 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
66 class BaseRepoController(BaseController): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
67 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
68 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
|
69 for those controllers, loaded items are |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
70 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
71 c.rhodecode_repo: instance of scm repository (taken from cache) |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
72 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
73 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
74 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
75 def __before__(self): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
76 super(BaseRepoController, self).__before__() |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
77 if c.repo_name: |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
78 |
1530
04027bdb876c
Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
79 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name) |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
80 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
81 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
82 if c.rhodecode_repo is None: |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
83 log.error('%s this repository is present in database but it ' |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
84 'cannot be created as an scm instance', c.repo_name) |
1282
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
85 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
86 redirect(url('home')) |
1304
5a96551ee9c0
gui-improvments
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
87 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
88 c.repository_followers = \ |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
89 self.scm_model.get_followers(c.repo_name) |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
90 c.repository_forks = self.scm_model.get_forks(c.repo_name) |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
91 |