diff 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
line wrap: on
line diff
--- a/browser_side/panels.py	Wed Dec 18 15:39:13 2013 +0100
+++ b/browser_side/panels.py	Thu Dec 19 13:56:47 2013 +0100
@@ -324,7 +324,11 @@
         self.content = data['content']
         self.xhtml = data.get('xhtml')
         self.author = data['author']
-        self.timestamp = float(data.get('timestamp', 0))  # XXX: int doesn't work here
+        self.updated = float(data.get('updated', 0))  # XXX: int doesn't work here
+        try:
+            self.published = float(data['published'])  # XXX: int doesn't work here
+        except KeyError:
+            self.published = self.updated
         self.comments = data.get('comments', False)
         if self.comments:
             try:
@@ -356,8 +360,8 @@
 
         self.entry = mblog_entry
         self.author = mblog_entry.author
-        self.timestamp = mblog_entry.timestamp
-        _datetime = datetime.fromtimestamp(mblog_entry.timestamp)
+        self.updated = mblog_entry.updated
+        self.published = mblog_entry.published
         self.comments = mblog_entry.comments
         self.pub_data = (mblog_entry.hash[0], mblog_entry.hash[1], mblog_entry.id)
 
@@ -365,11 +369,18 @@
 
         self.panel = FlowPanel()
         self.panel.setStyleName('mb_entry')
+        update_text = u" — ✍ " + "<span class='mb_entry_timestamp'>%s</span>" % datetime.fromtimestamp(self.updated)
         header = HTMLPanel("""<div class='mb_entry_header'>
-                                  <span class='mb_entry_author'>%(author)s</span>
-                                  <span>on</span>
-                                  <span class='mb_entry_timestamp'>%(timestamp)s</span>
-                              </div>""" % {'author': html_sanitize(self.author), 'timestamp': _datetime})
+                                  <span class='mb_entry_author'>%(author)s</span> on
+                                  <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s
+                              </div>""" % {'author': html_sanitize(self.author),
+                                           'published': datetime.fromtimestamp(self.published),
+                                           'updated': update_text if self.published != self.updated else ''
+                                           }
+                          )
+
+
+
         self.panel.add(header)
 
         if self.author == blog_panel.host.whoami.bare:
@@ -452,8 +463,10 @@
         if cancel or new_text == self.editable_content[0] or new_text == "":
             return
         self.editable_content[0] = new_text
-        self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, new_text,
-                                          {'rich': new_text} if self.entry.xhtml else {})
+        extra = {'published': str(self.published)}
+        if self.entry.xhtml:
+            extra.update({'rich': new_text})
+        self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, new_text, extra)
 
     def _update(self):
         """Change the bubble to an editbox"""
@@ -643,10 +656,10 @@
                 idx += 1
                 continue
             if reverse:
-                if child.timestamp < entry.timestamp:
+                if child.published < entry.published:
                     break
             else:
-                if child.timestamp > entry.timestamp:
+                if child.published > entry.published:
                     break
             idx += 1