comparison pylons_app/controllers/settings.py @ 320:05b212954275

Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 30 Jun 2010 15:35:10 +0200
parents
children 1ef52a70f3b7
comparison
equal deleted inserted replaced
319:c12f4d19c950 320:05b212954275
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # settings controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on June 30, 2010
22 settings controller for pylons
23 @author: marcink
24 """
25 from formencode import htmlfill
26 from pylons import tmpl_context as c, request, url
27 from pylons.controllers.util import redirect
28 from pylons.i18n.translation import _
29 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAllDecorator
30 from pylons_app.lib.base import BaseController, render
31 from pylons_app.lib.utils import invalidate_cache
32 from pylons_app.model.forms import RepoSettingsForm
33 from pylons_app.model.repo_model import RepoModel
34 import formencode
35 import logging
36 import pylons_app.lib.helpers as h
37 log = logging.getLogger(__name__)
38
39 class SettingsController(BaseController):
40
41 @LoginRequired()
42 @HasRepoPermissionAllDecorator('repository.admin')
43 def __before__(self):
44 super(SettingsController, self).__before__()
45
46 def index(self, repo_name):
47 repo_model = RepoModel()
48 c.repo_info = repo = repo_model.get(repo_name)
49 if not repo:
50 h.flash(_('%s repository is not mapped to db perhaps'
51 ' it was created or renamed from the filesystem'
52 ' please run the application again'
53 ' in order to rescan repositories') % repo_name,
54 category='error')
55
56 return redirect(url('repos'))
57 defaults = c.repo_info.__dict__
58 defaults.update({'user':c.repo_info.user.username})
59 c.users_array = repo_model.get_users_js()
60
61 for p in c.repo_info.repo2perm:
62 defaults.update({'perm_%s' % p.user.username:
63 p.permission.permission_name})
64
65 return htmlfill.render(
66 render('settings/repo_settings.html'),
67 defaults=defaults,
68 encoding="UTF-8",
69 force_defaults=False
70 )
71
72 def update(self, repo_name):
73 print request.POST
74 print 'x' * 110
75 repo_model = RepoModel()
76 _form = RepoSettingsForm(edit=True)()
77 try:
78 form_result = _form.to_python(dict(request.POST))
79 repo_model.update(repo_name, form_result)
80 invalidate_cache('cached_repo_list')
81 h.flash(_('Repository %s updated succesfully' % repo_name),
82 category='success')
83
84 except formencode.Invalid as errors:
85 c.repo_info = repo_model.get(repo_name)
86 c.users_array = repo_model.get_users_js()
87 errors.value.update({'user':c.repo_info.user.username})
88 c.form_errors = errors.error_dict
89 return htmlfill.render(
90 render('admin/repos/repo_edit.html'),
91 defaults=errors.value,
92 encoding="UTF-8")
93 except Exception:
94 h.flash(_('error occured during update of repository %s') \
95 % form_result['repo_name'], category='error')
96
97 return redirect(url('repo_settings_home', repo_name=repo_name))