diff src/browser/sat_browser/blog.py @ 606:7af8f4ab3675 frontends_multi_profiles

browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:55:16 +0100
parents ed6d8f7c6026
children 537649f6a2d0
line wrap: on
line diff
--- a/src/browser/sat_browser/blog.py	Mon Feb 09 21:46:15 2015 +0100
+++ b/src/browser/sat_browser/blog.py	Mon Feb 09 21:55:16 2015 +0100
@@ -47,11 +47,14 @@
 import richtext
 from constants import Const as C
 from sat_frontends.quick_frontend import quick_widgets
+from sat_frontends.tools import jid
 
 # TODO: at some point we should decide which behaviors to keep and remove these two constants
 TOGGLE_EDITION_USE_ICON = False  # set to True to use an icon inside the "toggle syntax" button
 NEW_MESSAGE_USE_BUTTON = False  # set to True to display the "New message" button instead of an empty entry
 
+unicode = str # XXX: pyjamas doesn't manage unicode
+
 
 class MicroblogItem():
     # XXX: should be moved in a separated module
@@ -64,7 +67,7 @@
         self.title_xhtml = data.get('title_xhtml', '')
         self.content = data.get('content', '')
         self.content_xhtml = data.get('content_xhtml', '')
-        self.author = data['author']
+        self.author = jid.JID(data['author'])
         self.updated = float(data.get('updated', 0))  # XXX: int doesn't work here
         self.published = float(data.get('published', self.updated))  # XXX: int doesn't work here
         self.service = data.get('service', '')
@@ -104,8 +107,8 @@
 
         entry_avatar = SimplePanel()
         entry_avatar.setStyleName('mb_entry_avatar')
-        # FIXME
-        self.avatar = Image(C.DEFAULT_AVATAR) # self._blog_panel.host.getAvatar(self.author))
+        assert isinstance(self.author, jid.JID) # FIXME: temporary
+        self.avatar = Image(self._blog_panel.host.getAvatarURL(self.author)) # FIXME: self.author should be initially a jid.JID
         entry_avatar.add(self.avatar)
         self.panel.add(entry_avatar)
 
@@ -139,7 +142,7 @@
         self.header.setHTML("""<div class='mb_entry_header'>
                                    <span class='mb_entry_author'>%(author)s</span> on
                                    <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s
-                               </div>""" % {'author': html_tools.html_sanitize(self.author),
+                               </div>""" % {'author': html_tools.html_sanitize(unicode(self.author)),
                                             'published': datetime.fromtimestamp(self.published),
                                             'updated': update_text if self.published != self.updated else ''
                                             }
@@ -275,7 +278,7 @@
         data = {'id': str(time()),
                 'new': True,
                 'type': 'comment',
-                'author': self._blog_panel.host.whoami.bare,
+                'author': unicode(self._blog_panel.host.whoami.bare),
                 'service': self.comments_service,
                 'node': self.comments_node
                 }
@@ -391,7 +394,7 @@
                     self.new_button.setVisible(False)
                 data = {'id': str(time()),
                         'new': True,
-                        'author': self.host.whoami.bare,
+                        'author': unicode(self.host.whoami.bare),
                         }
                 entry = self.addEntry(data)
                 entry.edit(True)
@@ -541,10 +544,11 @@
     def addEntryIfAccepted(self, sender, groups, mblog_entry):
         """Check if an entry can go in MicroblogPanel and add to it
 
-        @param sender: jid of the entry sender
+        @param sender(jid.JID): jid of the entry sender
         @param groups: groups which can receive this entry
         @param mblog_entry: panels.MicroblogItem instance
         """
+        assert isinstance(sender, jid.JID) # FIXME temporary
         if (mblog_entry.type == "comment"
             or self.isJidAccepted(sender)
             or (groups == None and sender == self.host.profiles[self.profile].whoami.bare)
@@ -660,19 +664,22 @@
         if self.selected_entry:
             self.selected_entry.removeStyleName('selected_entry')
         if entry:
-            log.debug("microblog entry selected (author=%s)" % entry.author)
+            log.debug("microblog entry selected (author=%s)" % unicode(entry.author))
             entry.addStyleName('selected_entry')
         self.selected_entry = entry
 
-    def updateValue(self, type_, jid, value):
+    def updateValue(self, type_, jid_, value):
         """Update a jid value in entries
+
         @param type_: one of 'avatar', 'nick'
-        @param jid: jid concerned
+        @param jid_(jid.JID): jid concerned
         @param value: new value"""
+        assert isinstance(jid_, jid.JID) # FIXME: temporary
         def updateVPanel(vpanel):
+            avatar_url = self.host.getAvatarURL(jid_)
             for child in vpanel.children:
-                if isinstance(child, MicroblogEntry) and child.author == jid:
-                    child.updateAvatar(value)
+                if isinstance(child, MicroblogEntry) and child.author == jid_:
+                    child.updateAvatar(avatar_url)
                 elif isinstance(child, VerticalPanel):
                     updateVPanel(child)
         if type_ == 'avatar':
@@ -700,6 +707,7 @@
         @param jid_(jid.JID): jid to check
         @return: True if the jid is accepted
         """
+        assert isinstance(jid_, jid.JID) # FIXME temporary
         if self.accept_all():
             return True
         for group in self._accepted_groups: