Mercurial > kallithea
annotate pylons_app/controllers/admin.py @ 197:da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Splited loggin and invalidation action to private methods inside simplehg.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 22 May 2010 19:29:50 +0200 |
parents | b68b2246e5a6 |
children | c8162373f214 |
rev | line source |
---|---|
43 | 1 import logging |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
2 import os |
43 | 3 |
4 from pylons import request, response, session, tmpl_context as c, url, app_globals as g | |
5 from pylons.controllers.util import abort, redirect | |
6 from pylons_app.lib.base import BaseController, render | |
62
4df4c0eac619
Updated admin to show last 5 actions + updated db model
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
7 from pylons_app.model import meta |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
8 from pylons_app.model.db import UserLogs |
78
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
9 from webhelpers.paginate import Page |
140
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
133
diff
changeset
|
10 from pylons_app.lib.utils import check_repo, invalidate_cache |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
11 from pylons_app.lib.auth import LoginRequired |
140
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
133
diff
changeset
|
12 |
43 | 13 log = logging.getLogger(__name__) |
14 | |
15 class AdminController(BaseController): | |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
16 |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
17 @LoginRequired() |
43 | 18 def __before__(self): |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
19 user = session['hg_app_user'] |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
20 c.admin_user = user.is_admin |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
21 c.admin_username = user.username |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
22 super(AdminController, self).__before__() |
43 | 23 |
24 def index(self): | |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
25 sa = meta.Session |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
26 |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
27 users_log = sa.query(UserLogs)\ |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
28 .order_by(UserLogs.action_date.desc()) |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
29 p = int(request.params.get('page', 1)) |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
30 c.users_log = Page(users_log, page=p, items_per_page=10) |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
31 c.log_data = render('admin/admin_log.html') |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
32 if request.params.get('partial'): |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
33 return c.log_data |
127
20dc7a5eb748
Html changes and cleanups, made folders for html templates, implemented tags and branches pages
Marcin Kuzminski <marcin@python-works.com>
parents:
125
diff
changeset
|
34 return render('admin/admin.html') |
43 | 35 |
36 def add_repo(self, new_repo): | |
37 #extra check it can be add since it's the command | |
44 | 38 if new_repo == '_admin': |
39 c.msg = 'DENIED' | |
43 | 40 c.new_repo = '' |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
41 return render('admin/add.html') |
43 | 42 |
43 new_repo = new_repo.replace(" ", "_") | |
44 new_repo = new_repo.replace("-", "_") | |
45 | |
46 try: | |
47 self._create_repo(new_repo) | |
48 c.new_repo = new_repo | |
49 c.msg = 'added repo' | |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
50 #clear our cached list for refresh with new repo |
171
52bbeb1e813f
Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents:
140
diff
changeset
|
51 invalidate_cache('cached_repo_list') |
43 | 52 except Exception as e: |
53 c.new_repo = 'Exception when adding: %s' % new_repo | |
54 c.msg = str(e) | |
55 | |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
56 return render('admin/add.html') |
43 | 57 |
58 | |
59 def _create_repo(self, repo_name): | |
60 if repo_name in [None, '', 'add']: | |
61 raise Exception('undefined repo_name of repo') | |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
62 repo_path = os.path.join(g.base_path, repo_name) |
125
2811259dc12d
Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
63 if check_repo(repo_name, g.base_path): |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
64 log.info('creating repo %s in %s', repo_name, repo_path) |
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
65 from vcs.backends.hg import MercurialRepository |
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
66 MercurialRepository(repo_path, create=True) |
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
67 |