Commit defe93f3 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[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.
parent 7347715bf0ee
......@@ -25,13 +25,14 @@ from itertools import chain
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 @@ class IDublinCoreAdapter(view.EntityAdapter):
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 @@ class IEmailableAdapter(view.EntityAdapter):
for attr in self.allowed_massmail_keys())
class INotifiableAdapter(view.EntityAdapter):
class INotifiableAdapter(EntityAdapter):
__regid__ = 'INotifiable'
__select__ = is_instance('Any')
......@@ -145,7 +146,7 @@ class INotifiableAdapter(view.EntityAdapter):
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 @@ def merge_weight_dict(maindict, newdict):
maindict.setdefault(weight, []).extend(words)
class IDownloadableAdapter(view.EntityAdapter):
class IDownloadableAdapter(EntityAdapter):
"""interface for downloadable entities"""
__regid__ = 'IDownloadable'
__abstract__ = True
......@@ -256,7 +257,7 @@ class IDownloadableAdapter(view.EntityAdapter):
# 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 @@ class ITreeAdapter(view.EntityAdapter):
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 @@ class ISerializableAdapter(view.EntityAdapter):
# error handling adapters ######################################################
class IUserFriendlyError(view.EntityAdapter):
class IUserFriendlyError(EntityAdapter):
__regid__ = 'IUserFriendlyError'
__abstract__ = True
......
......@@ -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
......
......@@ -1314,6 +1314,28 @@ class Relation(object):
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
......
......@@ -29,7 +29,7 @@ from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_use
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
......
......@@ -23,7 +23,7 @@ from os.path import join
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:
......
......@@ -554,18 +554,7 @@ class Component(ReloadableMixIn, View):
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
......@@ -23,12 +23,12 @@ from functools import partial
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')
......
......@@ -28,7 +28,8 @@ from logilab.common.date import todatetime
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 ################################################
......
......@@ -27,7 +27,7 @@ from logilab.common.graph import ordered_nodes
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
......
......@@ -25,11 +25,11 @@ from warnings import warn
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
......
......@@ -56,7 +56,7 @@ from logilab.mtconverter import xml_escape
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
......
......@@ -26,7 +26,8 @@ from logilab.mtconverter import xml_escape
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
......
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.
......@@ -2,6 +2,7 @@
Changelog history
===================
.. include:: 3.28.rst
.. include:: 3.27.rst
.. include:: 3.26.rst
.. include:: 3.25.rst
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment