##// END OF EJS Templates
forms: added RcForm with custom error reporting widget.
marcink -
r1715:805107e8 default
parent child Browse files
Show More
@@ -1,33 +1,49 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22 Base module for form rendering / validation - currently just a wrapper for
23 23 deform - later can be replaced with something custom.
24 24 """
25 25
26 26 from rhodecode.translation import _
27 from rhodecode.translation import TranslationString
28
29 from mako.template import Template
27 30 from deform import Button, Form, widget, ValidationFailure
28 31
29 32
30 33 class buttons:
31 34 save = Button(name='Save', type='submit')
32 35 reset = Button(name=_('Reset'), type='reset')
33 36 delete = Button(name=_('Delete'), type='submit')
37
38
39 class RcForm(Form):
40 def render_error(self, request, field):
41 html = ''
42 if field.error:
43 for err in field.error.messages():
44 if isinstance(err, TranslationString):
45 err = request.translate(err)
46 html = Template(
47 '<span class="error-message">${err}</span>').render(err=err)
48
49 return html
General Comments 0
You need to be logged in to leave comments. Login now