author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 13 May 2015 17:13:00 +0200 | |
changeset 10422 | 2b54acb271cb |
parent 10278 | 90aab6ddf6d8 |
child 10662 | 10942ed172de |
permissions | -rw-r--r-- |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8128
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4361
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6545 | 18 |
"""Specific views for CWProperty (eg site/user preferences""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
1641 | 21 |
_ = unicode |
0 | 22 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2225
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
24 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
25 |
from logilab.common.decorators import cached |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
26 |
|
1309 | 27 |
from cubicweb import UnknownProperty |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8128
diff
changeset
|
28 |
from cubicweb.predicates import (one_line_rset, none_rset, is_instance, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8128
diff
changeset
|
29 |
match_user_groups, logged_user_in_rset) |
984 | 30 |
from cubicweb.view import StartupView |
8665
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
31 |
from cubicweb.web import stdmsgs |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1995
diff
changeset
|
32 |
from cubicweb.web.form import FormViewMixIn |
1309 | 33 |
from cubicweb.web.formfields import FIELDS, StringField |
5502
c342531032a1
[selectors] new logged_user_in_rset selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
34 |
from cubicweb.web.formwidgets import (Select, TextInput, Button, SubmitButton, |
c342531032a1
[selectors] new logged_user_in_rset selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
35 |
FieldWidget) |
8665
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
36 |
from cubicweb.web.views import uicfg, primary, formrenderers, editcontroller |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
37 |
from cubicweb.web.views.ajaxcontroller import ajaxfunc |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
38 |
|
4361
887c92793407
add CWProperty for_user CWUser when on the user primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4360
diff
changeset
|
39 |
uicfg.primaryview_section.tag_object_of(('*', 'for_user', '*'), 'hidden') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
40 |
|
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
41 |
# some string we want to be internationalizable for nicer display of property |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
42 |
# groups |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
43 |
_('navigation') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
44 |
_('ui') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
45 |
_('boxes') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
46 |
_('components') |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
47 |
_('ctxcomponents') |
1641 | 48 |
_('navigation.combobox-limit') |
49 |
_('navigation.page-size') |
|
50 |
_('navigation.related-limit') |
|
51 |
_('navigation.short-line-size') |
|
52 |
_('ui.date-format') |
|
53 |
_('ui.datetime-format') |
|
54 |
_('ui.default-text-format') |
|
55 |
_('ui.fckeditor') |
|
56 |
_('ui.float-format') |
|
57 |
_('ui.language') |
|
58 |
_('ui.time-format') |
|
59 |
_('open all') |
|
60 |
_('ui.main-template') |
|
61 |
_('ui.site-title') |
|
62 |
_('ui.encoding') |
|
63 |
_('category') |
|
0 | 64 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
65 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
66 |
def make_togglable_link(nodeid, label): |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
67 |
"""builds a HTML link that switches the visibility & remembers it""" |
6545 | 68 |
return u'<a href="javascript: togglePrefVisibility(\'%s\')">%s</a>' % ( |
69 |
nodeid, label) |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
70 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
71 |
def css_class(someclass): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
72 |
return someclass and 'class="%s"' % someclass or '' |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
73 |
|
1309 | 74 |
|
1658
3f3672f76399
delete-trailing-whitespaces, update import
sylvain.thenault@logilab.fr
parents:
1641
diff
changeset
|
75 |
class CWPropertyPrimaryView(primary.PrimaryView): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5819
diff
changeset
|
76 |
__select__ = is_instance('CWProperty') |
1309 | 77 |
skip_none = False |
78 |
||
79 |
||
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
80 |
class SystemCWPropertiesForm(FormViewMixIn, StartupView): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
81 |
"""site-wide properties edition form""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
82 |
__regid__ = 'systempropertiesform' |
1309 | 83 |
__select__ = none_rset() & match_user_groups('managers') |
4216
6c9e67a89b3a
[forms] make it easier to override CWProperty form buttons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4212
diff
changeset
|
84 |
form_buttons = [SubmitButton()] |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
85 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
86 |
title = _('site configuration') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
87 |
category = 'startupview' |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
88 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
89 |
def linkable(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
90 |
return True |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
91 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
92 |
def url(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
93 |
"""return the url associated with this view. We can omit rql here""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
94 |
return self._cw.build_url('view', vid=self.__regid__) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
95 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
96 |
def _cookie_name(self, somestr): |
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
97 |
return str('%s_property_%s' % (self._cw.vreg.config.appid, somestr)) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
98 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
99 |
def _group_status(self, group, default=u'hidden'): |
1309 | 100 |
"""return css class name 'hidden' (collapsed), or '' (open)""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
101 |
cookies = self._cw.get_cookie() |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
102 |
cookiename = self._cookie_name(group) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
103 |
cookie = cookies.get(cookiename) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
104 |
if cookie is None: |
7855
54283a5b7afc
[web request]Â fix cookie 'expires' formating (closes #1953945)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
105 |
self._cw.set_cookie(cookiename, default, maxage=None) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
106 |
status = default |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
107 |
else: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
108 |
status = cookie.value |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
109 |
return status |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
110 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
111 |
def call(self, **kwargs): |
6545 | 112 |
self._cw.add_js(('cubicweb.preferences.js', |
113 |
'cubicweb.edition.js', 'cubicweb.ajax.js')) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
114 |
self._cw.add_css('cubicweb.preferences.css') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
115 |
values = self.defined_keys |
7829
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
116 |
mainopts, groupedopts = self.group_properties() |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
117 |
# precompute all forms first to consume error message |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
118 |
mainforms, groupedforms = self.build_forms(mainopts, groupedopts) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
119 |
_ = self._cw._ |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
120 |
self.w(u'<h1>%s</h1>\n' % _(self.title)) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
121 |
for label, group, form in sorted((_(g), g, f) |
7829
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
122 |
for g, f in mainforms.iteritems()): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
123 |
self.wrap_main_form(group, label, form) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
124 |
for label, group, objects in sorted((_(g), g, o) |
7829
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
125 |
for g, o in groupedforms.iteritems()): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
126 |
self.wrap_grouped_form(group, label, objects) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
127 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
128 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
129 |
@cached |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
130 |
def cwprops_rset(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
131 |
return self._cw.execute('Any P,K,V WHERE P is CWProperty, P pkey K, ' |
1309 | 132 |
'P value V, NOT P for_user U') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
133 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
134 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
135 |
def defined_keys(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
136 |
values = {} |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
137 |
for i, entity in enumerate(self.cwprops_rset.entities()): |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
138 |
values[entity.pkey] = i |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
139 |
return values |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
140 |
|
7829
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
141 |
def group_properties(self): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
142 |
mainopts, groupedopts = {}, {} |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
143 |
vreg = self._cw.vreg |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
144 |
# "self._regid__=='systempropertiesform'" to skip site wide properties on |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
145 |
# user's preference but not site's configuration |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
146 |
for key in vreg.user_property_keys(self.__regid__=='systempropertiesform'): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
147 |
parts = key.split('.') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
148 |
if parts[0] in vreg and len(parts) >= 3: |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
149 |
# appobject configuration |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
150 |
reg = parts[0] |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
151 |
propid = parts[-1] |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
152 |
oid = '.'.join(parts[1:-1]) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
153 |
groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
154 |
else: |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
155 |
mainopts.setdefault(parts[0], []).append(key) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
156 |
return mainopts, groupedopts |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
157 |
|
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
158 |
def build_forms(self, mainopts, groupedopts): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
159 |
mainforms, groupedforms = {}, {} |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
160 |
for group, keys in mainopts.items(): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
161 |
mainforms[group] = self.form(group, keys, False) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
162 |
for group, objects in groupedopts.items(): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
163 |
groupedforms[group] = {} |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
164 |
for oid, keys in objects.items(): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
165 |
groupedforms[group][oid] = self.form(group + '_' + oid, keys, True) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
166 |
return mainforms, groupedforms |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
167 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
168 |
def entity_for_key(self, key): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
169 |
values = self.defined_keys |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
170 |
if key in values: |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
171 |
entity = self.cwprops_rset.get_entity(values[key], 0) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
172 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
173 |
entity = self._cw.vreg['etypes'].etype_class('CWProperty')(self._cw) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
174 |
entity.eid = self._cw.varmaker.next() |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
175 |
entity.cw_attr_cache['pkey'] = key |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
176 |
entity.cw_attr_cache['value'] = self._cw.vreg.property_value(key) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
177 |
return entity |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
178 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
179 |
def form(self, formid, keys, splitlabel=False): |
4265
0912f111b028
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4259
diff
changeset
|
180 |
form = self._cw.vreg['forms'].select( |
0912f111b028
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4259
diff
changeset
|
181 |
'composite', self._cw, domid=formid, action=self._cw.build_url(), |
4216
6c9e67a89b3a
[forms] make it easier to override CWProperty form buttons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4212
diff
changeset
|
182 |
form_buttons=self.form_buttons, |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2585
diff
changeset
|
183 |
onsubmit="return validatePrefsForm('%s')" % formid, |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
184 |
submitmsg=self._cw._('changes applied')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
185 |
path = self._cw.relative_path() |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
186 |
if '?' in path: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
187 |
path, params = path.split('?', 1) |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
188 |
form.add_hidden('__redirectparams', params) |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
189 |
form.add_hidden('__redirectpath', path) |
1507 | 190 |
for key in keys: |
1309 | 191 |
self.form_row(form, key, splitlabel) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
192 |
renderer = self._cw.vreg['formrenderers'].select('cwproperties', self._cw, |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2585
diff
changeset
|
193 |
display_progress_div=False) |
6453
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
194 |
data = [] |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
195 |
form.render(w=data.append, renderer=renderer) |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
196 |
return u'\n'.join(data) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
197 |
|
1309 | 198 |
def form_row(self, form, key, splitlabel): |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
199 |
entity = self.entity_for_key(key) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
200 |
if splitlabel: |
1309 | 201 |
label = key.split('.')[-1] |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
202 |
else: |
1309 | 203 |
label = key |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
204 |
subform = self._cw.vreg['forms'].select('base', self._cw, entity=entity, |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
205 |
mainform=False) |
4258
16804a4f555d
with cw 3.6 we've to specify entity's relation role
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4252
diff
changeset
|
206 |
subform.append_field(PropertyValueField(name='value', label=label, role='subject', |
1309 | 207 |
eidparam=True)) |
4258
16804a4f555d
with cw 3.6 we've to specify entity's relation role
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4252
diff
changeset
|
208 |
subform.add_hidden('pkey', key, eidparam=True, role='subject') |
3513
c002f6488631
[form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
209 |
form.add_subform(subform) |
1309 | 210 |
return subform |
2161
200481e7b156
prepare time where it won't be mandatory to give rset to select()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2133
diff
changeset
|
211 |
|
7829
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
212 |
def wrap_main_form(self, group, label, form): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
213 |
status = css_class(self._group_status(group)) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
214 |
self.w(u'<div class="propertiesform">%s</div>\n' % |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
215 |
(make_togglable_link('fieldset_' + group, label))) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
216 |
self.w(u'<div id="fieldset_%s" %s>' % (group, status)) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
217 |
self.w(u'<fieldset class="preferences">') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
218 |
self.w(form) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
219 |
self.w(u'</fieldset></div>') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
220 |
|
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
221 |
def wrap_grouped_form(self, group, label, objects): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
222 |
status = css_class(self._group_status(group)) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
223 |
self.w(u'<div class="propertiesform">%s</div>\n' % |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
224 |
(make_togglable_link('fieldset_' + group, label))) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
225 |
self.w(u'<div id="fieldset_%s" %s>' % (group, status)) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
226 |
sorted_objects = sorted((self._cw.__('%s_%s' % (group, o)), o, f) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
227 |
for o, f in objects.iteritems()) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
228 |
for label, oid, form in sorted_objects: |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
229 |
self.wrap_object_form(group, oid, label, form) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
230 |
self.w(u'</div>') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
231 |
|
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
232 |
def wrap_object_form(self, group, oid, label, form): |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
233 |
w = self.w |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
234 |
w(u'<div class="component">') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
235 |
w(u'''<div class="componentLink"><a href="javascript:$.noop();" |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
236 |
onclick="javascript:toggleVisibility('field_%(oid)s_%(group)s')" |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
237 |
class="componentTitle">%(label)s</a>''' % {'label':label, 'oid':oid, 'group':group}) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
238 |
w(u''' (<div class="openlink"><a href="javascript:$.noop();" |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
239 |
onclick="javascript:openFieldset('fieldset_%(group)s')">%(label)s</a></div>)''' |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
240 |
% {'label':self._cw._('open all'), 'group':group}) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
241 |
w(u'</div>') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
242 |
docmsgid = '%s_%s_description' % (group, oid) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
243 |
doc = self._cw._(docmsgid) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
244 |
if doc != docmsgid: |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
245 |
w(u'<div class="helper">%s</div>' % xml_escape(doc).capitalize()) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
246 |
w(u'</div>') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
247 |
w(u'<fieldset id="field_%(oid)s_%(group)s" class="%(group)s preferences hidden">' |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
248 |
% {'oid':oid, 'group':group}) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
249 |
w(form) |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
250 |
w(u'</fieldset>') |
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
251 |
|
2161
200481e7b156
prepare time where it won't be mandatory to give rset to select()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2133
diff
changeset
|
252 |
|
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
253 |
class CWPropertiesForm(SystemCWPropertiesForm): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
254 |
"""user's preferences properties edition form""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
255 |
__regid__ = 'propertiesform' |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
691
diff
changeset
|
256 |
__select__ = ( |
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
257 |
(none_rset() & match_user_groups('users','managers')) |
5502
c342531032a1
[selectors] new logged_user_in_rset selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
258 |
| (one_line_rset() & match_user_groups('users') & logged_user_in_rset()) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5819
diff
changeset
|
259 |
| (one_line_rset() & match_user_groups('managers') & is_instance('CWUser')) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
260 |
) |
1507 | 261 |
|
7805
7111bb64b58f
[user prefs] use same title as the action for consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
262 |
title = _('user preferences') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
263 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
264 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
265 |
def user(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
266 |
if self.cw_rset is None: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
267 |
return self._cw.user |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
268 |
return self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
269 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
270 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
271 |
@cached |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
272 |
def cwprops_rset(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
273 |
return self._cw.execute('Any P,K,V WHERE P is CWProperty, P pkey K, P value V,' |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
274 |
'P for_user U, U eid %(x)s', {'x': self.user.eid}) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
275 |
|
1309 | 276 |
def form_row(self, form, key, splitlabel): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
277 |
subform = super(CWPropertiesForm, self).form_row(form, key, splitlabel) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
278 |
# if user is in the managers group and the property is being created, |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
279 |
# we have to set for_user explicitly |
1309 | 280 |
if not subform.edited_entity.has_eid() and self.user.matching_groups('managers'): |
4258
16804a4f555d
with cw 3.6 we've to specify entity's relation role
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4252
diff
changeset
|
281 |
subform.add_hidden('for_user', self.user.eid, eidparam=True, role='subject') |
7829
58f696c0f5b3
[cwproperties] refactor properties form to make it partly overrideable easily (closes #1936782)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7805
diff
changeset
|
282 |
return subform |
1309 | 283 |
|
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
284 |
# cwproperty form objects ###################################################### |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
285 |
|
4259
83b0bf9b0a51
inherit from FieldWidget to inherit from the process_field_data required by the edit controller
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4258
diff
changeset
|
286 |
class PlaceHolderWidget(FieldWidget): |
1507 | 287 |
|
2585
d84ea8753290
missing new renderer argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2583
diff
changeset
|
288 |
def render(self, form, field, renderer): |
4156
1bbb0ee42c8e
drop form_field_name/form_field_id methods from form object, in favor of field.input_name(form) / field.dom_id(form)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
289 |
domid = field.dom_id(form) |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
290 |
# empty span as well else html validation fail (label is refering to |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
291 |
# this id) |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
292 |
return '<div id="div:%s"><span id="%s">%s</span></div>' % ( |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
293 |
domid, domid, form._cw._('select a key first')) |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
294 |
|
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
295 |
|
4259
83b0bf9b0a51
inherit from FieldWidget to inherit from the process_field_data required by the edit controller
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4258
diff
changeset
|
296 |
class NotEditableWidget(FieldWidget): |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
297 |
def __init__(self, value, msg=None): |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
298 |
self.value = value |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
299 |
self.msg = msg |
1507 | 300 |
|
2585
d84ea8753290
missing new renderer argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2583
diff
changeset
|
301 |
def render(self, form, field, renderer): |
4156
1bbb0ee42c8e
drop form_field_name/form_field_id methods from form object, in favor of field.input_name(form) / field.dom_id(form)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
302 |
domid = field.dom_id(form) |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
303 |
value = '<span class="value" id="%s">%s</span>' % (domid, self.value) |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
304 |
if self.msg: |
10277
e7cdf820fe8f
[web/views] Fix exception in CWProperty edit form (closes #5087412)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8695
diff
changeset
|
305 |
value += '<div class="helper">%s</div>' % self.msg |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
306 |
return value |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
307 |
|
1309 | 308 |
|
309 |
class PropertyKeyField(StringField): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
310 |
"""specific field for CWProperty.pkey to set the value widget according to |
1309 | 311 |
the selected key |
312 |
""" |
|
313 |
widget = Select |
|
1507 | 314 |
|
1309 | 315 |
def render(self, form, renderer): |
316 |
wdg = self.get_widget(form) |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7855
diff
changeset
|
317 |
# pylint: disable=E1101 |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
318 |
wdg.attrs['tabindex'] = form._cw.next_tabindex() |
1309 | 319 |
wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % ( |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
320 |
form.edited_entity.eid, form._cw.next_tabindex()) |
2583
b8d39602a640
Add missing parameter to widget render call.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
2476
diff
changeset
|
321 |
return wdg.render(form, self, renderer) |
1507 | 322 |
|
1309 | 323 |
def vocabulary(self, form): |
324 |
entity = form.edited_entity |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
325 |
_ = form._cw._ |
1309 | 326 |
if entity.has_eid(): |
327 |
return [(_(entity.pkey), entity.pkey)] |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
328 |
choices = entity._cw.vreg.user_property_keys() |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
329 |
return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices)) |
1309 | 330 |
|
2225 | 331 |
|
1309 | 332 |
class PropertyValueField(StringField): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
333 |
"""specific field for CWProperty.value which will be different according to |
1309 | 334 |
the selected key type and vocabulary information |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
335 |
""" |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
336 |
widget = PlaceHolderWidget |
1507 | 337 |
|
1309 | 338 |
def render(self, form, renderer=None, tabindex=None): |
339 |
wdg = self.get_widget(form) |
|
340 |
if tabindex is not None: |
|
341 |
wdg.attrs['tabindex'] = tabindex |
|
2583
b8d39602a640
Add missing parameter to widget render call.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
2476
diff
changeset
|
342 |
return wdg.render(form, self, renderer) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
343 |
|
1309 | 344 |
def form_init(self, form): |
345 |
entity = form.edited_entity |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
346 |
if not (entity.has_eid() or 'pkey' in entity.cw_attr_cache): |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
347 |
# no key set yet, just include an empty div which will be filled |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
348 |
# on key selection |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
349 |
return |
1309 | 350 |
try: |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
351 |
pdef = form._cw.vreg.property_info(entity.pkey) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8665
diff
changeset
|
352 |
except UnknownProperty as ex: |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7855
diff
changeset
|
353 |
form.warning('%s (you should probably delete that property ' |
1309 | 354 |
'from the database)', ex) |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
355 |
msg = form._cw._('you should probably delete that property') |
1309 | 356 |
self.widget = NotEditableWidget(entity.printable_value('value'), |
357 |
'%s (%s)' % (msg, ex)) |
|
10277
e7cdf820fe8f
[web/views] Fix exception in CWProperty edit form (closes #5087412)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8695
diff
changeset
|
358 |
return |
1309 | 359 |
if entity.pkey.startswith('system.'): |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
360 |
msg = form._cw._('value associated to this key is not editable ' |
1309 | 361 |
'manually') |
362 |
self.widget = NotEditableWidget(entity.printable_value('value'), msg) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
363 |
# XXX race condition when used from CWPropertyForm, should not rely on |
1309 | 364 |
# instance attributes |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
365 |
self.value = pdef['default'] |
1309 | 366 |
self.help = pdef['help'] |
367 |
vocab = pdef['vocabulary'] |
|
368 |
if vocab is not None: |
|
369 |
if callable(vocab): |
|
370 |
# list() just in case its a generator function |
|
6069
d7cef08aad27
[cwprops] fix callable vocabulary of cwproperties which were inconsistently called. No more argument, should now simply return a list of (untranslated) values
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
371 |
self.choices = list(vocab()) |
1309 | 372 |
else: |
373 |
self.choices = vocab |
|
374 |
wdg = Select() |
|
2085
9e279029d7a0
fix #343630 by getting explicitly TextInput widget for String, also instantiate field to get proper widget configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2051
diff
changeset
|
375 |
elif pdef['type'] == 'String': # else we'll get a TextArea by default |
9e279029d7a0
fix #343630 by getting explicitly TextInput widget for String, also instantiate field to get proper widget configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2051
diff
changeset
|
376 |
wdg = TextInput() |
1309 | 377 |
else: |
2085
9e279029d7a0
fix #343630 by getting explicitly TextInput widget for String, also instantiate field to get proper widget configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2051
diff
changeset
|
378 |
field = FIELDS[pdef['type']]() |
9e279029d7a0
fix #343630 by getting explicitly TextInput widget for String, also instantiate field to get proper widget configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2051
diff
changeset
|
379 |
wdg = field.widget |
1309 | 380 |
if pdef['type'] == 'Boolean': |
2085
9e279029d7a0
fix #343630 by getting explicitly TextInput widget for String, also instantiate field to get proper widget configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2051
diff
changeset
|
381 |
self.choices = field.vocabulary(form) |
1309 | 382 |
self.widget = wdg |
383 |
||
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
384 |
|
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
385 |
class CWPropertiesFormRenderer(formrenderers.FormRenderer): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
386 |
"""specific renderer for properties""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
387 |
__regid__ = 'cwproperties' |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
388 |
|
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
389 |
def open_form(self, form, values): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
390 |
err = '<div class="formsg"></div>' |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
391 |
return super(CWPropertiesFormRenderer, self).open_form(form, values) + err |
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
392 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
393 |
def _render_fields(self, fields, w, form): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
394 |
for field in fields: |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
395 |
w(u'<div class="preffield">\n') |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
396 |
if self.display_label: |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
397 |
w(u'%s' % self.render_label(form, field)) |
4224
5998df006968
refactor form error handling:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
398 |
error = form.field_error(field) |
5998df006968
refactor form error handling:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
399 |
if error: |
5693
8af6623f3d4e
[pylint] fix detected name errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
400 |
w(u'<span class="error">%s</span>' % error) |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
401 |
w(u'%s' % self.render_help(form, field)) |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
402 |
w(u'<div class="prefinput">') |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
403 |
w(field.render(form, self)) |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
404 |
w(u'</div>') |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
405 |
w(u'</div>') |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
406 |
|
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
407 |
def render_buttons(self, w, form): |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
408 |
w(u'<div>\n') |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
409 |
for button in form.form_buttons: |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
410 |
w(u'%s\n' % button.render(form)) |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
411 |
w(u'</div>') |
4360
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
412 |
|
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
413 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
414 |
class CWPropertyIEditControlAdapter(editcontroller.IEditControlAdapter): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5819
diff
changeset
|
415 |
__select__ = is_instance('CWProperty') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
416 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
417 |
def after_deletion_path(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
418 |
"""return (path, parameters) which should be used as redirect |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
419 |
information when this entity is being deleted |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
420 |
""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
421 |
return 'view', {} |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5535
diff
changeset
|
422 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
423 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
424 |
@ajaxfunc(output_type='xhtml') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
425 |
def prop_widget(self, propkey, varname, tabindex=None): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
426 |
"""specific method for CWProperty handling""" |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
427 |
entity = self._cw.vreg['etypes'].etype_class('CWProperty')(self._cw) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
428 |
entity.eid = varname |
10278
90aab6ddf6d8
[web/views] Fix PropertyKeyField widget (closes #5087413)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10277
diff
changeset
|
429 |
entity.pkey = propkey |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
430 |
form = self._cw.vreg['forms'].select('edition', self._cw, entity=entity) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
431 |
form.build_context() |
10278
90aab6ddf6d8
[web/views] Fix PropertyKeyField widget (closes #5087413)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10277
diff
changeset
|
432 |
vfield = form.field_by_name('value', 'subject') |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
433 |
renderer = formrenderers.FormRenderer(self._cw) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
434 |
return vfield.render(form, renderer, tabindex=tabindex) \ |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
435 |
+ renderer.render_help(form, vfield) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7894
diff
changeset
|
436 |
|
4360
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
437 |
_afs = uicfg.autoform_section |
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
438 |
_afs.tag_subject_of(('*', 'for_user', '*'), 'main', 'hidden') |
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
439 |
_afs.tag_object_of(('*', 'for_user', '*'), 'main', 'hidden') |
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
440 |
_aff = uicfg.autoform_field |
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
441 |
_aff.tag_attribute(('CWProperty', 'pkey'), PropertyKeyField) |
5fdb9da1fab0
move CWProperty rtags from autoform to cwproperties module.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4265
diff
changeset
|
442 |
_aff.tag_attribute(('CWProperty', 'value'), PropertyValueField) |