[adapters] move class EntityAdapter from cubicweb.view to cubicweb.entity
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Sat, 08 Feb 2020 22:57:59 +0100
changeset 12880 59d4ad7e7df3
parent 12879 7347715bf0ee
child 12881 38fcf5707295
[adapters] move class EntityAdapter from cubicweb.view to cubicweb.entity The adapter mechanism is not specific to the use of views. Moving the class the cubicweb.entity makes this clearer.
cubicweb/entities/adapters.py
cubicweb/entities/wfobjs.py
cubicweb/entity.py
cubicweb/test/unittest_predicates.py
cubicweb/test/unittest_vregistry.py
cubicweb/view.py
cubicweb/web/test/unittest_idownloadable.py
cubicweb/web/views/calendar.py
cubicweb/web/views/editcontroller.py
cubicweb/web/views/ibreadcrumbs.py
cubicweb/web/views/navigation.py
cubicweb/web/views/xmlrss.py
doc/changes/3.28.rst
doc/changes/changelog.rst
--- a/cubicweb/entities/adapters.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/entities/adapters.py	Sat Feb 08 22:57:59 2020 +0100
@@ -25,13 +25,14 @@
 from logilab.mtconverter import TransformError
 from logilab.common.decorators import cached
 
-from cubicweb import (Unauthorized, ValidationError, view, ViolatedConstraint,
+from cubicweb.entity import EntityAdapter
+from cubicweb import (Unauthorized, ValidationError, ViolatedConstraint,
                       UniqueTogetherError)
 from cubicweb.schema import constraint_name_for
 from cubicweb.predicates import is_instance, relation_possible, match_exception
 
 
-class IDublinCoreAdapter(view.EntityAdapter):
+class IDublinCoreAdapter(EntityAdapter):
     __regid__ = 'IDublinCore'
     __select__ = is_instance('Any')
 
@@ -93,7 +94,7 @@
         return self._cw._(self._cw.vreg.property_value('ui.language'))
 
 
-class IEmailableAdapter(view.EntityAdapter):
+class IEmailableAdapter(EntityAdapter):
     __regid__ = 'IEmailable'
     __select__ = relation_possible('primary_email') | relation_possible('use_email')
 
@@ -126,7 +127,7 @@
                     for attr in self.allowed_massmail_keys())
 
 
-class INotifiableAdapter(view.EntityAdapter):
+class INotifiableAdapter(EntityAdapter):
     __regid__ = 'INotifiable'
     __select__ = is_instance('Any')
 
@@ -145,7 +146,7 @@
         return ()
 
 
-class IFTIndexableAdapter(view.EntityAdapter):
+class IFTIndexableAdapter(EntityAdapter):
     """standard adapter to handle fulltext indexing
 
     .. automethod:: cubicweb.entities.adapters.IFTIndexableAdapter.fti_containers
@@ -226,7 +227,7 @@
         maindict.setdefault(weight, []).extend(words)
 
 
-class IDownloadableAdapter(view.EntityAdapter):
+class IDownloadableAdapter(EntityAdapter):
     """interface for downloadable entities"""
     __regid__ = 'IDownloadable'
     __abstract__ = True
@@ -256,7 +257,7 @@
 
 
 # XXX should propose to use two different relations for children/parent
-class ITreeAdapter(view.EntityAdapter):
+class ITreeAdapter(EntityAdapter):
     """This adapter provides a tree interface.
 
     It has to be overriden to be configured using the tree_relation,
@@ -412,7 +413,7 @@
         return path
 
 
-class ISerializableAdapter(view.EntityAdapter):
+class ISerializableAdapter(EntityAdapter):
     """Adapter to serialize an entity to a bare python structure that may be
     directly serialized to e.g. JSON.
     """
@@ -441,7 +442,7 @@
 # error handling adapters ######################################################
 
 
-class IUserFriendlyError(view.EntityAdapter):
+class IUserFriendlyError(EntityAdapter):
     __regid__ = 'IUserFriendlyError'
     __abstract__ = True
 
--- a/cubicweb/entities/wfobjs.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/entities/wfobjs.py	Sat Feb 08 22:57:59 2020 +0100
@@ -24,7 +24,7 @@
 from logilab.common.decorators import cached, clear_cache
 
 from cubicweb.entities import AnyEntity, fetch_config
-from cubicweb.view import EntityAdapter
+from cubicweb.entity import EntityAdapter
 from cubicweb.predicates import relation_possible
 
 
--- a/cubicweb/entity.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/entity.py	Sat Feb 08 22:57:59 2020 +0100
@@ -1314,6 +1314,28 @@
     def __set__(self, eobj, value):
         raise NotImplementedError
 
+# entity adapters #############################################################
+
+class Adapter(AppObject):
+    """base class for adapters"""
+    __registry__ = 'adapters'
+
+
+class EntityAdapter(Adapter):
+    """base class for entity adapters (eg adapt an entity to an interface)
+
+    An example would be:
+
+    >>> some_entity.cw_adapt_to('IDownloadable')
+    """
+    def __init__(self, _cw, **kwargs):
+        try:
+            self.entity = kwargs.pop('entity')
+        except KeyError:
+            self.entity = kwargs['rset'].get_entity(kwargs.get('row') or 0,
+                                                    kwargs.get('col') or 0)
+        Adapter.__init__(self, _cw, **kwargs)
+
 
 from logging import getLogger
 from cubicweb import set_log_methods
--- a/cubicweb/test/unittest_predicates.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/test/unittest_predicates.py	Sat Feb 08 22:57:59 2020 +0100
@@ -29,7 +29,7 @@
                                  multi_lines_rset, score_entity, is_in_state,
                                  rql_condition, relation_possible, match_form_params,
                                  paginated_rset)
-from cubicweb.view import EntityAdapter
+from cubicweb.entity import EntityAdapter
 from cubicweb.web import action
 
 
--- a/cubicweb/test/unittest_vregistry.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/test/unittest_vregistry.py	Sat Feb 08 22:57:59 2020 +0100
@@ -23,7 +23,7 @@
 from cubicweb import CW_SOFTWARE_ROOT as BASE, devtools
 from cubicweb.cwvreg import CWRegistryStore, UnknownProperty
 from cubicweb.devtools.testlib import CubicWebTC
-from cubicweb.view import EntityAdapter
+from cubicweb.entity import EntityAdapter
 
 
 class YesSchema:
--- a/cubicweb/view.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/view.py	Sat Feb 08 22:57:59 2020 +0100
@@ -554,18 +554,7 @@
     def domid(self):
         return '%sComponent' % domid(self.__regid__)
 
-
-class Adapter(AppObject):
-    """base class for adapters"""
-    __registry__ = 'adapters'
-
-
-class EntityAdapter(Adapter):
-    """base class for entity adapters (eg adapt an entity to an interface)"""
-    def __init__(self, _cw, **kwargs):
-        try:
-            self.entity = kwargs.pop('entity')
-        except KeyError:
-            self.entity = kwargs['rset'].get_entity(kwargs.get('row') or 0,
-                                                    kwargs.get('col') or 0)
-        Adapter.__init__(self, _cw, **kwargs)
+# EntityAdapter moved to cubicweb.entity ######################################
+from logilab.common.deprecation import class_moved
+from cubicweb import entity
+EntityAdapter = class_moved(entity.EntityAdapter) # cubicweb 3.28
--- a/cubicweb/web/test/unittest_idownloadable.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/web/test/unittest_idownloadable.py	Sat Feb 08 22:57:59 2020 +0100
@@ -23,12 +23,12 @@
 from pytz import utc
 
 from cubicweb.devtools.testlib import CubicWebTC, real_error_handling
-from cubicweb import view
+from cubicweb.entity import EntityAdapter
 from cubicweb.predicates import is_instance
 from cubicweb.web import http_headers
 
 
-class IDownloadableUser(view.EntityAdapter):
+class IDownloadableUser(EntityAdapter):
     __regid__ = 'IDownloadable'
     __select__ = is_instance('CWUser')
 
--- a/cubicweb/web/views/calendar.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/web/views/calendar.py	Sat Feb 08 22:57:59 2020 +0100
@@ -28,7 +28,8 @@
 
 from cubicweb.utils import json_dumps, make_uid
 from cubicweb.predicates import adaptable
-from cubicweb.view import EntityView, EntityAdapter
+from cubicweb.view import EntityView
+from cubicweb.entity import EntityAdapter
 
 # useful constants & functions ################################################
 
--- a/cubicweb/web/views/editcontroller.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/web/views/editcontroller.py	Sat Feb 08 22:57:59 2020 +0100
@@ -27,7 +27,7 @@
 from rql.utils import rqlvar_maker
 
 from cubicweb import _, ValidationError, UnknownEid
-from cubicweb.view import EntityAdapter
+from cubicweb.entity import EntityAdapter
 from cubicweb.predicates import is_instance
 from cubicweb.web import RequestError, NothingToEdit, ProcessFormError
 from cubicweb.web.views import basecontrollers, autoform
--- a/cubicweb/web/views/ibreadcrumbs.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/web/views/ibreadcrumbs.py	Sat Feb 08 22:57:59 2020 +0100
@@ -25,11 +25,11 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb import tags, uilib
-from cubicweb.entity import Entity
+from cubicweb.entity import Entity, EntityAdapter
 from cubicweb.predicates import (is_instance, one_line_rset, adaptable,
                                 one_etype_rset, multi_lines_rset, any_rset,
                                 match_form_params)
-from cubicweb.view import EntityView, EntityAdapter
+from cubicweb.view import EntityView
 from cubicweb.web.views import basecomponents
 # don't use AnyEntity since this may cause bug with isinstance() due to reloading
 
--- a/cubicweb/web/views/navigation.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/web/views/navigation.py	Sat Feb 08 22:57:59 2020 +0100
@@ -56,7 +56,7 @@
 
 from cubicweb.predicates import paginated_rset, sorted_rset, adaptable
 from cubicweb.uilib import cut
-from cubicweb.view import EntityAdapter
+from cubicweb.entity import EntityAdapter
 from cubicweb.web.component import EmptyComponent, EntityCtxComponent, NavigationComponent
 
 
--- a/cubicweb/web/views/xmlrss.py	Sat Feb 15 17:08:15 2020 +0100
+++ b/cubicweb/web/views/xmlrss.py	Sat Feb 08 22:57:59 2020 +0100
@@ -26,7 +26,8 @@
 
 from cubicweb.predicates import (is_instance, non_final_entity, one_line_rset,
                                  appobject_selectable, adaptable)
-from cubicweb.view import EntityView, EntityAdapter, AnyRsetView, Component
+from cubicweb.view import EntityView, AnyRsetView, Component
+from cubicweb.entity import EntityAdapter
 from cubicweb.uilib import simple_sgml_tag
 from cubicweb.web import httpcache, component
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/changes/3.28.rst	Sat Feb 08 22:57:59 2020 +0100
@@ -0,0 +1,8 @@
+3.28
+====
+
+Changes
+-------
+
+- the class cubicweb.view.EntityAdapter was moved to cubicweb.entity.EntityAdapter
+  a deprecation warning is in place, but please update your source code accordingly.
--- a/doc/changes/changelog.rst	Sat Feb 15 17:08:15 2020 +0100
+++ b/doc/changes/changelog.rst	Sat Feb 08 22:57:59 2020 +0100
@@ -2,6 +2,7 @@
  Changelog history
 ===================
 
+.. include:: 3.28.rst
 .. include:: 3.27.rst
 .. include:: 3.26.rst
 .. include:: 3.25.rst