[saem-devel] [PATCH 05 of 12] Move monkey-patch of cw.entity.Entity in a non-reloadable location

saem-devel at lists.cubicweb.org saem-devel at lists.cubicweb.org
Wed Jan 25 13:23:24 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485266753 -3600
#      Tue Jan 24 15:05:53 2017 +0100
# Node ID c74e3dc65e7735fd7e9a56fece49d1d05527d859
# Parent  5757330bc7e8c3d35c88169569d32e33c8236c71
Move monkey-patch of cw.entity.Entity in a non-reloadable location

else you get into trouble with legacy  'start' command when code is being
reloaded.

diff --git a/entities/__init__.py b/entities/__init__.py
--- a/entities/__init__.py
+++ b/entities/__init__.py
@@ -19,21 +19,9 @@ from logilab.common.decorators import mo
 
 from cubicweb.view import Adapter, EntityAdapter
 from cubicweb.predicates import match_kwargs, relation_possible, is_instance
-from cubicweb.entity import Entity
 from cubicweb.entities import AnyEntity, fetch_config, authobjs
 
 
-_orig_rest_path = Entity.rest_path
-
-
- at monkeypatch(Entity)
-def rest_path(self, *args, **kwargs):
-    """Return ark:/<ARK> is entity has an ark attribute."""
-    if getattr(self, 'ark', None) is None:
-        return _orig_rest_path(self, *args, **kwargs)
-    return u'ark:/' + self.ark
-
-
 class ARKGeneratorMixIn(object):
     """Entity adapter for ARK unique identifier generation"""
     __abstract__ = True
diff --git a/site_cubicweb.py b/site_cubicweb.py
--- a/site_cubicweb.py
+++ b/site_cubicweb.py
@@ -24,6 +24,7 @@ from logilab.common.decorators import mo
 from cubicweb import cwvreg, _
 from cubicweb.cwconfig import register_persistent_options
 from cubicweb.uilib import PRINTERS
+from cubicweb.entity import Entity
 
 from cubes.skos import rdfio
 from cubes.skos.ccplugin import ImportSkosData
@@ -36,6 +37,19 @@ from . import permanent_url, _massive_st
 from . import pg_trgm  # noqa pylint: disable=unused-import
 
 
+# override Entity.rest_path to use ark for entities which have one
+
+_orig_rest_path = Entity.rest_path
+
+
+ at monkeypatch(Entity)
+def rest_path(self, *args, **kwargs):
+    """Return ark:/<ARK> is entity has an ark attribute."""
+    if getattr(self, 'ark', None) is None:
+        return _orig_rest_path(self, *args, **kwargs)
+    return u'ark:/' + self.ark
+
+
 # configure RDF generator to use ark based uri as canonical uris, and deactivating implicit
 # 'same_as_urls' in this case
 


More information about the saem-devel mailing list