Mercurial > public > src > rhodecode
annotate pylons_app/controllers/admin/settings.py @ 412:ca54622e39a1
Added separate create repository views for non administrative users.
Fixed permission issue with private repos
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 01 Aug 2010 17:08:58 +0200 |
parents | 5cd6616b8673 |
children | 55377fdc1fc6 |
rev | line source |
---|---|
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 # encoding: utf-8 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 # settings controller for pylons |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
385
339d1368c10d
new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
5 # |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 # This program is free software; you can redistribute it and/or |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # modify it under the terms of the GNU General Public License |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # of the License or (at your opinion) any later version of the license. |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # GNU General Public License for more details. |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # MA 02110-1301, USA. |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 """ |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 Created on July 14, 2010 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 settings controller for pylons |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 @author: marcink |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 """ |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 from formencode import htmlfill |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
26 from pylons import request, session, tmpl_context as c, url, app_globals as g, \ |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
27 config |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 from pylons.controllers.util import abort, redirect |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from pylons.i18n.translation import _ |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 from pylons_app.lib import helpers as h |
412
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
31 from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
32 HasPermissionAnyDecorator |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 from pylons_app.lib.base import BaseController, render |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
34 from pylons_app.lib.utils import repo2db_mapper, invalidate_cache, \ |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
35 set_hg_app_config |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
36 from pylons_app.model.db import User, UserLog, HgAppSettings |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
37 from pylons_app.model.forms import UserForm, ApplicationSettingsForm |
372
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
38 from pylons_app.model.hg_model import HgModel |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 from pylons_app.model.user_model import UserModel |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 import formencode |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 import logging |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
42 import traceback |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
43 |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 log = logging.getLogger(__name__) |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 class SettingsController(BaseController): |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 """REST Controller styled on the Atom Publishing Protocol""" |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 # To properly map this controller, ensure your config/routing.py |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 # file has a resource setup: |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 # map.resource('setting', 'settings', controller='admin/settings', |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 # path_prefix='/admin', name_prefix='admin_') |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 @LoginRequired() |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 def __before__(self): |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 c.admin_user = session.get('admin_user') |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 c.admin_username = session.get('admin_username') |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 super(SettingsController, self).__before__() |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
60 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
61 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
62 @HasPermissionAllDecorator('hg.admin') |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 def index(self, format='html'): |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 """GET /admin/settings: All items in the collection""" |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 # url('admin_settings') |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
66 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
67 hgsettings = self.sa.query(HgAppSettings).scalar() |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
68 defaults = hgsettings.__dict__ if hgsettings else {} |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
69 return htmlfill.render( |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
70 render('admin/settings/settings.html'), |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
71 defaults=defaults, |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
72 encoding="UTF-8", |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
73 force_defaults=False |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
74 ) |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
76 @HasPermissionAllDecorator('hg.admin') |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 def create(self): |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 """POST /admin/settings: Create a new item""" |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 # url('admin_settings') |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
80 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
81 @HasPermissionAllDecorator('hg.admin') |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 def new(self, format='html'): |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 """GET /admin/settings/new: Form to create a new item""" |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 # url('admin_new_setting') |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
85 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
86 @HasPermissionAllDecorator('hg.admin') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
87 def update(self, setting_id): |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
88 """PUT /admin/settings/setting_id: Update an existing item""" |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 # Forms posted to this method should contain a hidden field: |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 # <input type="hidden" name="_method" value="PUT" /> |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 # Or using helpers: |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
92 # h.form(url('admin_setting', setting_id=ID), |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 # method='put') |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
94 # url('admin_setting', setting_id=ID) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
95 if setting_id == 'mapping': |
372
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
96 rm_obsolete = request.POST.get('destroy', False) |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
97 log.debug('Rescanning directories with destroy=%s', rm_obsolete) |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
98 |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
99 initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
100 repo2db_mapper(initial, rm_obsolete) |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
101 invalidate_cache('cached_repo_list') |
385
339d1368c10d
new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
102 h.flash(_('Repositories sucessfully rescanned'), category='success') |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
103 |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
104 if setting_id == 'global': |
372
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
105 |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
106 application_form = ApplicationSettingsForm()() |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
107 try: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
108 form_result = application_form.to_python(dict(request.POST)) |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
109 title = form_result['app_title'] |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
110 realm = form_result['app_auth_realm'] |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
111 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
112 try: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
113 hgsettings = self.sa.query(HgAppSettings).get(1) |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
114 hgsettings.app_auth_realm = realm |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
115 hgsettings.app_title = title |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
116 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
117 self.sa.add(hgsettings) |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
118 self.sa.commit() |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
119 set_hg_app_config(config) |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
120 h.flash(_('Updated application settings'), |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
121 category='success') |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
122 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
123 except: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
124 log.error(traceback.format_exc()) |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
125 h.flash(_('error occured during chaning application settings'), |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
126 category='error') |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
127 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
128 self.sa.rollback() |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
129 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
130 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
131 except formencode.Invalid as errors: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
132 return htmlfill.render( |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
133 render('admin/settings/settings.html'), |
385
339d1368c10d
new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
134 defaults=errors.value, |
339d1368c10d
new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
135 errors=errors.error_dict or {}, |
339d1368c10d
new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
136 prefix_error=False, |
339d1368c10d
new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
137 encoding="UTF-8") |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
372
diff
changeset
|
138 |
372
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
369
diff
changeset
|
139 return redirect(url('admin_settings')) |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
140 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
141 @HasPermissionAllDecorator('hg.admin') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
142 def delete(self, setting_id): |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
143 """DELETE /admin/settings/setting_id: Delete an existing item""" |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 # Forms posted to this method should contain a hidden field: |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 # <input type="hidden" name="_method" value="DELETE" /> |
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 # Or using helpers: |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
147 # h.form(url('admin_setting', setting_id=ID), |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 # method='delete') |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
149 # url('admin_setting', setting_id=ID) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
150 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
151 @HasPermissionAllDecorator('hg.admin') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
152 def show(self, setting_id, format='html'): |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
153 """GET /admin/settings/setting_id: Show a specific item""" |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
154 # url('admin_setting', setting_id=ID) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
155 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
156 @HasPermissionAllDecorator('hg.admin') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
157 def edit(self, setting_id, format='html'): |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
158 """GET /admin/settings/setting_id/edit: Form to edit an existing item""" |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
159 # url('admin_edit_setting', setting_id=ID) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
160 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
161 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
162 def my_account(self): |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
163 """ |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
164 GET /_admin/my_account Displays info about my account |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
165 """ |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
166 # url('admin_settings_my_account') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
167 c.user = self.sa.query(User).get(c.hg_app_user.user_id) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
168 if c.user.username == 'default': |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
169 h.flash(_("You can't edit this user since it's" |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
170 " crucial for entire application"), category='warning') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
171 return redirect(url('users')) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
172 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
173 defaults = c.user.__dict__ |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
174 return htmlfill.render( |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
175 render('admin/users/user_edit_my_account.html'), |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
176 defaults=defaults, |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
177 encoding="UTF-8", |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
178 force_defaults=False |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
179 ) |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
181 def my_account_update(self): |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
182 """PUT /_admin/my_account_update: Update an existing item""" |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
183 # Forms posted to this method should contain a hidden field: |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
184 # <input type="hidden" name="_method" value="PUT" /> |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
185 # Or using helpers: |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
186 # h.form(url('admin_settings_my_account_update'), |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
187 # method='put') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
188 # url('admin_settings_my_account_update', id=ID) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
189 user_model = UserModel() |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
190 uid = c.hg_app_user.user_id |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
191 _form = UserForm(edit=True, old_data={'user_id':uid})() |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
192 form_result = {} |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
193 try: |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
194 form_result = _form.to_python(dict(request.POST)) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
195 user_model.update_my_account(uid, form_result) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
196 h.flash(_('Your account was updated succesfully'), category='success') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
197 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
198 except formencode.Invalid as errors: |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
199 #c.user = self.sa.query(User).get(c.hg_app_user.user_id) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
200 return htmlfill.render( |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
201 render('admin/users/user_edit_my_account.html'), |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
202 defaults=errors.value, |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
203 errors=errors.error_dict or {}, |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
204 prefix_error=False, |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
205 encoding="UTF-8") |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
206 except Exception: |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
207 log.error(traceback.format_exc()) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
208 h.flash(_('error occured during update of user %s') \ |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
209 % form_result.get('username'), category='error') |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
210 |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
211 return redirect(url('my_account')) |
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
212 |
412
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
213 @HasPermissionAnyDecorator('repository.create', 'hg.admin') |
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
214 def create_repository(self): |
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
215 """GET /_admin/create_repository: Form to create a new item""" |
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
216 new_repo = request.GET.get('repo', '') |
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
217 c.new_repo = h.repo_name_slug(new_repo) |
369
51362853ac3b
added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 |
412
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
219 return render('admin/repos/repo_add_create_repository.html') |
ca54622e39a1
Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
220 |