author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 23 Jun 2009 13:34:28 +0200 | |
branch | stable |
changeset 2143 | d4c2fb633062 |
parent 2133 | c3beb65d884d |
child 2144 | 51c84d585456 |
child 2161 | 200481e7b156 |
permissions | -rw-r--r-- |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
1 |
"""Specific views for CWProperty |
0 | 2 |
|
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1879
diff
changeset
|
4 |
:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1879
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
1641 | 9 |
_ = unicode |
0 | 10 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
11 |
from logilab.mtconverter import html_escape |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
12 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
13 |
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
|
14 |
|
1309 | 15 |
from cubicweb import UnknownProperty |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
16 |
from cubicweb.selectors import (one_line_rset, none_rset, implements, |
1537
788b5ca792bd
fix rfields declaration order
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1533
diff
changeset
|
17 |
match_user_groups) |
984 | 18 |
from cubicweb.view import StartupView |
1658
3f3672f76399
delete-trailing-whitespaces, update import
sylvain.thenault@logilab.fr
parents:
1641
diff
changeset
|
19 |
from cubicweb.web import uicfg, 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
|
20 |
from cubicweb.web.form import FormViewMixIn |
1309 | 21 |
from cubicweb.web.formfields import FIELDS, StringField |
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
|
22 |
from cubicweb.web.formwidgets import Select, TextInput, Button, SubmitButton |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
23 |
from cubicweb.web.views import primary, formrenderers |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
24 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
25 |
|
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
26 |
# 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
|
27 |
# groups |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
28 |
_('navigation') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
29 |
_('ui') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
30 |
_('actions') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
31 |
_('boxes') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
32 |
_('components') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
33 |
_('contentnavigation') |
1641 | 34 |
_('navigation.combobox-limit') |
35 |
_('navigation.page-size') |
|
36 |
_('navigation.related-limit') |
|
37 |
_('navigation.short-line-size') |
|
38 |
_('ui.date-format') |
|
39 |
_('ui.datetime-format') |
|
40 |
_('ui.default-text-format') |
|
41 |
_('ui.fckeditor') |
|
42 |
_('ui.float-format') |
|
43 |
_('ui.language') |
|
44 |
_('ui.time-format') |
|
45 |
_('open all') |
|
46 |
_('ui.main-template') |
|
47 |
_('ui.site-title') |
|
48 |
_('ui.encoding') |
|
49 |
_('category') |
|
0 | 50 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
51 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
52 |
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
|
53 |
"""builds a HTML link that switches the visibility & remembers it""" |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
54 |
action = u"javascript: togglePrefVisibility('%s')" % nodeid |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
55 |
return u'<a href="%s">%s</a>' % (action, label) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
56 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
57 |
def css_class(someclass): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
58 |
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
|
59 |
|
1309 | 60 |
|
1658
3f3672f76399
delete-trailing-whitespaces, update import
sylvain.thenault@logilab.fr
parents:
1641
diff
changeset
|
61 |
class CWPropertyPrimaryView(primary.PrimaryView): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
62 |
__select__ = implements('CWProperty') |
1309 | 63 |
skip_none = False |
64 |
||
65 |
||
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
66 |
class SystemCWPropertiesForm(FormViewMixIn, StartupView): |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
67 |
id = 'systempropertiesform' |
1309 | 68 |
__select__ = none_rset() & match_user_groups('managers') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
69 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
70 |
title = _('site configuration') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
71 |
category = 'startupview' |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
72 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
73 |
def linkable(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
74 |
return True |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
75 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
76 |
def url(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
77 |
"""return the url associated with this view. We can omit rql here""" |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
78 |
return self.build_url('view', vid=self.id) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
79 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
80 |
def _cookie_name(self, somestr): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
81 |
return str('%s_property_%s' % (self.config.appid, somestr)) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
82 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
83 |
def _group_status(self, group, default=u'hidden'): |
1309 | 84 |
"""return css class name 'hidden' (collapsed), or '' (open)""" |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
85 |
cookies = self.req.get_cookie() |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
86 |
cookiename = self._cookie_name(group) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
87 |
cookie = cookies.get(cookiename) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
88 |
if cookie is None: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
89 |
cookies[cookiename] = default |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
90 |
self.req.set_cookie(cookies, cookiename, maxage=None) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
91 |
status = default |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
92 |
else: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
93 |
status = cookie.value |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
94 |
return status |
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 call(self, **kwargs): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
97 |
"""The default view representing the application's index""" |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
98 |
self.req.add_js(('cubicweb.edition.js', 'cubicweb.preferences.js', 'cubicweb.ajax.js')) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
99 |
self.req.add_css('cubicweb.preferences.css') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
100 |
vreg = self.vreg |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
101 |
values = self.defined_keys |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
102 |
groupedopts = {} |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
103 |
mainopts = {} |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
104 |
# "self.id=='systempropertiesform'" to skip site wide properties on |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
105 |
# user's preference but not site's configuration |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
106 |
for key in vreg.user_property_keys(self.id=='systempropertiesform'): |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
107 |
parts = key.split('.') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
108 |
if parts[0] in vreg: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
109 |
# appobject configuration |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
110 |
reg, oid, propid = parts |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
111 |
groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
112 |
else: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
113 |
mainopts.setdefault(parts[0], []).append(key) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
114 |
# precompute form to consume error message |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
115 |
for group, keys in mainopts.items(): |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
116 |
mainopts[group] = self.form(group, keys, False) |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
117 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
118 |
for group, objects in groupedopts.items(): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
119 |
for oid, keys in objects.items(): |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
120 |
groupedopts[group][oid] = self.form(group + '-' + oid, keys, True) |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
121 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
122 |
w = self.w |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
123 |
req = self.req |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
124 |
_ = req._ |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
125 |
w(u'<h1>%s</h1>\n' % _(self.title)) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
126 |
for label, group, form in sorted((_(g), g, f) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
127 |
for g, f in mainopts.iteritems()): |
1507 | 128 |
status = css_class(self._group_status(group)) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
129 |
w(u'<h2 class="propertiesform">%s</h2>\n' % |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
130 |
(make_togglable_link('fieldset_' + group, label.capitalize()))) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
131 |
w(u'<div id="fieldset_%s" %s>' % (group, status)) |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
132 |
w(u'<fieldset class="preferences">') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
133 |
w(form) |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
134 |
w(u'</fieldset></div>') |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
135 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
136 |
for label, group, objects in sorted((_(g), g, o) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
137 |
for g, o in groupedopts.iteritems()): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
138 |
status = css_class(self._group_status(group)) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
139 |
w(u'<h2 class="propertiesform">%s</h2>\n' % |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
140 |
(make_togglable_link('fieldset_' + group, label.capitalize()))) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
141 |
w(u'<div id="fieldset_%s" %s>' % (group, status)) |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
142 |
# create selection |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
143 |
sorted_objects = sorted((self.req.__('%s_%s' % (group, o)), o, f) |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
144 |
for o, f in objects.iteritems()) |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
145 |
for label, oid, form in sorted_objects: |
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
146 |
w(u'<div class="component">') |
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
147 |
w(u'''<div class="componentLink"><a href="javascript:noop();" |
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
148 |
onclick="javascript:toggleVisibility('field_%(oid)s_%(group)s')" |
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
149 |
class="componentTitle">%(label)s</a>''' % {'label':label, 'oid':oid, 'group':group}) |
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
150 |
w(u''' (<div class="openlink"><a href="javascript:noop();" |
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
151 |
onclick="javascript:openFieldset('fieldset_%(group)s')">%(label)s</a></div>)''' |
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
152 |
% {'label':_('open all'), 'group':group}) |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
153 |
w(u'</div>') |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
154 |
docmsgid = '%s_%s_description' % (group, oid) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
155 |
doc = _(docmsgid) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
156 |
if doc != docmsgid: |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
157 |
w(u'<div class="helper">%s</div>' % html_escape(doc).capitalize()) |
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
158 |
w(u'</div>') |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
159 |
w(u'<fieldset id="field_%(oid)s_%(group)s" class="%(group)s preferences hidden">' |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
160 |
% {'oid':oid, 'group':group}) |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
161 |
w(form) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
162 |
w(u'</fieldset>') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
163 |
w(u'</div>') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
164 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
165 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
166 |
@cached |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
167 |
def cwprops_rset(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
168 |
return self.req.execute('Any P,K,V WHERE P is CWProperty, P pkey K, ' |
1309 | 169 |
'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
|
170 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
171 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
172 |
def defined_keys(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
173 |
values = {} |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
174 |
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
|
175 |
values[entity.pkey] = i |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
176 |
return values |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
177 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
178 |
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
|
179 |
values = self.defined_keys |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
180 |
if key in values: |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
181 |
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
|
182 |
else: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
183 |
entity = self.vreg.etype_class('CWProperty')(self.req, None, None) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
184 |
entity.eid = self.req.varmaker.next() |
1309 | 185 |
entity['pkey'] = key |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
186 |
entity['value'] = self.vreg.property_value(key) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
187 |
return entity |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
188 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
189 |
def form(self, formid, keys, splitlabel=False): |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
190 |
buttons = [SubmitButton()] |
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
|
191 |
form = self.vreg.select_object('forms', 'composite', self.req, |
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
|
192 |
domid=formid, action=self.build_url(), |
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
|
193 |
form_buttons=buttons, |
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
|
194 |
onsubmit="return validatePrefsForm('%s')" % formid, |
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
|
195 |
submitmsg=self.req._('changes applied')) |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
196 |
path = self.req.relative_path() |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
197 |
if '?' in path: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
198 |
path, params = path.split('?', 1) |
1309 | 199 |
form.form_add_hidden('__redirectparams', params) |
200 |
form.form_add_hidden('__redirectpath', path) |
|
1507 | 201 |
for key in keys: |
1309 | 202 |
self.form_row(form, key, splitlabel) |
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
|
203 |
renderer = self.vreg.select_object('formrenderers', 'cwproperties', self.req, |
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
|
204 |
display_progress_div=False) |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
205 |
return form.form_render(renderer=renderer) |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
206 |
|
1309 | 207 |
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
|
208 |
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
|
209 |
if splitlabel: |
1309 | 210 |
label = key.split('.')[-1] |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
211 |
else: |
1309 | 212 |
label = key |
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
|
213 |
subform = self.vreg.select_object('forms', 'base', self.req, entity=entity, |
2048
5e4d1433b90b
replace set_error_url/set_dom_id by a single mainform argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2046
diff
changeset
|
214 |
mainform=False) |
1309 | 215 |
subform.append_field(PropertyValueField(name='value', label=label, |
216 |
eidparam=True)) |
|
217 |
subform.vreg = self.vreg |
|
218 |
subform.form_add_hidden('pkey', key, eidparam=True) |
|
219 |
form.form_add_subform(subform) |
|
220 |
return subform |
|
2133 | 221 |
|
879 | 222 |
def is_user_prefs(cls, req, rset, row=None, col=0, **kwargs): |
223 |
return req.user.eid == rset[row or 0][col] |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
224 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
225 |
|
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
226 |
class CWPropertiesForm(SystemCWPropertiesForm): |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
227 |
id = 'propertiesform' |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
691
diff
changeset
|
228 |
__select__ = ( |
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
229 |
# we don't want guests to be able to come here |
792 | 230 |
match_user_groups('users', 'managers') & |
1309 | 231 |
(none_rset() | ((one_line_rset() & is_user_prefs) & |
232 |
(one_line_rset() & match_user_groups('managers')))) |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
233 |
) |
1507 | 234 |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
235 |
title = _('preferences') |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
236 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
237 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
238 |
def user(self): |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
239 |
if self.rset is None: |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
240 |
return self.req.user |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
241 |
return self.rset.get_entity(self.row or 0, self.col or 0) |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
242 |
|
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
243 |
@property |
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
244 |
@cached |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
245 |
def cwprops_rset(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
246 |
return self.req.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
|
247 |
'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
|
248 |
|
1309 | 249 |
def form_row(self, form, key, splitlabel): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
250 |
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
|
251 |
# 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
|
252 |
# we have to set for_user explicitly |
1309 | 253 |
if not subform.edited_entity.has_eid() and self.user.matching_groups('managers'): |
254 |
subform.form_add_hidden('for_user', self.user.eid, eidparam=True) |
|
255 |
||
256 |
||
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
257 |
# cwproperty form objects ###################################################### |
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
258 |
|
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
259 |
class PlaceHolderWidget(object): |
1507 | 260 |
|
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
261 |
def render(self, form, field): |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
262 |
domid = form.context[field]['id'] |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
263 |
# 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
|
264 |
# this id) |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
265 |
return '<div id="div:%s"><span id="%s">%s</span></div>' % ( |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
266 |
domid, domid, form.req._('select a key first')) |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
267 |
|
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
268 |
|
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
269 |
class NotEditableWidget(object): |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
270 |
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
|
271 |
self.value = value |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
272 |
self.msg = msg |
1507 | 273 |
|
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
274 |
def render(self, form, field): |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
275 |
domid = form.context[field]['id'] |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
276 |
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
|
277 |
if self.msg: |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
278 |
value + '<div class="helper">%s</div>' % self.msg |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
279 |
return value |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
280 |
|
1309 | 281 |
|
282 |
class PropertyKeyField(StringField): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
283 |
"""specific field for CWProperty.pkey to set the value widget according to |
1309 | 284 |
the selected key |
285 |
""" |
|
286 |
widget = Select |
|
1507 | 287 |
|
1309 | 288 |
def render(self, form, renderer): |
289 |
wdg = self.get_widget(form) |
|
290 |
wdg.attrs['tabindex'] = form.req.next_tabindex() |
|
291 |
wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % ( |
|
292 |
form.edited_entity.eid, form.req.next_tabindex()) |
|
293 |
return wdg.render(form, self) |
|
1507 | 294 |
|
1309 | 295 |
def vocabulary(self, form): |
296 |
entity = form.edited_entity |
|
297 |
_ = form.req._ |
|
298 |
if entity.has_eid(): |
|
299 |
return [(_(entity.pkey), entity.pkey)] |
|
300 |
# key beginning with 'system.' should usually not be edited by hand |
|
301 |
choices = entity.vreg.user_property_keys() |
|
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
302 |
return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices)) |
1309 | 303 |
|
2133 | 304 |
|
1309 | 305 |
class PropertyValueField(StringField): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1365
diff
changeset
|
306 |
"""specific field for CWProperty.value which will be different according to |
1309 | 307 |
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
|
308 |
""" |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
309 |
widget = PlaceHolderWidget |
1507 | 310 |
|
1309 | 311 |
def render(self, form, renderer=None, tabindex=None): |
312 |
wdg = self.get_widget(form) |
|
313 |
if tabindex is not None: |
|
314 |
wdg.attrs['tabindex'] = tabindex |
|
315 |
return wdg.render(form, self) |
|
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
316 |
|
1309 | 317 |
def form_init(self, form): |
318 |
entity = form.edited_entity |
|
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
319 |
if not (entity.has_eid() or 'pkey' in entity): |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
320 |
# 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
|
321 |
# on key selection |
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1309
diff
changeset
|
322 |
return |
1309 | 323 |
try: |
324 |
pdef = form.vreg.property_info(entity.pkey) |
|
325 |
except UnknownProperty, ex: |
|
326 |
self.warning('%s (you should probably delete that property ' |
|
327 |
'from the database)', ex) |
|
328 |
msg = form.req._('you should probably delete that property') |
|
329 |
self.widget = NotEditableWidget(entity.printable_value('value'), |
|
330 |
'%s (%s)' % (msg, ex)) |
|
331 |
if entity.pkey.startswith('system.'): |
|
332 |
msg = form.req._('value associated to this key is not editable ' |
|
333 |
'manually') |
|
334 |
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
|
335 |
# XXX race condition when used from CWPropertyForm, should not rely on |
1309 | 336 |
# instance attributes |
337 |
self.initial = pdef['default'] |
|
338 |
self.help = pdef['help'] |
|
339 |
vocab = pdef['vocabulary'] |
|
340 |
if vocab is not None: |
|
341 |
if callable(vocab): |
|
342 |
# list() just in case its a generator function |
|
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
343 |
self.choices = list(vocab(form.req)) |
1309 | 344 |
else: |
345 |
self.choices = vocab |
|
346 |
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
|
347 |
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
|
348 |
wdg = TextInput() |
1309 | 349 |
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
|
350 |
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
|
351 |
wdg = field.widget |
1309 | 352 |
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
|
353 |
self.choices = field.vocabulary(form) |
1309 | 354 |
self.widget = wdg |
355 |
||
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
356 |
uicfg.autoform_field.tag_attribute(('CWProperty', 'pkey'), PropertyKeyField) |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
357 |
uicfg.autoform_field.tag_attribute(('CWProperty', 'value'), PropertyValueField) |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
358 |
|
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
359 |
|
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
360 |
class CWPropertiesFormRenderer(formrenderers.FormRenderer): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
361 |
"""specific renderer for properties""" |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
362 |
id = 'cwproperties' |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
363 |
|
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
364 |
def open_form(self, form, values): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
365 |
err = '<div class="formsg"></div>' |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
366 |
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
|
367 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
368 |
def _render_fields(self, fields, w, form): |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
369 |
for field in fields: |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
370 |
w(u'<div class="preffield">\n') |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
371 |
if self.display_label: |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
372 |
w(u'%s' % self.render_label(form, field)) |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
373 |
error = form.form_field_error(field) |
1879
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
374 |
w(u'%s' % self.render_help(form, field)) |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
375 |
w(u'<div class="prefinput">') |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
376 |
w(field.render(form, self)) |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
377 |
w(u'</div>') |
cb3466e08d81
eproperty -> cwproperty, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1870
diff
changeset
|
378 |
w(u'</div>') |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
379 |
|
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
380 |
def render_buttons(self, w, form): |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
381 |
w(u'<div>\n') |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
382 |
for button in form.form_buttons: |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
383 |
w(u'%s\n' % button.render(form)) |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1739
diff
changeset
|
384 |
w(u'</div>') |