comparison 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
comparison
equal deleted inserted replaced
605:917e271975d9 606:7af8f4ab3675
45 import dialog 45 import dialog
46 import base_widget 46 import base_widget
47 import richtext 47 import richtext
48 from constants import Const as C 48 from constants import Const as C
49 from sat_frontends.quick_frontend import quick_widgets 49 from sat_frontends.quick_frontend import quick_widgets
50 from sat_frontends.tools import jid
50 51
51 # TODO: at some point we should decide which behaviors to keep and remove these two constants 52 # TODO: at some point we should decide which behaviors to keep and remove these two constants
52 TOGGLE_EDITION_USE_ICON = False # set to True to use an icon inside the "toggle syntax" button 53 TOGGLE_EDITION_USE_ICON = False # set to True to use an icon inside the "toggle syntax" button
53 NEW_MESSAGE_USE_BUTTON = False # set to True to display the "New message" button instead of an empty entry 54 NEW_MESSAGE_USE_BUTTON = False # set to True to display the "New message" button instead of an empty entry
55
56 unicode = str # XXX: pyjamas doesn't manage unicode
54 57
55 58
56 class MicroblogItem(): 59 class MicroblogItem():
57 # XXX: should be moved in a separated module 60 # XXX: should be moved in a separated module
58 61
62 self.empty = data.get('new', False) 65 self.empty = data.get('new', False)
63 self.title = data.get('title', '') 66 self.title = data.get('title', '')
64 self.title_xhtml = data.get('title_xhtml', '') 67 self.title_xhtml = data.get('title_xhtml', '')
65 self.content = data.get('content', '') 68 self.content = data.get('content', '')
66 self.content_xhtml = data.get('content_xhtml', '') 69 self.content_xhtml = data.get('content_xhtml', '')
67 self.author = data['author'] 70 self.author = jid.JID(data['author'])
68 self.updated = float(data.get('updated', 0)) # XXX: int doesn't work here 71 self.updated = float(data.get('updated', 0)) # XXX: int doesn't work here
69 self.published = float(data.get('published', self.updated)) # XXX: int doesn't work here 72 self.published = float(data.get('published', self.updated)) # XXX: int doesn't work here
70 self.service = data.get('service', '') 73 self.service = data.get('service', '')
71 self.node = data.get('node', '') 74 self.node = data.get('node', '')
72 self.comments = data.get('comments', False) 75 self.comments = data.get('comments', False)
102 self.entry_actions.setStyleName('mb_entry_actions') 105 self.entry_actions.setStyleName('mb_entry_actions')
103 self.panel.add(self.entry_actions) 106 self.panel.add(self.entry_actions)
104 107
105 entry_avatar = SimplePanel() 108 entry_avatar = SimplePanel()
106 entry_avatar.setStyleName('mb_entry_avatar') 109 entry_avatar.setStyleName('mb_entry_avatar')
107 # FIXME 110 assert isinstance(self.author, jid.JID) # FIXME: temporary
108 self.avatar = Image(C.DEFAULT_AVATAR) # self._blog_panel.host.getAvatar(self.author)) 111 self.avatar = Image(self._blog_panel.host.getAvatarURL(self.author)) # FIXME: self.author should be initially a jid.JID
109 entry_avatar.add(self.avatar) 112 entry_avatar.add(self.avatar)
110 self.panel.add(entry_avatar) 113 self.panel.add(entry_avatar)
111 114
112 if TOGGLE_EDITION_USE_ICON: 115 if TOGGLE_EDITION_USE_ICON:
113 self.entry_dialog = HorizontalPanel() 116 self.entry_dialog = HorizontalPanel()
137 return 140 return
138 update_text = u" — ✍ " + "<span class='mb_entry_timestamp'>%s</span>" % datetime.fromtimestamp(self.updated) 141 update_text = u" — ✍ " + "<span class='mb_entry_timestamp'>%s</span>" % datetime.fromtimestamp(self.updated)
139 self.header.setHTML("""<div class='mb_entry_header'> 142 self.header.setHTML("""<div class='mb_entry_header'>
140 <span class='mb_entry_author'>%(author)s</span> on 143 <span class='mb_entry_author'>%(author)s</span> on
141 <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s 144 <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s
142 </div>""" % {'author': html_tools.html_sanitize(self.author), 145 </div>""" % {'author': html_tools.html_sanitize(unicode(self.author)),
143 'published': datetime.fromtimestamp(self.published), 146 'published': datetime.fromtimestamp(self.published),
144 'updated': update_text if self.published != self.updated else '' 147 'updated': update_text if self.published != self.updated else ''
145 } 148 }
146 ) 149 )
147 150
273 self._blog_panel.setSelectedEntry(self._current_comment, True) 276 self._blog_panel.setSelectedEntry(self._current_comment, True)
274 return 277 return
275 data = {'id': str(time()), 278 data = {'id': str(time()),
276 'new': True, 279 'new': True,
277 'type': 'comment', 280 'type': 'comment',
278 'author': self._blog_panel.host.whoami.bare, 281 'author': unicode(self._blog_panel.host.whoami.bare),
279 'service': self.comments_service, 282 'service': self.comments_service,
280 'node': self.comments_node 283 'node': self.comments_node
281 } 284 }
282 entry = self._blog_panel.addEntry(data) 285 entry = self._blog_panel.addEntry(data)
283 if entry is None: 286 if entry is None:
389 def addBox(): 392 def addBox():
390 if hasattr(self, 'new_button'): 393 if hasattr(self, 'new_button'):
391 self.new_button.setVisible(False) 394 self.new_button.setVisible(False)
392 data = {'id': str(time()), 395 data = {'id': str(time()),
393 'new': True, 396 'new': True,
394 'author': self.host.whoami.bare, 397 'author': unicode(self.host.whoami.bare),
395 } 398 }
396 entry = self.addEntry(data) 399 entry = self.addEntry(data)
397 entry.edit(True) 400 entry.edit(True)
398 if NEW_MESSAGE_USE_BUTTON: 401 if NEW_MESSAGE_USE_BUTTON:
399 self.new_button = Button("New message", listener=addBox) 402 self.new_button = Button("New message", listener=addBox)
539 542
540 543
541 def addEntryIfAccepted(self, sender, groups, mblog_entry): 544 def addEntryIfAccepted(self, sender, groups, mblog_entry):
542 """Check if an entry can go in MicroblogPanel and add to it 545 """Check if an entry can go in MicroblogPanel and add to it
543 546
544 @param sender: jid of the entry sender 547 @param sender(jid.JID): jid of the entry sender
545 @param groups: groups which can receive this entry 548 @param groups: groups which can receive this entry
546 @param mblog_entry: panels.MicroblogItem instance 549 @param mblog_entry: panels.MicroblogItem instance
547 """ 550 """
551 assert isinstance(sender, jid.JID) # FIXME temporary
548 if (mblog_entry.type == "comment" 552 if (mblog_entry.type == "comment"
549 or self.isJidAccepted(sender) 553 or self.isJidAccepted(sender)
550 or (groups == None and sender == self.host.profiles[self.profile].whoami.bare) 554 or (groups == None and sender == self.host.profiles[self.profile].whoami.bare)
551 or (groups and groups.intersection(self.accepted_groups))): 555 or (groups and groups.intersection(self.accepted_groups))):
552 self.addEntry(mblog_entry) 556 self.addEntry(mblog_entry)
658 if self.selected_entry == entry: 662 if self.selected_entry == entry:
659 entry = None 663 entry = None
660 if self.selected_entry: 664 if self.selected_entry:
661 self.selected_entry.removeStyleName('selected_entry') 665 self.selected_entry.removeStyleName('selected_entry')
662 if entry: 666 if entry:
663 log.debug("microblog entry selected (author=%s)" % entry.author) 667 log.debug("microblog entry selected (author=%s)" % unicode(entry.author))
664 entry.addStyleName('selected_entry') 668 entry.addStyleName('selected_entry')
665 self.selected_entry = entry 669 self.selected_entry = entry
666 670
667 def updateValue(self, type_, jid, value): 671 def updateValue(self, type_, jid_, value):
668 """Update a jid value in entries 672 """Update a jid value in entries
673
669 @param type_: one of 'avatar', 'nick' 674 @param type_: one of 'avatar', 'nick'
670 @param jid: jid concerned 675 @param jid_(jid.JID): jid concerned
671 @param value: new value""" 676 @param value: new value"""
677 assert isinstance(jid_, jid.JID) # FIXME: temporary
672 def updateVPanel(vpanel): 678 def updateVPanel(vpanel):
679 avatar_url = self.host.getAvatarURL(jid_)
673 for child in vpanel.children: 680 for child in vpanel.children:
674 if isinstance(child, MicroblogEntry) and child.author == jid: 681 if isinstance(child, MicroblogEntry) and child.author == jid_:
675 child.updateAvatar(value) 682 child.updateAvatar(avatar_url)
676 elif isinstance(child, VerticalPanel): 683 elif isinstance(child, VerticalPanel):
677 updateVPanel(child) 684 updateVPanel(child)
678 if type_ == 'avatar': 685 if type_ == 'avatar':
679 updateVPanel(self.vpanel) 686 updateVPanel(self.vpanel)
680 687
698 """Tell if a jid is actepted and must be shown in this panel 705 """Tell if a jid is actepted and must be shown in this panel
699 706
700 @param jid_(jid.JID): jid to check 707 @param jid_(jid.JID): jid to check
701 @return: True if the jid is accepted 708 @return: True if the jid is accepted
702 """ 709 """
710 assert isinstance(jid_, jid.JID) # FIXME temporary
703 if self.accept_all(): 711 if self.accept_all():
704 return True 712 return True
705 for group in self._accepted_groups: 713 for group in self._accepted_groups:
706 if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group): 714 if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group):
707 return True 715 return True