Mercurial > libervia-web
comparison server_side/blog.py @ 306:52b1afd7ac3f
server_side: display rich text in blogs (addURLToText is now in sat_frontends/tools/strings)
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 18 Dec 2013 15:39:13 +0100 |
parents | 63e9b680d3e7 |
children | bbadd490e63c |
comparison
equal
deleted
inserted
replaced
305:d002cd631271 | 306:52b1afd7ac3f |
---|---|
17 | 17 |
18 You should have received a copy of the GNU Affero General Public License | 18 You should have received a copy of the GNU Affero General Public License |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | 20 """ |
21 | 21 |
22 from sat_frontends.tools.strings import addURLToText | |
22 from server_side.html_tools import sanitizeHtml | 23 from server_side.html_tools import sanitizeHtml |
23 from twisted.internet import reactor, defer | 24 from twisted.internet import reactor, defer |
24 from twisted.web import server | 25 from twisted.web import server |
25 from twisted.web.resource import Resource | 26 from twisted.web.resource import Resource |
26 from twisted.words.protocols.jabber.jid import JID | 27 from twisted.words.protocols.jabber.jid import JID |
86 """ % {'user': user}) | 87 """ % {'user': user}) |
87 #mblog_data.reverse() | 88 #mblog_data.reverse() |
88 for entry in mblog_data: | 89 for entry in mblog_data: |
89 timestamp = float(entry.get('timestamp', 0)) | 90 timestamp = float(entry.get('timestamp', 0)) |
90 _datetime = datetime.fromtimestamp(timestamp) | 91 _datetime = datetime.fromtimestamp(timestamp) |
92 body = addURLToText(sanitizeHtml(entry['content'])).encode('utf-8') if 'xhtml' not in entry else entry['xhtml'].encode() | |
91 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> | 93 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> |
92 <span class='mblog_content'>%(content)s</span></div>""" % { | 94 <span class='mblog_content'>%(content)s</span></div>""" % { |
93 'date': _datetime, | 95 'date': _datetime, |
94 'content': sanitizeHtml(entry['content']).encode('utf-8')}) | 96 'content': body}) |
95 request.write('</body></html>') | 97 request.write('</body></html>') |
96 request.finish() | 98 request.finish() |
97 | 99 |
98 def render_error_blog(self, error, request, profile): | 100 def render_error_blog(self, error, request, profile): |
99 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") | 101 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") |