diff -r 749e1a67987f -r 58f696c0f5b3 web/views/cwproperties.py --- a/web/views/cwproperties.py Thu Sep 22 16:12:28 2011 +0200 +++ b/web/views/cwproperties.py Thu Sep 22 16:12:33 2011 +0200 @@ -1,4 +1,4 @@ -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -113,72 +113,18 @@ self._cw.add_js(('cubicweb.preferences.js', 'cubicweb.edition.js', 'cubicweb.ajax.js')) self._cw.add_css('cubicweb.preferences.css') - vreg = self._cw.vreg values = self.defined_keys - groupedopts = {} - mainopts = {} - # "self.id=='systempropertiesform'" to skip site wide properties on - # user's preference but not site's configuration - for key in vreg.user_property_keys(self.__regid__=='systempropertiesform'): - parts = key.split('.') - if parts[0] in vreg and len(parts) >= 3: - # appobject configuration - reg = parts[0] - propid = parts[-1] - oid = '.'.join(parts[1:-1]) - 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(group, keys, False) - - for group, objects in groupedopts.items(): - for oid, keys in objects.items(): - groupedopts[group][oid] = self.form(group + '_' + oid, keys, True) - - w = self.w - req = self._cw - _ = req._ - w(u'

%s

\n' % _(self.title)) + mainopts, groupedopts = self.group_properties() + # precompute all forms first to consume error message + mainforms, groupedforms = self.build_forms(mainopts, groupedopts) + _ = self._cw._ + self.w(u'

%s

\n' % _(self.title)) for label, group, form in sorted((_(g), g, f) - for g, f in mainopts.iteritems()): - status = css_class(self._group_status(group)) - w(u'
%s
\n' % - (make_togglable_link('fieldset_' + group, label.capitalize()))) - w(u'
' % (group, status)) - w(u'
') - w(form) - w(u'
') - + for g, f in mainforms.iteritems()): + self.wrap_main_form(group, label, form) for label, group, objects in sorted((_(g), g, o) - for g, o in groupedopts.iteritems()): - status = css_class(self._group_status(group)) - w(u'
%s
\n' % - (make_togglable_link('fieldset_' + group, label.capitalize()))) - w(u'
' % (group, status)) - # create selection - sorted_objects = sorted((self._cw.__('%s_%s' % (group, o)), o, f) - for o, f in objects.iteritems()) - for label, oid, form in sorted_objects: - w(u'
') - w(u'''') - docmsgid = '%s_%s_description' % (group, oid) - doc = _(docmsgid) - if doc != docmsgid: - w(u'
%s
' % xml_escape(doc).capitalize()) - w(u'
') - w(u'') - w(u'
') + for g, o in groupedforms.iteritems()): + self.wrap_grouped_form(group, label, objects) @property @cached @@ -193,6 +139,33 @@ values[entity.pkey] = i return values + def group_properties(self): + mainopts, groupedopts = {}, {} + vreg = self._cw.vreg + # "self._regid__=='systempropertiesform'" to skip site wide properties on + # user's preference but not site's configuration + for key in vreg.user_property_keys(self.__regid__=='systempropertiesform'): + parts = key.split('.') + if parts[0] in vreg and len(parts) >= 3: + # appobject configuration + reg = parts[0] + propid = parts[-1] + oid = '.'.join(parts[1:-1]) + groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key) + else: + mainopts.setdefault(parts[0], []).append(key) + return mainopts, groupedopts + + def build_forms(self, mainopts, groupedopts): + mainforms, groupedforms = {}, {} + for group, keys in mainopts.items(): + mainforms[group] = self.form(group, keys, False) + for group, objects in groupedopts.items(): + groupedforms[group] = {} + for oid, keys in objects.items(): + groupedforms[group][oid] = self.form(group + '_' + oid, keys, True) + return mainforms, groupedforms + def entity_for_key(self, key): values = self.defined_keys if key in values: @@ -233,11 +206,50 @@ mainform=False) subform.append_field(PropertyValueField(name='value', label=label, role='subject', eidparam=True)) - #subform.vreg = self._cw.vreg subform.add_hidden('pkey', key, eidparam=True, role='subject') form.add_subform(subform) return subform + def wrap_main_form(self, group, label, form): + status = css_class(self._group_status(group)) + self.w(u'
%s
\n' % + (make_togglable_link('fieldset_' + group, label))) + self.w(u'
' % (group, status)) + self.w(u'
') + self.w(form) + self.w(u'
') + + def wrap_grouped_form(self, group, label, objects): + status = css_class(self._group_status(group)) + self.w(u'
%s
\n' % + (make_togglable_link('fieldset_' + group, label))) + self.w(u'
' % (group, status)) + sorted_objects = sorted((self._cw.__('%s_%s' % (group, o)), o, f) + for o, f in objects.iteritems()) + for label, oid, form in sorted_objects: + self.wrap_object_form(group, oid, label, form) + self.w(u'
') + + def wrap_object_form(self, group, oid, label, form): + w = self.w + w(u'
') + w(u'''') + docmsgid = '%s_%s_description' % (group, oid) + doc = self._cw._(docmsgid) + if doc != docmsgid: + w(u'
%s
' % xml_escape(doc).capitalize()) + w(u'
') + w(u'') + class CWPropertiesForm(SystemCWPropertiesForm): """user's preferences properties edition form""" @@ -268,7 +280,7 @@ # we have to set for_user explicitly if not subform.edited_entity.has_eid() and self.user.matching_groups('managers'): subform.add_hidden('for_user', self.user.eid, eidparam=True, role='subject') - + return subform # cwproperty form objects ######################################################