comparison browser_side/panels.py @ 119:a8d11fdea090

microblog avatar update
author Goffi <goffi@goffi.org>
date Wed, 06 Jul 2011 03:03:07 +0200
parents c64b00f31461
children 054b7b3424a3
comparison
equal deleted inserted replaced
118:a2a21e0290dc 119:a8d11fdea090
472 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this 472 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
473 return AutoCompleteTextBox.complete(self)""" 473 return AutoCompleteTextBox.complete(self)"""
474 474
475 class MicroblogEntry(SimplePanel): 475 class MicroblogEntry(SimplePanel):
476 476
477 def __init__(self, mblog_entry): 477 def __init__(self, host, mblog_entry):
478 SimplePanel.__init__(self) 478 SimplePanel.__init__(self)
479 479
480 self.author = mblog_entry.author
480 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) 481 _datetime = datetime.fromtimestamp(mblog_entry.timestamp)
481 482
482 panel = HTMLPanel(""" 483 self.panel = HTMLPanel("""
483 <div class="mb_entry_avatar"><img src="%(avatar)s" alt="%(author)s" /></div> 484 <div class="mb_entry_avatar" id='id_avatar'></div>
484 <div class="mb_entry_dialog"> 485 <div class="mb_entry_dialog">
485 <p class="bubble">%(body)s</p> 486 <p class="bubble">%(body)s</p>
486 </div> 487 </div>
487 <div class='mb_entry_timestamp'>%(timestamp)s</div> 488 <div class='mb_entry_timestamp'>%(timestamp)s</div>
488 """ % {"avatar": "/media/misc/empty_avatar", 489 """ % {"author": html_sanitize(self.author),
489 "author": html_sanitize(mblog_entry.author),
490 "timestamp": _datetime, 490 "timestamp": _datetime,
491 "body": html_sanitize(mblog_entry.content) 491 "body": html_sanitize(mblog_entry.content)
492 }) 492 })
493 panel.setStyleName('mb_entry') 493 self.avatar = Image(host.getAvatar(self.author))
494 self.add(panel) 494 self.panel.add(self.avatar, "id_avatar")
495 self.panel.setStyleName('mb_entry')
496 self.add(self.panel)
497
498 def updateAvatar(self, new_avatar):
499 """Change the avatar of the entry
500 @param new_avatar: path to the new image"""
501 self.avatar.setUrl(new_avatar)
502
495 503
496 class MicroblogPanel(LiberviaWidget): 504 class MicroblogPanel(LiberviaWidget):
497 505
498 def __init__(self, host, title='', accept_all=False): 506 def __init__(self, host, title='', accept_all=False):
499 """Panel used to show microblog 507 """Panel used to show microblog
515 @param id: unique id of the entry 523 @param id: unique id of the entry
516 @param author: who wrote the entry 524 @param author: who wrote the entry
517 @param date: when the entry was written""" 525 @param date: when the entry was written"""
518 if mblog_entry.id in self.entries: 526 if mblog_entry.id in self.entries:
519 return 527 return
520 _entry = MicroblogEntry(mblog_entry) 528 _entry = MicroblogEntry(self.host, mblog_entry)
521 self.entries[mblog_entry.id] = _entry 529 self.entries[mblog_entry.id] = _entry
522 self.vpanel.insert(_entry,0) 530 self.vpanel.insert(_entry,0)
531
532 def updateValue(self, type, jid, value):
533 """Update a jid value in entries
534 @param type: one of 'avatar', 'nick'
535 @param jid: jid concerned
536 @param value: new value"""
537 if type=='avatar':
538 for entry in self.entries.values():
539 if entry.author == jid:
540 entry.updateAvatar(value)
523 541
524 def setAcceptedGroup(self, group): 542 def setAcceptedGroup(self, group):
525 """Set the group which can be displayed in this panel 543 """Set the group which can be displayed in this panel
526 @param group: string of the group, or list of string 544 @param group: string of the group, or list of string
527 """ 545 """