annotate pylons_app/controllers/admin.py @ 191:b68b2246e5a6

Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user. Removed login form from admin.
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 May 2010 01:47:07 +0200
parents 52bbeb1e813f
children c8162373f214
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
3
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
4 from pylons import request, response, session, tmpl_context as c, url, app_globals as g
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
5 from pylons.controllers.util import abort, redirect
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
13 log = logging.getLogger(__name__)
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
14
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
23
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
35
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
36 def add_repo(self, new_repo):
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
37 #extra check it can be add since it's the command
44
d924b931b488 Added managment pages.
marcink
parents: 43
diff changeset
38 if new_repo == '_admin':
d924b931b488 Added managment pages.
marcink
parents: 43
diff changeset
39 c.msg = 'DENIED'
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
42
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
43 new_repo = new_repo.replace(" ", "_")
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
44 new_repo = new_repo.replace("-", "_")
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
45
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
46 try:
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
47 self._create_repo(new_repo)
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
48 c.new_repo = new_repo
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
52 except Exception as e:
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
53 c.new_repo = 'Exception when adding: %s' % new_repo
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
54 c.msg = str(e)
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
57
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
58
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
59 def _create_repo(self, repo_name):
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
60 if repo_name in [None, '', 'add']:
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents:
diff changeset
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