changeset 345:2109d7d30ffc

server_side: sort blog post with "published" instead of "timestamp" + display titles in <h1> tags.
author souliane <souliane@mailoo.org>
date Wed, 05 Feb 2014 16:37:31 +0100
parents d7b98e499935
children 82f9e92379b0
files libervia_server/blog.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libervia_server/blog.py	Wed Jan 22 17:07:50 2014 +0100
+++ b/libervia_server/blog.py	Wed Feb 05 16:37:31 2014 +0100
@@ -86,11 +86,15 @@
             <body>
                 <div class='mblog_title'>%(user)s</div>
             """ % {'user': user})
-        #mblog_data.reverse()
+        mblog_data = sorted(mblog_data, key=lambda entry: (-int(entry.get('published', 0))))
         for entry in mblog_data:
-            timestamp = float(entry.get('timestamp', 0))
+            timestamp = float(entry.get('published', 0))
             _datetime = datetime.fromtimestamp(timestamp)
-            body = addURLToText(sanitizeHtml(entry['content'])).encode('utf-8') if 'xhtml' not in entry else entry['xhtml'].encode()
+            getText = lambda key: entry['%s_xhtml' % key].encode() if ('%s_xhtml' % key) in entry else (addURLToText(sanitizeHtml(entry[key])).encode('utf-8') if key in entry else '')
+            body = getText('content')
+            title = getText('title')
+            if title:
+                body = "<h1>%s</h1>\n%s" % (title, body)
             request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span>
                           <span class='mblog_content'>%(content)s</span></div>""" % {
                           'date': _datetime,