##// END OF EJS Templates
fixed warning message
marcink -
r772:82265952 beta
parent child Browse files
Show More
@@ -1,106 +1,106 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 package.rhodecode.controllers.admin.ldap_settings
4 4 ~~~~~~~~~~~~~~
5 5
6 6 ldap controller for RhodeCode
7 7 :created_on: Nov 26, 2010
8 8 :author: marcink
9 9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 10 :license: GPLv3, see COPYING for more details.
11 11 """
12 12 # This program is free software; you can redistribute it and/or
13 13 # modify it under the terms of the GNU General Public License
14 14 # as published by the Free Software Foundation; version 2
15 15 # of the License or (at your opinion) any later version of the license.
16 16 #
17 17 # This program is distributed in the hope that it will be useful,
18 18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 20 # GNU General Public License for more details.
21 21 #
22 22 # You should have received a copy of the GNU General Public License
23 23 # along with this program; if not, write to the Free Software
24 24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 25 # MA 02110-1301, USA.
26 26 import logging
27 27 import formencode
28 28 import traceback
29 29
30 30 from formencode import htmlfill
31 31
32 32 from pylons import request, response, session, tmpl_context as c, url
33 33 from pylons.controllers.util import abort, redirect
34 34 from pylons.i18n.translation import _
35 35
36 36 from rhodecode.lib.base import BaseController, render
37 37 from rhodecode.lib import helpers as h
38 38 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
39 39 from rhodecode.lib.auth_ldap import LdapImportError
40 40 from rhodecode.model.settings import SettingsModel
41 41 from rhodecode.model.forms import LdapSettingsForm
42 42 from sqlalchemy.exc import DatabaseError
43 43
44 44 log = logging.getLogger(__name__)
45 45
46 46
47 47
48 48 class LdapSettingsController(BaseController):
49 49
50 50 @LoginRequired()
51 51 @HasPermissionAllDecorator('hg.admin')
52 52 def __before__(self):
53 53 c.admin_user = session.get('admin_user')
54 54 c.admin_username = session.get('admin_username')
55 55 super(LdapSettingsController, self).__before__()
56 56
57 57 def index(self):
58 58 defaults = SettingsModel().get_ldap_settings()
59 59
60 60 return htmlfill.render(
61 61 render('admin/ldap/ldap.html'),
62 62 defaults=defaults,
63 63 encoding="UTF-8",
64 64 force_defaults=True,)
65 65
66 66 def ldap_settings(self):
67 67 """
68 68 POST ldap create and store ldap settings
69 69 """
70 70
71 71 settings_model = SettingsModel()
72 72 _form = LdapSettingsForm()()
73 73
74 74 try:
75 75 form_result = _form.to_python(dict(request.POST))
76 76 try:
77 77
78 78 for k, v in form_result.items():
79 79 if k.startswith('ldap_'):
80 80 setting = settings_model.get(k)
81 81 setting.app_settings_value = v
82 82 self.sa.add(setting)
83 83
84 84 self.sa.commit()
85 85 h.flash(_('Ldap settings updated successfully'),
86 86 category='success')
87 87 except (DatabaseError,):
88 88 raise
89 89 except LdapImportError:
90 h.flash(_('Unable to activate ldap. The "ldap-python" library '
90 h.flash(_('Unable to activate ldap. The "python-ldap" library '
91 91 'is missing.'), category='warning')
92 92
93 93 except formencode.Invalid, errors:
94 94
95 95 return htmlfill.render(
96 96 render('admin/ldap/ldap.html'),
97 97 defaults=errors.value,
98 98 errors=errors.error_dict or {},
99 99 prefix_error=False,
100 100 encoding="UTF-8")
101 101 except Exception:
102 102 log.error(traceback.format_exc())
103 103 h.flash(_('error occured during update of ldap settings'),
104 104 category='error')
105 105
106 106 return redirect(url('ldap_home'))
General Comments 0
You need to be logged in to leave comments. Login now