changeset 1638:9e17690fb187

quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
author souliane <souliane@mailoo.org>
date Sat, 21 Nov 2015 13:58:30 +0100
parents 7751b5a51586
children baac2e120600
files frontends/src/quick_frontend/quick_blog.py
diffstat 1 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_blog.py	Fri Nov 20 11:46:26 2015 +0100
+++ b/frontends/src/quick_frontend/quick_blog.py	Sat Nov 21 13:58:30 2015 +0100
@@ -41,13 +41,14 @@
 
     def __init__(self, data):
         """
-        @param data(dict, None): microblog data as return by bridge methods
-            if data is None, set a default values
+        @param data(dict): microblog data as return by bridge methods
+            if data values are not defined, set default values
         """
         self.id = data['id']
         self.title = data.get('title')
         self.title_rich = None
         self.title_xhtml = data.get('title_xhtml')
+        self.tags = mbdata2tags(data)
         self.content = data.get('content')
         self.content_rich = None
         self.content_xhtml = data.get('content_xhtml')
@@ -197,7 +198,7 @@
 
         used during init (it's a set and not a reset then)
         or later (e.g. message sent, or cancellation of an edition
-        @param idem_data(dict): data as in __init__
+        @param idem_data(dict, None): data as in __init__
         """
         if item_data is None:
             self.new = True
@@ -213,7 +214,7 @@
             self.author_jid = self.service
         self.mode = C.ENTRY_MODE_TEXT if self.item.content_xhtml is None else C.ENTRY_MODE_XHTML
 
-    def refresh(semf):
+    def refresh(self):
         """Refresh the display when data have been modified"""
         pass
 
@@ -243,7 +244,7 @@
     def send(self):
         """Send entry according to parent QuickBlog configuration and current level"""
 
-        # keys other to keep other than content* and title*
+        # keys to keep other than content*, title* and tag*
         keys_to_keep = ('id', 'comments', 'author', 'author_jid', 'published')
 
         mb_data = {}
@@ -259,6 +260,8 @@
                 if value is not None:
                     mb_data[name] = value
 
+        mb_data.update(tags2mbdata(self.item.tags))
+
         if self.level == 0:
             if self.blog.new_message_target == C.PUBLIC:
                 if self.new:
@@ -451,3 +454,25 @@
         raise ValueError("type_ should be ENTRY or COMMENT")
     if COMMENTS_CLS is None:
         COMMENTS_CLS = ENTRY_CLS
+
+
+def mbdata2tags(mb_data):
+    """Parse the tags in microblog data.
+    
+    @param mb_data (dict): microblog data as return by bridge methods
+    @return list[unicode]
+    """
+    return [tag for key, tag in mb_data.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
+    
+def tags2mbdata(tags):
+    """Build from the tags a dict using the microblog data format.
+    
+    @param tags (list[unicode]): list of tags
+    @return dict
+    """
+    data = {}
+    count = 0
+    for tag in tags:
+        data[('tag#%i' % count) if count else 'tag'] = tag
+        count += 1
+    return data