site_cubicweb.py 3 KB
Newer Older
1
# copyright 2013-2022 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
Nicola Spanti's avatar
Nicola Spanti committed
2
# contact https://www.logilab.fr/ -- mailto:contact@logilab.fr
Sylvain Thénault's avatar
Sylvain Thénault committed
3
4
5
6
7
8
9
10
11
12
13
14
#
# This program is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
Nicola Spanti's avatar
Nicola Spanti committed
15
# with this program. If not, see <https://www.gnu.org/licenses/>.
Sylvain Thénault's avatar
Sylvain Thénault committed
16
"""this is where you could register procedures for instance"""
17
__docformat__ = "restructuredtext en"
18
19
20

from logilab.common.decorators import monkeypatch

21
22
from cubicweb.web import formwidgets, stdmsgs

23
from cubicweb_bootstrap import monkeypatch_default_value
24
25
26
27
28
29
30
31
32
33

# put there monkeypatches of things that aren't reloaded automatically

# monkeypatches #############################################################

# keep the original `formwidgets.FieldWidget.attributes`
orig_attributes = formwidgets.FieldWidget.attributes

formwidgets.FieldWidget.css_class = 'form-control'

34
# Keep the `validateButton` as it is used in js (e.g `unfreezeFormButtons`)
35
formwidgets.ButtonInput.css_class = 'btn btn-default'
36
37
38
formwidgets.Button.css_class = 'btn btn-default validateButton'
formwidgets.SubmitButton.css_class = 'btn btn-primary validateButton'

Sylvain Thénault's avatar
pep8    
Sylvain Thénault committed
39

40
41
42
43
44
45
46
47
48
49
@monkeypatch(formwidgets.FieldWidget)
def attributes(self, form, field):
    """ add the bootstrap `form-control` class to formwidgets.FieldWidget.attributes method
    """
    attrs = orig_attributes(self, form, field)
    if self.css_class:
        attrs['class'] = ' '.join((attrs.get('class', ''),
                                   self.css_class)).strip()
    return attrs

50
51
# in bootstrap 3.0.0 CheckBox, RadioBox and FileInput must not have
# form-control class
52
53


54
formwidgets.CheckBox.attributes = orig_attributes
55
formwidgets.FileInput.attributes = orig_attributes
56

57
58
59
60
61
62
63
64
65
66

# Buttons
stdmsgs.BUTTON_OK = (stdmsgs.BUTTON_OK[0], 'glyphicon glyphicon-ok')
stdmsgs.BUTTON_APPLY = (stdmsgs.BUTTON_APPLY[0], 'glyphicon glyphicon-cog')
stdmsgs.BUTTON_CANCEL = (stdmsgs.BUTTON_CANCEL[0], 'glyphicon glyphicon-remove')
stdmsgs.BUTTON_DELETE = (stdmsgs.BUTTON_DELETE[0], 'glyphicon glyphicon-trash')


# Override default form buttons to 'btn-class' and use bootstrap glyphicons.

Sylvain Thénault's avatar
pep8    
Sylvain Thénault committed
67
68
69
70
71

monkeypatch_default_value(formwidgets.Button.__init__, 'label',
                          (stdmsgs.BUTTON_OK[0], 'glyphicon glyphicon-ok'))


72
# options #############################################################
73
74
75

options = (
    ('cw_compatibility',
Sylvain Thénault's avatar
pep8    
Sylvain Thénault committed
76
     {'type': 'yn',
77
      'default': False,
Sylvain Thénault's avatar
pep8    
Sylvain Thénault committed
78
79
80
      'help': 'use compat css rules (enable if your application uses views '
      'that have not been ported to bootstrap)',
      'group': 'bootstrap', 'level': 2}),
81
)