# HG changeset patch
# User sylvain.thenault@logilab.fr
# Date 1240928514 -7200
# Node ID 525965b1c23a8eb5e263cf4da51e628f79434833
# Parent b38e888ee7e35e71d844706da075c4203c0e3268
rename
diff -r b38e888ee7e3 -r 525965b1c23a web/views/cwproperties.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/views/cwproperties.py Tue Apr 28 16:21:54 2009 +0200
@@ -0,0 +1,329 @@
+"""Specific views for CWProperty
+
+:organization: Logilab
+:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+"""
+__docformat__ = "restructuredtext en"
+
+from logilab.mtconverter import html_escape
+
+from logilab.common.decorators import cached
+
+from cubicweb import UnknownProperty
+from cubicweb.selectors import (one_line_rset, none_rset, implements,
+ match_user_groups, entity_implements)
+from cubicweb.utils import UStringIO
+from cubicweb.view import StartupView
+from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, uicfg
+from cubicweb.web.views import baseviews
+from cubicweb.web import stdmsgs
+from cubicweb.web.form import CompositeForm, EntityFieldsForm, FormViewMixIn
+from cubicweb.web.formfields import FIELDS, StringField
+from cubicweb.web.formwidgets import Select, Button, SubmitButton
+
+_ = unicode
+
+# some string we want to be internationalizable for nicer display of eproperty
+# groups
+_('navigation')
+_('ui')
+_('actions')
+_('boxes')
+_('components')
+_('contentnavigation')
+
+
+def make_togglable_link(nodeid, label, cookiename):
+ """builds a HTML link that switches the visibility & remembers it"""
+ action = u"javascript: toggle_and_remember_visibility('%s', '%s')" % \
+ (nodeid, cookiename)
+ return u'%s' % (action, label)
+
+def css_class(someclass):
+ return someclass and 'class="%s"' % someclass or ''
+
+
+class CWPropertyPrimaryView(baseviews.PrimaryView):
+ __select__ = implements('CWProperty')
+ skip_none = False
+
+
+class SystemEPropertiesForm(FormViewMixIn, StartupView):
+ id = 'systemepropertiesform'
+ __select__ = none_rset() & match_user_groups('managers')
+
+ title = _('site configuration')
+ category = 'startupview'
+
+ def linkable(self):
+ return True
+
+ def url(self):
+ """return the url associated with this view. We can omit rql here"""
+ return self.build_url('view', vid=self.id)
+
+ def _cookie_name(self, somestr):
+ return str('%s_property_%s' % (self.config.appid, somestr))
+
+ def _group_status(self, group, default=u'hidden'):
+ """return css class name 'hidden' (collapsed), or '' (open)"""
+ cookies = self.req.get_cookie()
+ cookiename = self._cookie_name(group)
+ cookie = cookies.get(cookiename)
+ if cookie is None:
+ cookies[cookiename] = default
+ self.req.set_cookie(cookies, cookiename, maxage=None)
+ status = default
+ else:
+ status = cookie.value
+ return status
+
+ def call(self, **kwargs):
+ """The default view representing the application's index"""
+ self.req.add_js('cubicweb.preferences.js')
+ self.req.add_css('cubicweb.preferences.css')
+ vreg = self.vreg
+ values = self.defined_keys
+ groupedopts = {}
+ mainopts = {}
+ # "self.id=='systemepropertiesform'" to skip site wide properties on
+ # user's preference but not site's configuration
+ for key in vreg.user_property_keys(self.id=='systemepropertiesform'):
+ parts = key.split('.')
+ if parts[0] in vreg:
+ # appobject configuration
+ reg, oid, propid = parts
+ groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key)
+ else:
+ mainopts.setdefault(parts[0], []).append(key)
+ # precompute form to consume error message
+ for group, keys in mainopts.items():
+ mainopts[group] = self.form(keys, True)
+ for group, objects in groupedopts.items():
+ for oid, keys in objects.items():
+ groupedopts[group][oid] = self.form(keys, True)
+ w = self.w
+ req = self.req
+ _ = req._
+ w(u'
%s
\n' % _(self.title))
+ # we don't want this in each sub-forms
+ w(u'
%s
' % self.req._('validating...'))
+ for label, group, form in sorted((_(g), g, f)
+ for g, f in mainopts.iteritems()):
+ status = css_class(self._group_status(group))
+ w(u'
' % self.msg
+ return value
+
+
+class PropertyKeyField(StringField):
+ """specific field for CWProperty.pkey to set the value widget according to
+ the selected key
+ """
+ widget = Select
+
+ def render(self, form, renderer):
+ wdg = self.get_widget(form)
+ wdg.attrs['tabindex'] = form.req.next_tabindex()
+ wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % (
+ form.edited_entity.eid, form.req.next_tabindex())
+ return wdg.render(form, self)
+
+ def vocabulary(self, form):
+ entity = form.edited_entity
+ _ = form.req._
+ if entity.has_eid():
+ return [(_(entity.pkey), entity.pkey)]
+ # key beginning with 'system.' should usually not be edited by hand
+ choices = entity.vreg.user_property_keys()
+ return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices))
+
+
+class PropertyValueField(StringField):
+ """specific field for CWProperty.value which will be different according to
+ the selected key type and vocabulary information
+ """
+ widget = PlaceHolderWidget
+
+ def render(self, form, renderer=None, tabindex=None):
+ wdg = self.get_widget(form)
+ if tabindex is not None:
+ wdg.attrs['tabindex'] = tabindex
+ return wdg.render(form, self)
+
+ def form_init(self, form):
+ entity = form.edited_entity
+ if not (entity.has_eid() or 'pkey' in entity):
+ # no key set yet, just include an empty div which will be filled
+ # on key selection
+ return
+ try:
+ pdef = form.vreg.property_info(entity.pkey)
+ except UnknownProperty, ex:
+ self.warning('%s (you should probably delete that property '
+ 'from the database)', ex)
+ msg = form.req._('you should probably delete that property')
+ self.widget = NotEditableWidget(entity.printable_value('value'),
+ '%s (%s)' % (msg, ex))
+ if entity.pkey.startswith('system.'):
+ msg = form.req._('value associated to this key is not editable '
+ 'manually')
+ self.widget = NotEditableWidget(entity.printable_value('value'), msg)
+ # XXX race condition when used from CWPropertyForm, should not rely on
+ # instance attributes
+ self.initial = pdef['default']
+ self.help = pdef['help']
+ vocab = pdef['vocabulary']
+ if vocab is not None:
+ if callable(vocab):
+ # list() just in case its a generator function
+ self.choices = list(vocab(form.req))
+ else:
+ self.choices = vocab
+ wdg = Select()
+ else:
+ wdg = FIELDS[pdef['type']].widget()
+ if pdef['type'] == 'Boolean':
+ self.choices = [(form.req._('yes'), '1'), (form.req._('no'), '')]
+ elif pdef['type'] in ('Float', 'Int'):
+ wdg.attrs.setdefault('size', 3)
+ self.widget = wdg
+
+uicfg.rfields.set_rtag(PropertyKeyField, 'pkey', 'subject', 'CWProperty')
+uicfg.rfields.set_rtag(PropertyValueField, 'value', 'subject', 'CWProperty')
+
diff -r b38e888ee7e3 -r 525965b1c23a web/views/eproperties.py
--- a/web/views/eproperties.py Tue Apr 28 16:21:32 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,329 +0,0 @@
-"""Specific views for CWProperty
-
-:organization: Logilab
-:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-"""
-__docformat__ = "restructuredtext en"
-
-from logilab.mtconverter import html_escape
-
-from logilab.common.decorators import cached
-
-from cubicweb import UnknownProperty
-from cubicweb.selectors import (one_line_rset, none_rset, implements,
- match_user_groups, entity_implements)
-from cubicweb.utils import UStringIO
-from cubicweb.view import StartupView
-from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, uicfg
-from cubicweb.web.views import baseviews
-from cubicweb.web import stdmsgs
-from cubicweb.web.form import CompositeForm, EntityFieldsForm, FormViewMixIn
-from cubicweb.web.formfields import FIELDS, StringField
-from cubicweb.web.formwidgets import Select, Button, SubmitButton
-
-_ = unicode
-
-# some string we want to be internationalizable for nicer display of eproperty
-# groups
-_('navigation')
-_('ui')
-_('actions')
-_('boxes')
-_('components')
-_('contentnavigation')
-
-
-def make_togglable_link(nodeid, label, cookiename):
- """builds a HTML link that switches the visibility & remembers it"""
- action = u"javascript: toggle_and_remember_visibility('%s', '%s')" % \
- (nodeid, cookiename)
- return u'%s' % (action, label)
-
-def css_class(someclass):
- return someclass and 'class="%s"' % someclass or ''
-
-
-class CWPropertyPrimaryView(baseviews.PrimaryView):
- __select__ = implements('CWProperty')
- skip_none = False
-
-
-class SystemEPropertiesForm(FormViewMixIn, StartupView):
- id = 'systemepropertiesform'
- __select__ = none_rset() & match_user_groups('managers')
-
- title = _('site configuration')
- category = 'startupview'
-
- def linkable(self):
- return True
-
- def url(self):
- """return the url associated with this view. We can omit rql here"""
- return self.build_url('view', vid=self.id)
-
- def _cookie_name(self, somestr):
- return str('%s_property_%s' % (self.config.appid, somestr))
-
- def _group_status(self, group, default=u'hidden'):
- """return css class name 'hidden' (collapsed), or '' (open)"""
- cookies = self.req.get_cookie()
- cookiename = self._cookie_name(group)
- cookie = cookies.get(cookiename)
- if cookie is None:
- cookies[cookiename] = default
- self.req.set_cookie(cookies, cookiename, maxage=None)
- status = default
- else:
- status = cookie.value
- return status
-
- def call(self, **kwargs):
- """The default view representing the application's index"""
- self.req.add_js('cubicweb.preferences.js')
- self.req.add_css('cubicweb.preferences.css')
- vreg = self.vreg
- values = self.defined_keys
- groupedopts = {}
- mainopts = {}
- # "self.id=='systemepropertiesform'" to skip site wide properties on
- # user's preference but not site's configuration
- for key in vreg.user_property_keys(self.id=='systemepropertiesform'):
- parts = key.split('.')
- if parts[0] in vreg:
- # appobject configuration
- reg, oid, propid = parts
- groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key)
- else:
- mainopts.setdefault(parts[0], []).append(key)
- # precompute form to consume error message
- for group, keys in mainopts.items():
- mainopts[group] = self.form(keys, True)
- for group, objects in groupedopts.items():
- for oid, keys in objects.items():
- groupedopts[group][oid] = self.form(keys, True)
- w = self.w
- req = self.req
- _ = req._
- w(u'
%s
\n' % _(self.title))
- # we don't want this in each sub-forms
- w(u'
%s
' % self.req._('validating...'))
- for label, group, form in sorted((_(g), g, f)
- for g, f in mainopts.iteritems()):
- status = css_class(self._group_status(group))
- w(u'
' % self.msg
- return value
-
-
-class PropertyKeyField(StringField):
- """specific field for CWProperty.pkey to set the value widget according to
- the selected key
- """
- widget = Select
-
- def render(self, form, renderer):
- wdg = self.get_widget(form)
- wdg.attrs['tabindex'] = form.req.next_tabindex()
- wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % (
- form.edited_entity.eid, form.req.next_tabindex())
- return wdg.render(form, self)
-
- def vocabulary(self, form):
- entity = form.edited_entity
- _ = form.req._
- if entity.has_eid():
- return [(_(entity.pkey), entity.pkey)]
- # key beginning with 'system.' should usually not be edited by hand
- choices = entity.vreg.user_property_keys()
- return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices))
-
-
-class PropertyValueField(StringField):
- """specific field for CWProperty.value which will be different according to
- the selected key type and vocabulary information
- """
- widget = PlaceHolderWidget
-
- def render(self, form, renderer=None, tabindex=None):
- wdg = self.get_widget(form)
- if tabindex is not None:
- wdg.attrs['tabindex'] = tabindex
- return wdg.render(form, self)
-
- def form_init(self, form):
- entity = form.edited_entity
- if not (entity.has_eid() or 'pkey' in entity):
- # no key set yet, just include an empty div which will be filled
- # on key selection
- return
- try:
- pdef = form.vreg.property_info(entity.pkey)
- except UnknownProperty, ex:
- self.warning('%s (you should probably delete that property '
- 'from the database)', ex)
- msg = form.req._('you should probably delete that property')
- self.widget = NotEditableWidget(entity.printable_value('value'),
- '%s (%s)' % (msg, ex))
- if entity.pkey.startswith('system.'):
- msg = form.req._('value associated to this key is not editable '
- 'manually')
- self.widget = NotEditableWidget(entity.printable_value('value'), msg)
- # XXX race condition when used from CWPropertyForm, should not rely on
- # instance attributes
- self.initial = pdef['default']
- self.help = pdef['help']
- vocab = pdef['vocabulary']
- if vocab is not None:
- if callable(vocab):
- # list() just in case its a generator function
- self.choices = list(vocab(form.req))
- else:
- self.choices = vocab
- wdg = Select()
- else:
- wdg = FIELDS[pdef['type']].widget()
- if pdef['type'] == 'Boolean':
- self.choices = [(form.req._('yes'), '1'), (form.req._('no'), '')]
- elif pdef['type'] in ('Float', 'Int'):
- wdg.attrs.setdefault('size', 3)
- self.widget = wdg
-
-uicfg.rfields.set_rtag(PropertyKeyField, 'pkey', 'subject', 'CWProperty')
-uicfg.rfields.set_rtag(PropertyValueField, 'value', 'subject', 'CWProperty')
-