Mercurial > kallithea
annotate pylons_app/controllers/admin.py @ 127:20dc7a5eb748
Html changes and cleanups, made folders for html templates, implemented tags and branches pages
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 03 May 2010 19:07:54 +0200 |
parents | 2811259dc12d |
children | 919b5bcd8630 |
rev | line source |
---|---|
43 | 1 import logging |
2 | |
3 from pylons import request, response, session, tmpl_context as c, url, app_globals as g | |
4 from pylons.controllers.util import abort, redirect | |
5 | |
6 from pylons_app.lib.base import BaseController, render | |
7 import os | |
44 | 8 from pylons_app.lib import auth |
45 | 9 from pylons_app.model.forms import LoginForm |
10 import formencode | |
11 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
|
12 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
|
13 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
|
14 from webhelpers.paginate import Page |
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
|
15 from pylons_app.lib.utils import check_repo |
43 | 16 log = logging.getLogger(__name__) |
17 | |
18 class AdminController(BaseController): | |
19 | |
20 def __before__(self): | |
101
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
79
diff
changeset
|
21 |
52 | 22 c.admin_user = session.get('admin_user', False) |
45 | 23 c.admin_username = session.get('admin_username') |
43 | 24 |
25 def index(self): | |
26 # Return a rendered template | |
45 | 27 if request.POST: |
28 #import Login Form validator class | |
29 login_form = LoginForm() | |
30 | |
31 try: | |
32 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
|
33 if auth.admin_auth(c.form_result['username'], c.form_result['password']): |
45 | 34 session['admin_user'] = True |
35 session['admin_username'] = c.form_result['username'] | |
36 session.save() | |
37 return redirect(url('admin_home')) | |
38 else: | |
39 raise formencode.Invalid('Login Error', None, None, | |
40 error_dict={'username':'invalid login', | |
41 'password':'invalid password'}) | |
42 | |
43 except formencode.Invalid, error: | |
44 c.form_result = error.value | |
45 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
|
46 html = render('admin/admin.html') |
45 | 47 |
48 return htmlfill.render( | |
49 html, | |
50 defaults=c.form_result, | |
51 encoding="UTF-8" | |
52 ) | |
62
4df4c0eac619
Updated admin to show last 5 actions + updated db model
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
53 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
|
54 sa = meta.Session |
78
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
55 |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
56 users_log = sa.query(UserLogs)\ |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
57 .order_by(UserLogs.action_date.desc()) |
6f524697f79d
Implemented paging to admin user acion log
Marcin Kuzminski <marcin@python-blog.com>
parents:
75
diff
changeset
|
58 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
|
59 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
|
60 c.log_data = render('admin/admin_log.html') |
79
9fe23fdab9e9
Implemented AJAH paging
Marcin Kuzminski <marcin@python-blog.com>
parents:
78
diff
changeset
|
61 if request.params.get('partial'): |
9fe23fdab9e9
Implemented AJAH paging
Marcin Kuzminski <marcin@python-blog.com>
parents:
78
diff
changeset
|
62 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
|
63 return render('admin/admin.html') |
43 | 64 |
65 def hgrc(self, dirname): | |
66 filename = os.path.join(dirname, '.hg', 'hgrc') | |
67 return filename | |
68 | |
69 def add_repo(self, new_repo): | |
70 | |
71 | |
72 #extra check it can be add since it's the command | |
44 | 73 if new_repo == '_admin': |
74 c.msg = 'DENIED' | |
43 | 75 c.new_repo = '' |
76 return render('add.html') | |
77 | |
78 new_repo = new_repo.replace(" ", "_") | |
79 new_repo = new_repo.replace("-", "_") | |
80 | |
81 try: | |
82 self._create_repo(new_repo) | |
83 c.new_repo = new_repo | |
84 c.msg = 'added repo' | |
85 except Exception as e: | |
86 c.new_repo = 'Exception when adding: %s' % new_repo | |
87 c.msg = str(e) | |
88 | |
89 return render('add.html') | |
90 | |
91 | |
92 def _create_repo(self, repo_name): | |
93 if repo_name in [None, '', 'add']: | |
94 raise Exception('undefined repo_name of repo') | |
95 | |
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
|
96 if check_repo(repo_name, g.base_path): |
43 | 97 log.info('creating repo %s in %s', repo_name, self.repo_path) |
98 cmd = """mkdir %s && hg init %s""" \ | |
99 % (self.repo_path, self.repo_path) | |
100 os.popen(cmd) |