[entities] Restore dc_ methods instead of __getattr__ proxy
In 8de62610cea2, a __getattr__ proxy was introduced to handle compatibility
with dc_* methods being called on entity instances instead of through the
IDublinCore adapter. Unfortunately, __getattr__ does not play well with
super() and since the latter is often used by, we here restore all dc_ methods
with an explicit proxy to the adapter. More verbose but should work.
Closes #17103999.
--- a/cubicweb/entities/__init__.py Wed Sep 13 17:19:42 2017 +0200
+++ b/cubicweb/entities/__init__.py Tue Sep 26 10:46:43 2017 +0200
@@ -98,15 +98,29 @@
# meta data api ###########################################################
- def __getattr__(self, name):
- prefix = 'dc_'
- if name.startswith(prefix):
- # Proxy to IDublinCore adapter for bw compat.
- adapted = self.cw_adapt_to('IDublinCore')
- method = name[len(prefix):]
- if hasattr(adapted, method):
- return getattr(adapted, method)
- raise AttributeError(name)
+ def dc_title(self):
+ return self.cw_adapt_to('IDublinCore').title()
+
+ def dc_long_title(self):
+ return self.cw_adapt_to('IDublinCore').long_title()
+
+ def dc_description(self, *args, **kwargs):
+ return self.cw_adapt_to('IDublinCore').description(*args, **kwargs)
+
+ def dc_authors(self):
+ return self.cw_adapt_to('IDublinCore').authors()
+
+ def dc_creator(self):
+ return self.cw_adapt_to('IDublinCore').creator()
+
+ def dc_date(self, *args, **kwargs):
+ return self.cw_adapt_to('IDublinCore').date(*args, **kwargs)
+
+ def dc_type(self, *args, **kwargs):
+ return self.cw_adapt_to('IDublinCore').type(*args, **kwargs)
+
+ def dc_language(self):
+ return self.cw_adapt_to('IDublinCore').language()
@property
def creator(self):