changeset 2476:6607bb29ab7b

tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
author Goffi <goffi@goffi.org>
date Fri, 19 Jan 2018 17:41:10 +0100
parents efd7a24d611c
children cae326e962c3
files src/tools/common/data_objects.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/tools/common/data_objects.py	Fri Jan 19 17:40:06 2018 +0100
+++ b/src/tools/common/data_objects.py	Fri Jan 19 17:41:10 2018 +0100
@@ -25,11 +25,14 @@
 except ImportError:
     safe = unicode
 
+from sat.tools.common import uri as xmpp_uri
+
 
 class BlogItem(object):
 
-    def __init__(self, mb_data):
+    def __init__(self, mb_data, parent):
         self.mb_data = mb_data
+        self.parent = parent
         self._tags = None
         self._groups = None
         self._comments = None
@@ -44,6 +47,16 @@
         return self.mb_data.get(u'atom_id')
 
     @property
+    def uri(self):
+        node = self.parent.node
+        service = self.parent.service
+        return xmpp_uri.buildXMPPUri(u'pubsub',
+                                     subtype=u'microblog',
+                                     path=service,
+                                     node=node,
+                                     item=self.id)
+
+    @property
     def published(self):
         return self.mb_data.get(u'published')
 
@@ -133,7 +146,7 @@
 class BlogItems(object):
 
     def __init__(self, mb_data):
-        self.items = [BlogItem(i) for i in mb_data[0]]
+        self.items = [BlogItem(i, self) for i in mb_data[0]]
         self.metadata = mb_data[1]
 
     @property