comparison browser_side/panels.py @ 307:44b46db7dfef

browser_side (groupblog): order items using "published" instead of "updated"
author souliane <souliane@mailoo.org>
date Thu, 19 Dec 2013 13:56:47 +0100
parents 52b1afd7ac3f
children 05e264e96a1c
comparison
equal deleted inserted replaced
306:52b1afd7ac3f 307:44b46db7dfef
322 self.id = data['id'] 322 self.id = data['id']
323 self.type = data.get('type', 'main_item') 323 self.type = data.get('type', 'main_item')
324 self.content = data['content'] 324 self.content = data['content']
325 self.xhtml = data.get('xhtml') 325 self.xhtml = data.get('xhtml')
326 self.author = data['author'] 326 self.author = data['author']
327 self.timestamp = float(data.get('timestamp', 0)) # XXX: int doesn't work here 327 self.updated = float(data.get('updated', 0)) # XXX: int doesn't work here
328 try:
329 self.published = float(data['published']) # XXX: int doesn't work here
330 except KeyError:
331 self.published = self.updated
328 self.comments = data.get('comments', False) 332 self.comments = data.get('comments', False)
329 if self.comments: 333 if self.comments:
330 try: 334 try:
331 self.comments_hash = (data['comments_service'], data['comments_node']) 335 self.comments_hash = (data['comments_service'], data['comments_node'])
332 self.comments_service = data['comments_service'] 336 self.comments_service = data['comments_service']
354 SimplePanel.__init__(self) 358 SimplePanel.__init__(self)
355 self._blog_panel = blog_panel 359 self._blog_panel = blog_panel
356 360
357 self.entry = mblog_entry 361 self.entry = mblog_entry
358 self.author = mblog_entry.author 362 self.author = mblog_entry.author
359 self.timestamp = mblog_entry.timestamp 363 self.updated = mblog_entry.updated
360 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) 364 self.published = mblog_entry.published
361 self.comments = mblog_entry.comments 365 self.comments = mblog_entry.comments
362 self.pub_data = (mblog_entry.hash[0], mblog_entry.hash[1], mblog_entry.id) 366 self.pub_data = (mblog_entry.hash[0], mblog_entry.hash[1], mblog_entry.id)
363 367
364 self.editable_content = [mblog_entry.xhtml, const._SYNTAX_XHTML] if mblog_entry.xhtml else [mblog_entry.content, None] 368 self.editable_content = [mblog_entry.xhtml, const._SYNTAX_XHTML] if mblog_entry.xhtml else [mblog_entry.content, None]
365 369
366 self.panel = FlowPanel() 370 self.panel = FlowPanel()
367 self.panel.setStyleName('mb_entry') 371 self.panel.setStyleName('mb_entry')
372 update_text = u" — ✍ " + "<span class='mb_entry_timestamp'>%s</span>" % datetime.fromtimestamp(self.updated)
368 header = HTMLPanel("""<div class='mb_entry_header'> 373 header = HTMLPanel("""<div class='mb_entry_header'>
369 <span class='mb_entry_author'>%(author)s</span> 374 <span class='mb_entry_author'>%(author)s</span> on
370 <span>on</span> 375 <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s
371 <span class='mb_entry_timestamp'>%(timestamp)s</span> 376 </div>""" % {'author': html_sanitize(self.author),
372 </div>""" % {'author': html_sanitize(self.author), 'timestamp': _datetime}) 377 'published': datetime.fromtimestamp(self.published),
378 'updated': update_text if self.published != self.updated else ''
379 }
380 )
381
382
383
373 self.panel.add(header) 384 self.panel.add(header)
374 385
375 if self.author == blog_panel.host.whoami.bare: 386 if self.author == blog_panel.host.whoami.bare:
376 entry_delete_update = VerticalPanel() 387 entry_delete_update = VerticalPanel()
377 entry_delete_update.setStyleName('mb_entry_delete_update') 388 entry_delete_update.setStyleName('mb_entry_delete_update')
450 new_text = self.editbox.getText().strip() 461 new_text = self.editbox.getText().strip()
451 self.edit_panel = self.editbox = None 462 self.edit_panel = self.editbox = None
452 if cancel or new_text == self.editable_content[0] or new_text == "": 463 if cancel or new_text == self.editable_content[0] or new_text == "":
453 return 464 return
454 self.editable_content[0] = new_text 465 self.editable_content[0] = new_text
455 self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, new_text, 466 extra = {'published': str(self.published)}
456 {'rich': new_text} if self.entry.xhtml else {}) 467 if self.entry.xhtml:
468 extra.update({'rich': new_text})
469 self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, new_text, extra)
457 470
458 def _update(self): 471 def _update(self):
459 """Change the bubble to an editbox""" 472 """Change the bubble to an editbox"""
460 if self.editbox and self.editbox.getVisible(): 473 if self.editbox and self.editbox.getVisible():
461 return 474 return
641 for child in vpanel.children: 654 for child in vpanel.children:
642 if not isinstance(child, MicroblogEntry): 655 if not isinstance(child, MicroblogEntry):
643 idx += 1 656 idx += 1
644 continue 657 continue
645 if reverse: 658 if reverse:
646 if child.timestamp < entry.timestamp: 659 if child.published < entry.published:
647 break 660 break
648 else: 661 else:
649 if child.timestamp > entry.timestamp: 662 if child.published > entry.published:
650 break 663 break
651 idx += 1 664 idx += 1
652 665
653 vpanel.insert(entry, idx) 666 vpanel.insert(entry, idx)
654 667