[entities] Let dataset_maintainer just return name and email information
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 22 Jan 2015 18:07:51 +0100
changeset 67 64966fde037f
parent 66 e9f30ed9b309
child 68 dd318b930f1d
[entities] Let dataset_maintainer just return name and email information Thus do not force that downstream code to use CWUser.
entities.py
test/data/entities.py
--- a/entities.py	Wed Jan 21 16:47:14 2015 +0100
+++ b/entities.py	Thu Jan 22 18:07:51 2015 +0100
@@ -104,14 +104,11 @@
                 'owner_org':self.ckan_get_organization_id(
                     self.ckan_organization)
                }
-        maintainer = self.dataset_maintainer()
+        maintainer, maintainer_email = self.dataset_maintainer()
         if maintainer:
-            if isinstance(maintainer, basestring):
-                data['maintainer'] = maintainer
-            else:
-                data['maintainer'] = maintainer.dc_long_title()
-                if maintainer.primary_email:
-                    data['maintainer_email'] = maintainer.primary_email[0].address
+            data['maintainer'] = maintainer
+        if maintainer_email:
+            data['maintainer_email'] = maintainer_email
         data['tags'] = list(self.dataset_tags())
         data['extras'] = list(self.dataset_extras())
         return data
@@ -127,10 +124,10 @@
                 yield {'name': slugify(tag.name)}
 
     def dataset_maintainer(self):
-        """May return a CWUser entity corresponding to the maintainer of
+        """May return (name, email) information about the maintainer of
         dataset-like entity.
         """
-        return None
+        return None, None
 
 
 class CKANResourceAdapter(EntityAdapter):
--- a/test/data/entities.py	Wed Jan 21 16:47:14 2015 +0100
+++ b/test/data/entities.py	Thu Jan 22 18:07:51 2015 +0100
@@ -9,7 +9,14 @@
 
     def dataset_maintainer(self):
         if self.entity.maintainer:
-            return self.entity.maintainer[0]
+            user = self.entity.maintainer[0]
+            if user.primary_email:
+                email = user.primary_email[0].address
+            else:
+                email = None
+            return user.dc_long_title(), email
+        else:
+            return None, None
 
 
 class CWDatasetResourceCKANResourceAdapter(FileCKANResourceAdapter):