Migrate to cw 3.25
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 11 Oct 2017 08:06:59 +0200
changeset 2714 fadde7202d72
parent 2700 ba6a36fa1ce7
child 2715 757262c669ca
Migrate to cw 3.25 and drop monkey-patches which are hence no more necessary. Closes #17106806
cubicweb_seda/__pkginfo__.py
cubicweb_seda/site_cubicweb.py
cubicweb_seda/views/__init__.py
cubicweb_seda/views/archiveunit.py
cubicweb_seda/views/patches.py
--- a/cubicweb_seda/__pkginfo__.py	Thu Oct 05 17:35:16 2017 +0200
+++ b/cubicweb_seda/__pkginfo__.py	Wed Oct 11 08:06:59 2017 +0200
@@ -14,7 +14,7 @@
 web = 'http://www.cubicweb.org/project/%s' % distname
 
 __depends__ = {
-    'cubicweb': '>= 3.24, < 3.25',
+    'cubicweb': '>= 3.25, < 3.26',
     'six': '>= 1.4.0',
     'cubicweb-eac': None,
     'cubicweb-skos': '>= 0.12.1',
--- a/cubicweb_seda/site_cubicweb.py	Thu Oct 05 17:35:16 2017 +0200
+++ b/cubicweb_seda/site_cubicweb.py	Wed Oct 11 08:06:59 2017 +0200
@@ -14,115 +14,10 @@
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 
-from logilab.common.decorators import monkeypatch
-
-# hack to avoid crash when cube is installed in a directory specified by CW_CUBES_PATH, because
-# `RegistrableInstance` attempt to compute its __module__, but in that case the file isn't in the
-# python path. This should go away once cubes become regular packages.
-
-import traceback
-
-from logilab.common import registry
-
-from cubicweb import rtags
 from cubicweb.entity import Entity
 
 
-@monkeypatch(registry.RegistrableInstance, methodname='__new__')
-@staticmethod
-def __new__(cls, *args, **kwargs):
-    """Add a __module__ attribute telling the module where the instance was
-    created, for automatic registration.
-    """
-    module = kwargs.pop('__module__', None)
-    self = super(registry.RegistrableInstance, cls).__new__(cls)
-    if module is None:
-        filepath = traceback.extract_stack(limit=2)[0][0]
-        module = registry._modname_from_path(filepath)
-    self.__module__ = module
-    return self
-
-
-@monkeypatch(rtags.RelationTags)
-def __init__(self, __module__=None):
-    super(rtags.RelationTags, self).__init__()
-    self._tagdefs = {}
-
-
 Entity.cw_skip_copy_for.append(('container', 'subject'))
 Entity.cw_skip_copy_for.append(('container', 'object'))
 Entity.cw_skip_copy_for.append(('clone_of', 'subject'))
 Entity.cw_skip_copy_for.append(('clone_of', 'object'))
-
-
-# auto-configuration of custom fields ##############################################################
-# (https://www.cubicweb.org/ticket/14474840)
-# other part in views/patches
-
-from cubicweb.web import formfields  # noqa
-
-
-@monkeypatch(formfields)  # noqa
-def guess_field(eschema, rschema, role='subject', req=None, **kwargs):
-    """This function return the most adapted field to edit the given relation
-    (`rschema`) where the given entity type (`eschema`) is the subject or object
-    (`role`).
-
-    The field is initialized according to information found in the schema,
-    though any value can be explicitly specified using `kwargs`.
-    """
-    fieldclass = None
-    rdef = eschema.rdef(rschema, role)
-    if role == 'subject':
-        targetschema = rdef.object
-        if rschema.final:
-            if rdef.get('internationalizable'):
-                kwargs.setdefault('internationalizable', True)
-    else:
-        targetschema = rdef.subject
-    card = rdef.role_cardinality(role)
-    composite = getattr(rdef, 'composite', None)
-    kwargs['name'] = rschema.type
-    kwargs['role'] = role
-    kwargs['eidparam'] = True
-    # don't mark composite relation as required, we want the composite element
-    # to be removed when not linked to its parent
-    kwargs.setdefault('required', card in '1+' and composite != formfields.neg_role(role))
-    if role == 'object':
-        kwargs.setdefault('label', (eschema.type, rschema.type + '_object'))
-    else:
-        kwargs.setdefault('label', (eschema.type, rschema.type))
-    kwargs.setdefault('help', rdef.description)
-    if rschema.final:
-        fieldclass = kwargs.pop('fieldclass', formfields.FIELDS[targetschema])
-        if issubclass(fieldclass, formfields.StringField):
-            if eschema.has_metadata(rschema, 'format'):
-                # use RichTextField instead of StringField if the attribute has
-                # a "format" metadata. But getting information from constraints
-                # may be useful anyway...
-                for cstr in rdef.constraints:
-                    if isinstance(cstr, formfields.StaticVocabularyConstraint):
-                        raise Exception('rich text field with static vocabulary')
-                return formfields.RichTextField(**kwargs)
-            # init StringField parameters according to constraints
-            for cstr in rdef.constraints:
-                if isinstance(cstr, formfields.StaticVocabularyConstraint):
-                    kwargs.setdefault('choices', cstr.vocabulary)
-                    break
-            for cstr in rdef.constraints:
-                if isinstance(cstr, formfields.SizeConstraint) and cstr.max is not None:
-                    kwargs['max_length'] = cstr.max
-            return fieldclass(**kwargs)
-        if issubclass(fieldclass, formfields.FileField):
-            if req:
-                aff_kwargs = req.vreg['uicfg'].select('autoform_field_kwargs', req)
-            else:
-                aff_kwargs = formfields._AFF_KWARGS
-            for metadata in formfields.KNOWN_METAATTRIBUTES:
-                metaschema = eschema.has_metadata(rschema, metadata)
-                if metaschema is not None:
-                    metakwargs = aff_kwargs.etype_get(eschema, metaschema, 'subject')
-                    kwargs['%s_field' % metadata] = formfields.guess_field(eschema, metaschema,
-                                                                           req=req, **metakwargs)
-        return fieldclass(**kwargs)
-    return formfields.RelationField.fromcardinality(card, **kwargs)
--- a/cubicweb_seda/views/__init__.py	Thu Oct 05 17:35:16 2017 +0200
+++ b/cubicweb_seda/views/__init__.py	Wed Oct 11 08:06:59 2017 +0200
@@ -24,9 +24,6 @@
 # XXX alias to avoid side effect: uicfg will become our uicfg submodule. Not necessary with 3.23?
 from cubicweb.web.views import uicfg as cwuicfg
 
-# XXX trigger monkey patches necessary to import this module, until we use a recent version of
-# lgc.registry supporting instantiation of rtags with explicit __module__ argument
-from .. import site_cubicweb  # noqa
 from ..xsd import XSDM_MAPPING
 from ..xsd2uicfg import FIRST_LEVEL_ETYPES
 from .widgets import SEDAMetaField
--- a/cubicweb_seda/views/archiveunit.py	Thu Oct 05 17:35:16 2017 +0200
+++ b/cubicweb_seda/views/archiveunit.py	Wed Oct 11 08:06:59 2017 +0200
@@ -1117,7 +1117,7 @@
                   & simplified_profile())
 
     def inlined_form_views(self):
-        views = super(DataObjectSimplifiedAutomaticEntityForm, self).inlined_form_views()
+        views = list(super(DataObjectSimplifiedAutomaticEntityForm, self).inlined_form_views())
         ref_forms = [v.form for v in views if v.rtype == 'seda_data_object_reference_id']
         if ref_forms:  # may be empty if user has no write access
             ref_form = ref_forms[0]
--- a/cubicweb_seda/views/patches.py	Thu Oct 05 17:35:16 2017 +0200
+++ b/cubicweb_seda/views/patches.py	Wed Oct 11 08:06:59 2017 +0200
@@ -46,90 +46,3 @@
 # this js file contains a custom implementation of addInlineCreationForm that propage
 # sedaContainerEID
 autoform.AutomaticEntityForm.needs_js += ('cubes.seda.form.js',)
-
-
-# fix unexpected redirect after clicking on cancel in reledit ######################################
-# (https://www.cubicweb.org/ticket/13120795)
-
-from cubicweb.web.views import reledit  # noqa
-
-orig_build_form = reledit.AutoClickAndEditFormView._build_form
-
-
-@monkeypatch(reledit.AutoClickAndEditFormView)
-def _build_form(*args, **kwargs):
-    form, renderer = orig_build_form(*args, **kwargs)
-    for button in getattr(form, 'form_buttons', ()):
-        if button.label.endswith('cancel') and 'class' in button.attrs:
-            button.attrs['class'] = button.attrs['class'].replace('cwjs-edition-cancel', '')
-    return form, renderer
-
-
-# auto-configuration of custom fields ##############################################################
-# (https://www.cubicweb.org/ticket/14474840)
-# other part in site_cubicweb
-
-from cubicweb.web import formfields  # noqa
-from cubicweb.web.views import forms  # noqa
-
-
-@monkeypatch(forms.EntityFieldsForm, methodname='field_by_name')
-@forms.iclassmethod
-def field_by_name(cls_or_self, name, role=None, eschema=None):
-    """return field with the given name and role. If field is not explicitly
-    defined for the form but `eclass` is specified, guess_field will be
-    called.
-    """
-    try:
-        return super(forms.EntityFieldsForm, cls_or_self).field_by_name(name, role)
-    except forms.form.FieldNotFound:
-        if eschema is None or role is None or name not in eschema.schema:
-            raise
-        rschema = eschema.schema.rschema(name)
-        # XXX use a sample target type. Document this.
-        tschemas = rschema.targets(eschema, role)
-        fieldclass = cls_or_self.uicfg_aff.etype_get(
-            eschema, rschema, role, tschemas[0])
-        kwargs = cls_or_self.uicfg_affk.etype_get(
-            eschema, rschema, role, tschemas[0])
-        if kwargs is None:
-            kwargs = {}
-        if fieldclass:
-            if not isinstance(fieldclass, type):
-                return fieldclass  # already an instance
-            kwargs['fieldclass'] = fieldclass
-        if isinstance(cls_or_self, type):
-            req = None
-        else:
-            req = cls_or_self._cw
-        field = formfields.guess_field(eschema, rschema, role, req=req, eidparam=True, **kwargs)
-        if field is None:
-            raise
-        return field
-
-
-# allow configuration of inlined form renderer using a class attribute #############################
-# (https://www.cubicweb.org/ticket/15755515)
-
-from logilab.common.decorators import cached  # noqa
-
-autoform.InlineEntityEditionFormView.form_renderer_id = 'inline'
-
-
-@monkeypatch(autoform.InlineEntityEditionFormView, methodname='form')
-@property
-@cached
-def form(self):
-    entity = self._entity()
-    form = self._cw.vreg['forms'].select('edition', self._cw,
-                                         entity=entity,
-                                         formtype='inlined',
-                                         form_renderer_id=self.form_renderer_id,
-                                         copy_nav_params=False,
-                                         mainform=False,
-                                         parent_form=self.pform,
-                                         **self.cw_extra_kwargs)
-    if self.pform is None:
-        form.restore_previous_post(form.session_key())
-    self.add_hiddens(form, entity)
-    return form