changeset 741:c3cb68227cca

browser_side: read and write tags from microblog data: - not tested! - implementation missing in quick_blog.Item and quick_blog.Entry
author souliane <souliane@mailoo.org>
date Thu, 19 Nov 2015 17:20:37 +0100
parents b6510fd9ae15
children d123e27fc386
files src/browser/sat_browser/list_manager.py src/browser/sat_browser/richtext.py
diffstat 2 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/list_manager.py	Thu Nov 19 16:43:18 2015 +0100
+++ b/src/browser/sat_browser/list_manager.py	Thu Nov 19 17:20:37 2015 +0100
@@ -483,7 +483,7 @@
     STYLE = {"main": "tagsPanel-main",
              "tags": "tagsPanel-tags"}
 
-    def __init__(self, suggested_tags, tags):
+    def __init__(self, suggested_tags, tags=None):
         """
         
         @param suggested_tags (list[unicode]): list of all suggested tags
@@ -491,6 +491,10 @@
         """
         base_panel.ToggleStackPanel.__init__(self, Width="100%")
         self.addStyleName(self.STYLE["main"])
+        
+        if tags is None:
+            tags = []
+
         self.tags = ListPanel(quick_list_manager.QuickTagList(suggested_tags), tags)
         self.tags.addStyleName(self.STYLE["tags"])
         self.tags.ACCEPT_NEW_ENTRY = True
--- a/src/browser/sat_browser/richtext.py	Thu Nov 19 16:43:18 2015 +0100
+++ b/src/browser/sat_browser/richtext.py	Thu Nov 19 17:20:37 2015 +0100
@@ -89,7 +89,7 @@
         if edit is None:
             edit = hasattr(self, 'textarea') and self.textarea.getVisible()
 
-        for widget in ['title_panel', 'command']:
+        for widget in ['title_panel', 'tags_panel', 'command']:
             if hasattr(self, widget):
                 getattr(self, widget).setVisible(edit)
 
@@ -120,12 +120,11 @@
             self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2)
             self.setWidget(self.title_offset, 0, self.title_panel)
 
-        if not self.read_only and not hasattr(self, 'tags'):
+        if not self.read_only and not hasattr(self, 'tags_panel'):
             suggested_tags = []  # TODO: feed this list with tags suggestion
-            tags = []  # TODO: feed this list with tags already assigned to this message
-            self.tags = list_manager.TagsPanel(suggested_tags, tags)
+            self.tags_panel = list_manager.TagsPanel(suggested_tags)
             self.getFlexCellFormatter().setColSpan(self.tags_offset, 0, 2)
-            self.setWidget(self.tags_offset, 0, self.tags)
+            self.setWidget(self.tags_offset, 0, self.tags_panel)
 
         if not self.read_only and not hasattr(self, 'command'):
             self.command = HorizontalPanel()
@@ -266,6 +265,11 @@
             content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax}
         if hasattr(self, 'title_panel'):
             content.update({'title': self.strproc(self.title_panel.getText())})
+        if hasattr(self, 'tags_panel'):
+            count = 0
+            for tag in self.tags_panel.getTags():
+                content['tag#%i' % count if count else 'tag'] = tag
+                count += 1
         return content
 
     def edit(self, edit=False, abort=False, sync=False):
@@ -296,9 +300,16 @@
                         content.update({'text': text})
                     content.update({'syntax': syntax})
                     self.textarea.setText(content['text'])
+                    
                     if hasattr(self, 'title_panel') and 'title' in content:
                         self.title_panel.setText(content['title'])
                         self.title_panel.setStackVisible(0, content['title'] != '')
+
+                    if hasattr(self, 'tags_panel') and 'tag' in content:
+                        tags = [tag for key, tag in content.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
+                        self.tags_panel.setTags(tags)
+                        self.tags_panel.setStackVisible(0, len(tags) > 0)
+
                     self.setToolBar(syntax)
                 if content['text'] and content['syntax'] != syntax:
                     self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'])
@@ -316,7 +327,10 @@
         content = self._original_content
         text = content['text']
         if 'title' in content and content['title']:
-            text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), content['text'])
+            text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), text)
+        if 'tag' in content:  # FIXME: display it more beautiful
+            tags = [tag for key, tag in content.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
+            text = '%s<h3>%s %s</h3>' % (text, _("Tags:"), html_tools.html_sanitize(", ".join(tags)))
         self.display.setContent({'text': text})
 
     def setFocus(self, focus):