comparison src/browser/sat_browser/blog.py @ 809:c500bdb0c216

browser (blog): fixed comments ordering
author Goffi <goffi@goffi.org>
date Fri, 18 Dec 2015 19:37:13 +0100
parents 103f0f01ba54
children f8a7a046ff9c
comparison
equal deleted inserted replaced
808:9e1e6d5241f9 809:c500bdb0c216
331 def _onCommentClick(self): 331 def _onCommentClick(self):
332 """Add an empty entry for a new comment""" 332 """Add an empty entry for a new comment"""
333 if self._current_comment is None: 333 if self._current_comment is None:
334 if not self.item.comments_service or not self.item.comments_node: 334 if not self.item.comments_service or not self.item.comments_node:
335 log.warning("Invalid service and node for comments, can't create a comment") 335 log.warning("Invalid service and node for comments, can't create a comment")
336 self._current_comment = self.addEntry(editable=True, service=self.item.comments_service, node=self.item.comments_node) 336 self._current_comment = self.addEntry(editable=True, service=self.item.comments_service, node=self.item.comments_node, edit_entry=True)
337 self.blog.setSelectedEntry(self._current_comment, True) 337 self.blog.setSelectedEntry(self._current_comment, True)
338 338
339 def _changeMode(self, original_content, text): 339 def _changeMode(self, original_content, text):
340 self.mode = C.ENTRY_MODE_RICH if self.mode == C.ENTRY_MODE_TEXT else C.ENTRY_MODE_TEXT 340 self.mode = C.ENTRY_MODE_RICH if self.mode == C.ENTRY_MODE_TEXT else C.ENTRY_MODE_TEXT
341 if self.mode in ENTRY_RICH and not text: 341 if self.mode in ENTRY_RICH and not text:
373 callback=lambda converted: self._changeMode(original_content, converted)) 373 callback=lambda converted: self._changeMode(original_content, converted))
374 374
375 def update(self, entry=None): 375 def update(self, entry=None):
376 """Update comments""" 376 """Update comments"""
377 self._createCommentsPanel() 377 self._createCommentsPanel()
378 self.entries.sort(key=lambda entry: entry.item.published, reverse=True) 378 self.entries.sort(key=lambda entry: entry.item.published)
379 for idx, entry in enumerate(self.entries): 379 # we put edit_entry at the end
380 edit_entry = [] if self.edit_entry is None else [self.edit_entry]
381 for idx, entry in enumerate(self.entries + edit_entry):
380 if not entry.displayed: 382 if not entry.displayed:
381 self.comments_panel.insert(entry, idx) 383 self.comments_panel.insert(entry, idx)
382 entry.displayed = True 384 entry.displayed = True
383 385
384 def delete(self): 386 def delete(self):
415 self.vpanel = VerticalPanel() 417 self.vpanel = VerticalPanel()
416 self.vpanel.setStyleName('microblogPanel') 418 self.vpanel.setStyleName('microblogPanel')
417 self.setWidget(self.vpanel) 419 self.setWidget(self.vpanel)
418 if ((self._targets_type == C.ALL and self.host.mblog_available) or 420 if ((self._targets_type == C.ALL and self.host.mblog_available) or
419 (self._targets_type == C.GROUP and self.host.groupblog_available)): 421 (self._targets_type == C.GROUP and self.host.groupblog_available)):
420 self.addEntry(editable=True, first=True) 422 self.addEntry(editable=True, edit_entry=True)
421 423
422 self.getAll() 424 self.getAll()
423 425
424 # self.footer = HTML('', StyleName='microblogPanel_footer') 426 # self.footer = HTML('', StyleName='microblogPanel_footer')
425 # self.footer.waiting = False 427 # self.footer.waiting = False
433 435
434 def update(self): 436 def update(self):
435 self.entries.sort(key=lambda entry: entry.item.published, reverse=True) 437 self.entries.sort(key=lambda entry: entry.item.published, reverse=True)
436 438
437 start_idx = 0 439 start_idx = 0
438 if self._first_entry is not None: 440 if self.edit_entry is not None:
439 start_idx = 1 441 start_idx = 1
440 if not self._first_entry.displayed: 442 if not self.edit_entry.displayed:
441 self.vpanel.insert(self._first_entry, 0) 443 self.vpanel.insert(self.edit_entry, 0)
442 self._first_entry.displayed = True 444 self.edit_entry.displayed = True
443 445
444 # XXX: enumerate is buggued in pyjamas (start is not used) 446 # XXX: enumerate is buggued in pyjamas (start is not used)
445 # we have to use idx 447 # we have to use idx
446 idx = start_idx 448 idx = start_idx
447 for entry in self.entries: 449 for entry in self.entries: