Mercurial > libervia-web
comparison libervia_server/blog.py @ 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 | d7870ab9d1ff |
comparison
equal
deleted
inserted
replaced
344:d7b98e499935 | 345:2109d7d30ffc |
---|---|
84 <title>%(user)s's microblog</title> | 84 <title>%(user)s's microblog</title> |
85 </head> | 85 </head> |
86 <body> | 86 <body> |
87 <div class='mblog_title'>%(user)s</div> | 87 <div class='mblog_title'>%(user)s</div> |
88 """ % {'user': user}) | 88 """ % {'user': user}) |
89 #mblog_data.reverse() | 89 mblog_data = sorted(mblog_data, key=lambda entry: (-int(entry.get('published', 0)))) |
90 for entry in mblog_data: | 90 for entry in mblog_data: |
91 timestamp = float(entry.get('timestamp', 0)) | 91 timestamp = float(entry.get('published', 0)) |
92 _datetime = datetime.fromtimestamp(timestamp) | 92 _datetime = datetime.fromtimestamp(timestamp) |
93 body = addURLToText(sanitizeHtml(entry['content'])).encode('utf-8') if 'xhtml' not in entry else entry['xhtml'].encode() | 93 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 '') |
94 body = getText('content') | |
95 title = getText('title') | |
96 if title: | |
97 body = "<h1>%s</h1>\n%s" % (title, body) | |
94 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> | 98 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> |
95 <span class='mblog_content'>%(content)s</span></div>""" % { | 99 <span class='mblog_content'>%(content)s</span></div>""" % { |
96 'date': _datetime, | 100 'date': _datetime, |
97 'content': body}) | 101 'content': body}) |
98 request.write('</body></html>') | 102 request.write('</body></html>') |