comparison browser_side/panels.py @ 58:4fa3d57f72f8

browser side: microblog entries caching
author Goffi <goffi@goffi.org>
date Sun, 29 May 2011 17:57:02 +0200
parents e552a67b933d
children 12e889a683ce
comparison
equal deleted inserted replaced
57:e552a67b933d 58:4fa3d57f72f8
110 You can contact the author at <a href="mailto:goffi@goffi.org">goffi@goffi.org</a><br /> 110 You can contact the author at <a href="mailto:goffi@goffi.org">goffi@goffi.org</a><br />
111 Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br /> 111 Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br />
112 Project page: <a href="http://wiki.goffi.org/wiki/Salut_à_Toi"target="_blank">http://wiki.goffi.org/wiki/Salut_à_Toi</a><br /> 112 Project page: <a href="http://wiki.goffi.org/wiki/Salut_à_Toi"target="_blank">http://wiki.goffi.org/wiki/Salut_à_Toi</a><br />
113 <br /> 113 <br />
114 Any help welcome :) 114 Any help welcome :)
115 <p style='font-size:x-small;text-align:center'>This project is dedicated to Roger Poisson</p> 115 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p>
116 """) 116 """)
117 _dialog = dialog.GenericDialog("About", _about) 117 _dialog = dialog.GenericDialog("About", _about)
118 _dialog.show() 118 _dialog.show()
119 119
120 #Contact menu 120 #Contact menu
274 item_type = None 274 item_type = None
275 DOM.eventPreventDefault(event) 275 DOM.eventPreventDefault(event)
276 if item_type=="GROUP": 276 if item_type=="GROUP":
277 _new_panel = MicroblogPanel(self.host, item) 277 _new_panel = MicroblogPanel(self.host, item)
278 _new_panel.setAcceptedGroup(item) 278 _new_panel.setAcceptedGroup(item)
279 self.host.FillMicroblogPanel(_new_panel)
279 elif item_type=="CONTACT": 280 elif item_type=="CONTACT":
280 _contact = JID(item) 281 _contact = JID(item)
281 _new_panel = ChatPanel(self.host, _contact) 282 _new_panel = ChatPanel(self.host, _contact)
282 _new_panel.historyPrint() 283 _new_panel.historyPrint()
283 elif item_type=="CONTACT_TITLE": 284 elif item_type=="CONTACT_TITLE":
284 _new_panel = MicroblogPanel(self.host, accept_all=True) 285 _new_panel = MicroblogPanel(self.host, accept_all=True)
286 self.host.FillMicroblogPanel(_new_panel)
285 else: 287 else:
286 return 288 return
287 self.host.mpanels.remove(self) 289 self.host.mpanels.remove(self)
288 self.host.mpanels.append(_new_panel) 290 self.host.mpanels.append(_new_panel)
289 grid = self.getParent() 291 grid = self.getParent()
463 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this 465 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
464 return AutoCompleteTextBox.complete(self) 466 return AutoCompleteTextBox.complete(self)
465 467
466 class MicroblogEntry(SimplePanel): 468 class MicroblogEntry(SimplePanel):
467 469
468 def __init__(self, body, author, timestamp): 470 def __init__(self, mblog_entry):
469 SimplePanel.__init__(self) 471 SimplePanel.__init__(self)
470 472
471 _datetime = datetime.fromtimestamp(timestamp) 473 _datetime = datetime.fromtimestamp(mblog_entry.timestamp)
472 474
473 panel = HTMLPanel("<div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><div class='mb_entry_body'>%(body)s</div>" % 475 panel = HTMLPanel("<div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><div class='mb_entry_body'>%(body)s</div>" %
474 {"author": html_sanitize(author), 476 {"author": html_sanitize(mblog_entry.author),
475 "timestamp": _datetime, 477 "timestamp": _datetime,
476 "body": html_sanitize(body)} 478 "body": html_sanitize(mblog_entry.content)}
477 ) 479 )
478 panel.setStyleName('microblogEntry') 480 panel.setStyleName('microblogEntry')
479 self.add(panel) 481 self.add(panel)
480 482
481 class MicroblogPanel(DropCell, ScrollPanelWrapper): 483 class MicroblogPanel(DropCell, ScrollPanelWrapper):
488 DropCell.__init__(self) 490 DropCell.__init__(self)
489 self.host = host 491 self.host = host
490 self.accept_all = accept_all 492 self.accept_all = accept_all
491 title=html_sanitize(title) 493 title=html_sanitize(title)
492 self.accepted_groups = [] 494 self.accepted_groups = []
495 self.entries = {}
493 _class = ['mb_panel_header'] 496 _class = ['mb_panel_header']
494 if title == '&nbsp;': 497 if title == '&nbsp;':
495 _class.append('empty_header') 498 _class.append('empty_header')
496 self.vpanel = VerticalPanel() 499 self.vpanel = VerticalPanel()
497 self.vpanel.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title))) 500 self.vpanel.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title)))
498 self.vpanel.setWidth('100%') 501 self.vpanel.setWidth('100%')
499 self.setStyleName('microblogPanel') 502 self.setStyleName('microblogPanel')
500 self.setWidget(self.vpanel) 503 self.setWidget(self.vpanel)
501 504
502 def addEntry(self, text, author=None, timestamp=None): 505 def addEntry(self, mblog_entry):
503 """Add an entry to the panel 506 """Add an entry to the panel
504 @param text: main text of the entry 507 @param text: main text of the entry
508 @param id: unique id of the entry
505 @param author: who wrote the entry 509 @param author: who wrote the entry
506 @param date: when the entry was written""" 510 @param date: when the entry was written"""
507 _entry = MicroblogEntry(text, author, timestamp) 511 if mblog_entry.id in self.entries:
512 return
513 _entry = MicroblogEntry(mblog_entry)
514 self.entries[mblog_entry.id] = _entry
508 self.vpanel.insert(_entry,1) 515 self.vpanel.insert(_entry,1)
509 516
510 def setAcceptedGroup(self, group): 517 def setAcceptedGroup(self, group):
511 """Set the group which can be displayed in this panel 518 """Set the group which can be displayed in this panel
512 @param group: string of the group, or list of string 519 @param group: string of the group, or list of string