Mercurial > kallithea
annotate pylons_app/controllers/admin.py @ 172:83c7ee1b5f5c
improved timerproxy with sqllogging, and new way of sqlformat queries
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 21 May 2010 03:01:31 +0200 |
parents | 52bbeb1e813f |
children | b68b2246e5a6 |
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 | |
44 | 7 from pylons_app.lib import auth |
45 | 8 from pylons_app.model.forms import LoginForm |
9 import formencode | |
10 import formencode.htmlfill as htmlfill | |
62
4df4c0eac619
Updated admin to show last 5 actions + updated db model
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
11 from pylons_app.model import meta |
4df4c0eac619
Updated admin to show last 5 actions + updated db model
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
12 from pylons_app.model.db import Users, UserLogs |
78
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
13 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
|
14 from pylons_app.lib.utils import check_repo, invalidate_cache |
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
133
diff
changeset
|
15 |
43 | 16 log = logging.getLogger(__name__) |
17 | |
18 class AdminController(BaseController): | |
19 | |
20 def __before__(self): | |
52 | 21 c.admin_user = session.get('admin_user', False) |
45 | 22 c.admin_username = session.get('admin_username') |
43 | 23 |
24 def index(self): | |
25 # Return a rendered template | |
45 | 26 if request.POST: |
27 #import Login Form validator class | |
28 login_form = LoginForm() | |
29 | |
30 try: | |
31 c.form_result = login_form.to_python(dict(request.params)) | |
46
9db7782727b3
Static files for production fixed
Marcin Kuzminski <marcin@python-blog.com>
parents:
45
diff
changeset
|
32 if auth.admin_auth(c.form_result['username'], c.form_result['password']): |
45 | 33 session['admin_user'] = True |
34 session['admin_username'] = c.form_result['username'] | |
35 session.save() | |
36 return redirect(url('admin_home')) | |
37 else: | |
38 raise formencode.Invalid('Login Error', None, None, | |
39 error_dict={'username':'invalid login', | |
40 'password':'invalid password'}) | |
41 | |
42 except formencode.Invalid, error: | |
43 c.form_result = error.value | |
44 c.form_errors = error.error_dict or {} | |
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
|
45 html = render('admin/admin.html') |
45 | 46 |
47 return htmlfill.render( | |
48 html, | |
49 defaults=c.form_result, | |
50 encoding="UTF-8" | |
51 ) | |
62
4df4c0eac619
Updated admin to show last 5 actions + updated db model
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
52 if c.admin_user: |
4df4c0eac619
Updated admin to show last 5 actions + updated db model
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
53 sa = meta.Session |
78
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
54 |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
55 users_log = sa.query(UserLogs)\ |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
56 .order_by(UserLogs.action_date.desc()) |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
57 p = int(request.params.get('page', 1)) |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
58 c.users_log = Page(users_log, page=p, items_per_page=10) |
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
|
59 c.log_data = render('admin/admin_log.html') |
79
9fe23fdab9e9
Implemented AJAH paging
Marcin Kuzminski <marcin@python-blog.com>
parents:
78
diff
changeset
|
60 if request.params.get('partial'): |
9fe23fdab9e9
Implemented AJAH paging
Marcin Kuzminski <marcin@python-blog.com>
parents:
78
diff
changeset
|
61 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
|
62 return render('admin/admin.html') |
43 | 63 |
64 def hgrc(self, dirname): | |
65 filename = os.path.join(dirname, '.hg', 'hgrc') | |
66 return filename | |
67 | |
68 def add_repo(self, new_repo): | |
69 | |
70 | |
71 #extra check it can be add since it's the command | |
44 | 72 if new_repo == '_admin': |
73 c.msg = 'DENIED' | |
43 | 74 c.new_repo = '' |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
75 return render('admin/add.html') |
43 | 76 |
77 new_repo = new_repo.replace(" ", "_") | |
78 new_repo = new_repo.replace("-", "_") | |
79 | |
80 try: | |
81 self._create_repo(new_repo) | |
82 c.new_repo = new_repo | |
83 c.msg = 'added repo' | |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
84 #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
|
85 invalidate_cache('cached_repo_list') |
43 | 86 except Exception as e: |
87 c.new_repo = 'Exception when adding: %s' % new_repo | |
88 c.msg = str(e) | |
89 | |
133
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
90 return render('admin/add.html') |
43 | 91 |
92 | |
93 def _create_repo(self, repo_name): | |
94 if repo_name in [None, '', 'add']: | |
95 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
|
96 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
|
97 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
|
98 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
|
99 from vcs.backends.hg import MercurialRepository |
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
100 MercurialRepository(repo_path, create=True) |
919b5bcd8630
Changed creation of repository to vcs implementation,
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
101 |