Mercurial > libervia-web
annotate libervia_server/blog.py @ 398:462fc3359ee3
browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 11 Mar 2014 12:31:29 +0100 |
parents | 2d782349b88a |
children | 35a43d0dc032 |
rev | line source |
---|---|
10 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
10 | 6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
10 # (at your option) any later version. |
10 | 11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
15 # GNU Affero General Public License for more details. |
10 | 16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
10 | 19 |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
20 from sat.core.i18n import _ |
306
52b1afd7ac3f
server_side: display rich text in blogs (addURLToText is now in sat_frontends/tools/strings)
souliane <souliane@mailoo.org>
parents:
243
diff
changeset
|
21 from sat_frontends.tools.strings import addURLToText |
331
06a48d805547
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
317
diff
changeset
|
22 from libervia_server.html_tools import sanitizeHtml |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
23 from twisted.internet import defer |
10 | 24 from twisted.web import server |
25 from twisted.web.resource import Resource | |
26 from twisted.words.protocols.jabber.jid import JID | |
27 from datetime import datetime | |
317
bbadd490e63c
misc: gather the constants in a single file, as it is done for other frontends
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
28 from constants import Const |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
29 import uuid |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
30 import re |
229
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
31 |
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
32 |
10 | 33 class MicroBlog(Resource): |
34 isLeaf = True | |
35 | |
36 ERROR_TEMPLATE = """ | |
37 <html> | |
38 <head> | |
39 <title>MICROBLOG ERROR</title> | |
40 </head> | |
41 <body> | |
42 <h1 style='text-align: center; color: red;'>%s</h1> | |
43 </body> | |
44 </html> | |
45 """ | |
46 | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
47 def __init__(self, host): |
10 | 48 self.host = host |
49 Resource.__init__(self) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
50 if not host.bridge.isConnected("libervia"): # FIXME: hard coded value for test |
10 | 51 host.bridge.connect("libervia") |
52 | |
53 def render_GET(self, request): | |
54 if not request.postpath: | |
55 return MicroBlog.ERROR_TEMPLATE % "You must indicate a nickname" | |
56 else: | |
57 prof_requested = request.postpath[0] | |
58 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here | |
59 prof_found = self.host.bridge.getProfileName(prof_requested) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
60 if not prof_found or prof_found == 'libervia': |
10 | 61 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" |
62 else: | |
149
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
63 def got_jid(pub_jid_s): |
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
64 pub_jid = JID(pub_jid_s) |
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
65 d2 = defer.Deferred() |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
66 item_id = None |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
67 if len(request.postpath) > 1: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
68 if request.postpath[1] == 'atom.xml': # return the atom feed |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
69 d2.addCallbacks(self.render_atom_feed, self.render_error_blog, [request], None, [request, prof_found], None) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
70 self.host.bridge.getLastGroupBlogsAtom(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
71 return |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
72 try: # check if the given path is a valid UUID |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
73 uuid.UUID(request.postpath[1]) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
74 item_id = request.postpath[1] |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
75 except ValueError: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
76 pass |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
77 d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
78 if item_id: # display one message and its comments |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
79 self.host.bridge.getGroupBlogsWithComments(pub_jid.userhost(), [item_id], 'libervia', d2.callback, d2.errback) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
80 else: # display the last messages without comment |
344
d7b98e499935
server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
81 self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback) |
229
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
82 |
149
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
83 d1 = defer.Deferred() |
317
bbadd490e63c
misc: gather the constants in a single file, as it is done for other frontends
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
84 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', Const.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback)) |
149
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
85 d1.addCallbacks(got_jid) |
10 | 86 |
87 return server.NOT_DONE_YET | |
88 | |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
89 def render_html_blog(self, mblog_data, request, profile): |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
90 """Retrieve the blog banner or other user's specific stuff before actually rendering the static blog |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
91 @param mblog_data: list of microblog data or list of couple (microblog data, list of microblog data) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
92 @param request: HTTP request |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
93 @param profile |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
94 """ |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
95 def check_banner(banner): |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
96 """Regexp from http://answers.oreilly.com/topic/280-how-to-validate-urls-with-regular-expressions/""" |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
97 if re.match(r"^(https?|ftp)://[a-z0-9-]+(\.[a-z0-9-]+)+(/[\w-]+)*/[\w-]+\.(gif|png|jpg)$", banner): |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
98 style = {'banner': banner} |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
99 else: |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
100 style = {} |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
101 self.__render_html_blog(mblog_data, style, request, profile) |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
102 eb = lambda failure: self.render_error_blog(failure, request, profile) |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
103 self.host.bridge.asyncGetParamA('Blog banner', 'Misc', 'value', Const.SERVER_SECURITY_LIMIT, profile, callback=check_banner, errback=eb) |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
104 |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
105 def __render_html_blog(self, mblog_data, style, request, profile): |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
106 """Actually render the static blog. If mblog_data is a list of dict, we are missing |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
107 the comments items so we just display the main items. If mblog_data is a list of couple, |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
108 each couple is associating a main item data with the list of its comments, so we render all. |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
109 @param mblog_data: list of microblog data or list of couple (microblog data, list of microblog data) |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
110 @param style: dict defining the blog's rendering parameters |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
111 @param request: the HTTP request |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
112 @profile |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
113 """ |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
114 if not isinstance(style, dict): |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
115 style = {} |
10 | 116 user = sanitizeHtml(profile).encode('utf-8') |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
117 root_url = '../' * len(request.postpath) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
118 base_url = root_url + 'blog/' + user |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
119 banner = style['banner'].encode('utf-8') if 'banner' in style else '' |
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
120 banner_elt = "<img src='%(banner)s' alt='%(user)s'/>" % {'user': user, 'banner': banner} if banner else user |
10 | 121 request.write(""" |
122 <html> | |
123 <head> | |
175
764ca916e56e
browser side: fixed charset in public blog page
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
124 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
125 <link rel="alternate" type="application/atom+xml" href="%(base)s/atom.xml"/> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
126 <link rel="stylesheet" type="text/css" href="%(root)scss/blog.css" /> |
10 | 127 <title>%(user)s's microblog</title> |
128 </head> | |
129 <body> | |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
130 <div class="mblog_title"><a href="%(base)s">%(banner_elt)s</a></div> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
131 """ % {'base': base_url, |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
132 'root': root_url, |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
133 'user': user, |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
134 'banner_elt': banner_elt}) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
135 mblog_data = [(entry if isinstance(entry, tuple) else (entry, [])) for entry in mblog_data] |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
136 mblog_data = sorted(mblog_data, key=lambda entry: (-float(entry[0].get('published', 0)))) |
10 | 137 for entry in mblog_data: |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
138 self.__render_html_entry(entry[0], base_url, request) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
139 comments = sorted(entry[1], key=lambda entry: (float(entry.get('published', 0)))) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
140 for comment in comments: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
141 self.__render_html_entry(comment, base_url, request) |
10 | 142 request.write('</body></html>') |
143 request.finish() | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
144 |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
145 def __render_html_entry(self, entry, base_url, request): |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
146 """Render one microblog entry. |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
147 @param entry: the microblog entry |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
148 @param base_url: the base url of the blog |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
149 @param request: the HTTP request |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
150 """ |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
151 timestamp = float(entry.get('published', 0)) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
152 datetime_ = datetime.fromtimestamp(timestamp) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
153 is_comment = entry['type'] == 'comment' |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
154 if is_comment: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
155 author = (_("comment from %s") % entry['author']).encode('utf-8') |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
156 item_link = '' |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
157 else: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
158 author = ' ' |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
159 item_link = ("%(base)s/%(item_id)s" % {'base': base_url, 'item_id': entry['id']}).encode('utf-8') |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
160 |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
161 def getText(key): |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
162 if ('%s_xhtml' % key) in entry: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
163 return entry['%s_xhtml' % key].encode('utf-8') |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
164 elif key in entry: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
165 processor = addURLToText if key.startswith('content') else sanitizeHtml |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
166 return processor(entry[key]).encode('utf-8') |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
167 return '' |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
168 |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
169 def addMainItemLink(elem): |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
170 if not item_link or not elem: |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
171 return elem |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
172 return """<a href="%(link)s" class="item_link">%(elem)s</a>""" % {'link': item_link, 'elem': elem} |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
173 |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
174 header = addMainItemLink("""<div class="mblog_header"> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
175 <div class="mblog_metadata"> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
176 <div class="mblog_author">%(author)s</div> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
177 <div class="mblog_timestamp">%(date)s</div> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
178 </div> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
179 </div>""" % {'author': author, 'date': datetime_}) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
180 |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
181 title = addMainItemLink(getText('title')) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
182 body = getText('content') |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
183 if title: # insert the title within the body |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
184 body = """<h1>%(title)s</h1>\n%(body)s""" % {'title': title, 'body': body} |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
185 |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
186 request.write("""<div class="mblog_entry %(extra_style)s"> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
187 %(header)s |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
188 <span class="mblog_content">%(content)s</span> |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
189 </div>""" % |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
190 {'extra_style': 'mblog_comment' if entry['type'] == 'comment' else '', |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
191 'item_link': item_link, |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
192 'header': header, |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
193 'content': body}) |
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
194 |
344
d7b98e499935
server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
195 def render_atom_feed(self, feed, request): |
d7b98e499935
server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
196 request.write(feed.encode('utf-8')) |
d7b98e499935
server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
197 request.finish() |
d7b98e499935
server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
198 |
12
513fe9bd0665
server: fixed wrong parameter number in blog resource
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
199 def render_error_blog(self, error, request, profile): |
10 | 200 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") |
201 request.finish() |