annotate src/server/blog.py @ 679:a90cc8fc9605

merged branch frontends_multi_profiles
author Goffi <goffi@goffi.org>
date Wed, 18 Mar 2015 16:15:18 +0100
parents c8cca1a373dd 7af8f4ab3675
children 9877607c719a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org>
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
19
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
20 from sat.core.i18n import _, D_
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
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
22 from sat.core.log import getLogger
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
23 log = getLogger(__name__)
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 446
diff changeset
24
388
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
25 from twisted.internet import defer
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.web import server
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.web.resource import Resource
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.words.protocols.jabber.jid import JID
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from datetime import datetime
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
30 import uuid
388
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
31 import re
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
32 import os
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 228
diff changeset
33
588
c8cca1a373dd server_side: static blog: convert \n in raw text message to <br/>
souliane <souliane@mailoo.org>
parents: 586
diff changeset
34 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 446
diff changeset
35 from libervia.server.constants import Const as C
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 446
diff changeset
36
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 228
diff changeset
37
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class MicroBlog(Resource):
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
39 isLeaf = True
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
40
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
41 ERROR_TEMPLATE = """
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
42 <html>
409
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
43 <head profile="http://www.w3.org/2005/10/profile">
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
44 <link rel="icon" type="image/png" href="%(root)ssat_logo_16.png">
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
45 <title>MICROBLOG ERROR</title>
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
46 </head>
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
47 <body>
409
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
48 <h1 style='text-align: center; color: red;'>%(message)s</h1>
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
49 </body>
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
50 </html>
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
51 """
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
52
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 229
diff changeset
53 def __init__(self, host):
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.host = host
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
55 Resource.__init__(self)
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
56 self.host.bridge.register('entityDataUpdated', self.entityDataUpdatedCb)
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
57 self.host.bridge.register('actionResult', self.actionResultCb) # FIXME: actionResult is to be removed
484
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
58 self.avatars_cache = {}
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
59 self.waiting_deferreds = {}
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
60
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
61 def entityDataUpdatedCb(self, entity_jid_s, key, value, dummy):
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
62 """Retrieve the avatar we've been waiting for and fires the callback
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
63 for self.getAvatar to return.
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
64
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
65 @param entity_jid_s (str): JID of the contact
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
66 @param key (str): entity data key
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
67 @param value (str): entity data value
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
68 @param dummy (str): that would be C.SERVICE_PROFILE
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
69 """
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
70 if key != 'avatar':
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
71 return
487
e588335b6aa8 browser and server side: force lower case for the profile name at new account creation + fixes CSS for textarea
souliane <souliane@mailoo.org>
parents: 484
diff changeset
72 entity_jid_s = entity_jid_s.lower()
484
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
73 log.debug(_("Received a new avatar for entity %s") % entity_jid_s)
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
74 avatar = C.AVATARS_DIR + value
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
75 self.avatars_cache[entity_jid_s] = avatar
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
76 try:
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
77 self.waiting_deferreds[entity_jid_s][1].callback(avatar)
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
78 del self.waiting_deferreds[entity_jid_s]
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
79 except KeyError:
484
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
80 pass
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
81
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
82 def actionResultCb(self, answer_type, action_id, data, dummy):
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
83 """Fires the callback for self.getAvatar to return
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
84
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
85 @param answer_type (str): 'SUPPRESS' or another value that we would ignore
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
86 @param action_id (str): the request ID
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
87 @param data (dict): ignored
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
88 @param dummy (str): that would be C.SERVICE_PROFILE
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
89 """
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
90 # FIXME: actionResult is to be removed. For now we use it to get notified
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
91 # when the requested vCard hasn't been found. Replace with the new system.
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
92 if answer_type != 'SUPPRESS':
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
93 return
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
94 try:
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
95 entity_jid_s = [key for (key, value) in self.waiting_deferreds.items() if value[0] == action_id][0]
484
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
96 except IndexError: # impossible to guess the entity
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
97 return
484
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
98 log.debug(_("Using default avatar for entity %s") % entity_jid_s)
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 487
diff changeset
99 self.avatars_cache[entity_jid_s] = C.DEFAULT_AVATAR_URL
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 487
diff changeset
100 self.waiting_deferreds[entity_jid_s][1].callback(C.DEFAULT_AVATAR_URL)
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
101 del self.waiting_deferreds[entity_jid_s]
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
102
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
103 def getAvatar(self, profile):
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
104 """Get the avatar of the given profile
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
105
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 487
diff changeset
106 @param profile(unicode): %(doc_profile)s
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
107 @return: deferred avatar path, relative to the server's root
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
108 """
487
e588335b6aa8 browser and server side: force lower case for the profile name at new account creation + fixes CSS for textarea
souliane <souliane@mailoo.org>
parents: 484
diff changeset
109 jid_s = (profile + '@' + self.host.bridge.getNewAccountDomain()).lower()
484
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
110 if jid_s in self.avatars_cache:
ae86b32b959c server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents: 483
diff changeset
111 return defer.succeed(self.avatars_cache[jid_s])
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
112 # FIXME: request_id is no more need when actionResult is removed
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
113 request_id = self.host.bridge.getCard(jid_s, C.SERVICE_PROFILE)
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
114 self.waiting_deferreds[jid_s] = (request_id, defer.Deferred())
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
115 return self.waiting_deferreds[jid_s][1]
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
116
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def render_GET(self, request):
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
118 if not request.postpath:
409
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
119 return MicroBlog.ERROR_TEMPLATE % {'root': '',
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
120 'message': "You must indicate a nickname"}
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
121 else:
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
122 prof_requested = request.postpath[0]
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
123 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
124 prof_found = self.host.bridge.getProfileName(prof_requested)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 454
diff changeset
125 if not prof_found or prof_found == C.SERVICE_PROFILE:
409
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
126 return MicroBlog.ERROR_TEMPLATE % {'root': '../' * len(request.postpath),
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
127 'message': "Invalid nickname"}
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
128 else:
149
f78761e1be8e server side: fixed public microblog
Goffi <goffi@goffi.org>
parents: 131
diff changeset
129 def got_jid(pub_jid_s):
f78761e1be8e server side: fixed public microblog
Goffi <goffi@goffi.org>
parents: 131
diff changeset
130 pub_jid = JID(pub_jid_s)
f78761e1be8e server side: fixed public microblog
Goffi <goffi@goffi.org>
parents: 131
diff changeset
131 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
132 item_id = None
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
133 atom = None
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
134 rsm_ = {}
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
135
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
136 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
137 if request.postpath[1] == 'atom.xml': # return the atom feed
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
138 atom = True
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
139 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
140 try: # check if the given path is a valid UUID
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
141 uuid.UUID(request.postpath[1])
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
142 item_id = request.postpath[1]
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
143 except ValueError:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
144 pass
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
145
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
146 # retrieve RSM request data from URL parameters
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
147 try:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
148 max_items = int(request.args['max'][0])
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
149 except (ValueError, KeyError):
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
150 max_items = C.RSM_MAX_ITEMS if item_id else C.RSM_MAX_COMMENTS
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
151 rsm_['max'] = unicode(max_items)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
152 try:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
153 rsm_['index'] = request.args['index'][0]
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
154 except (ValueError, KeyError):
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
155 try:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
156 rsm_['before'] = request.args['before'][0]
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
157 except KeyError:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
158 try:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
159 rsm_['after'] = request.args['after'][0]
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
160 except KeyError:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
161 pass
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
162
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
163 if atom is not None:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
164 d2.addCallbacks(self.render_atom_feed, self.render_error_blog, [request], None, [request, prof_found], None)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
165 self.host.bridge.getGroupBlogsAtom(pub_jid.userhost(), rsm_, C.SERVICE_PROFILE, d2.callback, d2.errback)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
166 return
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
167
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
168 d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None)
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
169 if item_id:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
170 if max_items > 0: # display one message and its comments
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
171 self.host.bridge.getGroupBlogsWithComments(pub_jid.userhost(), [item_id], {}, max_items, C.SERVICE_PROFILE, d2.callback, d2.errback)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
172 else: # display one message, count its comments
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
173 self.host.bridge.getGroupBlogs(pub_jid.userhost(), [item_id], {}, True, C.SERVICE_PROFILE, d2.callback, d2.errback)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
174 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
175 if max_items == 1: # display one message and its comments
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
176 self.host.bridge.getGroupBlogsWithComments(pub_jid.userhost(), [], rsm_, C.RSM_MAX_COMMENTS, C.SERVICE_PROFILE, d2.callback, d2.errback)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
177 else: # display the last messages, count their comments
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
178 self.host.bridge.getGroupBlogs(pub_jid.userhost(), [], rsm_, True, C.SERVICE_PROFILE, d2.callback, d2.errback)
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 228
diff changeset
179
149
f78761e1be8e server side: fixed public microblog
Goffi <goffi@goffi.org>
parents: 131
diff changeset
180 d1 = defer.Deferred()
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 409
diff changeset
181 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', C.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
182 d1.addCallbacks(got_jid)
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
183
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
184 return server.NOT_DONE_YET
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
185
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
186 def render_html_blog(self, mblog_data, request, profile):
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
187 """Retrieve the user parameters before actually rendering the static blog
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
188
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
189 @param mblog_data (list): couple (list, dict) with:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
190 - a list of microblog data, or a list of couple containing:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
191 - microblog data (main item)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
192 - couple (comments data, RSM response data for the comments)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
193 - RSM response data for the main items
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
194 @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
195 @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
196 """
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
197 d_list = []
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
198 options = {}
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
199
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
200 def getCallback(param_name):
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
201 d = defer.Deferred()
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
202 d.addCallback(lambda value: options.update({param_name: value}))
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
203 d_list.append(d)
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
204 return d.callback
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
205
388
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
206 eb = lambda failure: self.render_error_blog(failure, request, profile)
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
207
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
208 self.getAvatar(profile).addCallbacks(getCallback('avatar'), eb)
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
209 for param_name in (C.STATIC_BLOG_PARAM_TITLE, C.STATIC_BLOG_PARAM_BANNER, C.STATIC_BLOG_PARAM_KEYWORDS, C.STATIC_BLOG_PARAM_DESCRIPTION):
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
210 self.host.bridge.asyncGetParamA(param_name, C.STATIC_BLOG_KEY, 'value', C.SERVER_SECURITY_LIMIT, profile, callback=getCallback(param_name), errback=eb)
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
211
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
212 cb = lambda dummy: self.__render_html_blog(mblog_data, options, request, profile)
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
213 defer.DeferredList(d_list).addCallback(cb)
388
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
214
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
215 def __render_html_blog(self, mblog_data, options, request, profile):
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
216 """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
217 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
218 each couple is associating a main item data with the list of its comments, so we render all.
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
219
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
220 @param mblog_data (list): couple (list, dict) with:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
221 - a list of microblog data, or a list of couple containing:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
222 - microblog data (main item)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
223 - couple (comments data, RSM response data for the comments)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
224 - RSM response data for the main items
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
225 @param options: dict defining the blog's parameters
388
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
226 @param request: the HTTP request
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
227 @profile
893451e35686 server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents: 375
diff changeset
228 """
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
229 if not isinstance(options, dict):
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
230 options = {}
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
231 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
232 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
233 base_url = root_url + 'blog/' + user
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
234
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
235 def getOption(key):
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
236 return sanitizeHtml(options[key]).encode('utf-8') if key in options else ''
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
237
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
238 def getImageOption(key, alt):
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
239 """regexp from http://answers.oreilly.com/topic/280-how-to-validate-urls-with-regular-expressions/"""
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
240 url = options[key].encode('utf-8') if key in options else ''
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
241 regexp = r"^(https?|ftp)://[a-z0-9-]+(\.[a-z0-9-]+)+(/[\w-]+)*/[\w-]+\.(gif|png|jpg)$"
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
242 return "<img src='%(url)s' alt='%(alt)s'/>" % {'alt': alt, 'url': url} if re.match(regexp, url) else alt
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
243
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
244 request.write("""
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
245 <html>
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
246 <head>
175
764ca916e56e browser side: fixed charset in public blog page
Goffi <goffi@goffi.org>
parents: 165
diff changeset
247 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
248 <meta name="keywords" content="%(keywords)s">
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
249 <meta name="description" content="%(description)s">
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
250 <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
251 <link rel="stylesheet" type="text/css" href="%(root)scss/blog.css" />
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
252 <link rel="icon" type="image/png" href="%(favicon)s">
441
63017904c4d4 server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents: 436
diff changeset
253 <title>%(title)s</title>
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
254 </head>
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
255 <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
256 <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
257 """ % {'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
258 '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
259 'user': user,
483
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
260 'keywords': getOption(C.STATIC_BLOG_PARAM_KEYWORDS),
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
261 'description': getOption(C.STATIC_BLOG_PARAM_DESCRIPTION),
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
262 'title': getOption(C.STATIC_BLOG_PARAM_TITLE) or "%s's microblog" % user,
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
263 'favicon': os.path.normpath(root_url + getOption('avatar')),
0bbbef1d53a8 server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents: 481
diff changeset
264 'banner_elt': getImageOption(C.STATIC_BLOG_PARAM_BANNER, getOption(C.STATIC_BLOG_PARAM_TITLE) or user)})
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
265 mblog_data, main_rsm = mblog_data
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
266 display_single = len(mblog_data) == 1
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
267
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
268 # build the navigation links
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
269 count = int(main_rsm['count']) if 'count' in main_rsm else 0
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
270 if count > 0:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
271 index = int(main_rsm['index'])
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
272 if index > 0:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
273 before_link = ("%(base)s?before=%(item_id)s" % {'base': base_url, 'item_id': main_rsm['first']}).encode('utf-8')
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
274 if display_single:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
275 before_link += '&max=1'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
276 tmp_text = D_("Later message")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
277 class_ = 'later_message'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
278 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
279 tmp_text = D_("Later messages")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
280 class_ = 'later_messages'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
281 before_tag = """<a href="%(link)s" class="%(class)s">%(text)s</a>""" % {'link': before_link, 'class': class_, 'text': tmp_text}
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
282 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
283 before_tag = None
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
284 if index + len(mblog_data) < count:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
285 after_link = ("%(base)s?after=%(item_id)s" % {'base': base_url, 'item_id': main_rsm['last']}).encode('utf-8')
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
286 if display_single:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
287 after_link += '&max=1'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
288 text = D_("Older message")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
289 class_ = 'older_message'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
290 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
291 text = D_("Older messages")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
292 class_ = 'older_messages'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
293 after_tag = """<a href="%(link)s" class="%(class)s">%(text)s</a>""" % {'link': after_link, 'class': class_, 'text': text}
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
294 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
295 after_tag = None
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
296
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
297 # display navigation header
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
298 request.write("""<div class="header">""")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
299 if before_tag:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
300 request.write(before_tag)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
301 request.write("&nbsp;")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
302 if display_single and after_tag:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
303 request.write(after_tag)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
304 request.write("""</div>""")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
305
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
306 mblog_data = [(entry if isinstance(entry, tuple) else (entry, ([], {}))) for entry in mblog_data]
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
307 mblog_data = sorted(mblog_data, key=lambda entry: (-float(entry[0].get('updated', 0))))
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
308 for main_data, comments_data in mblog_data:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
309 self.__render_html_entry(main_data, base_url, request)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
310 comments, comments_rsm = comments_data
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
311
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
312 # eventually display the link to show all comments
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
313 comments_count = int(main_data['comments_count'])
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
314 delta = comments_count - len(comments)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
315 if display_single and delta > 0:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
316 link = ("%(base)s/%(item_id)s?max=%(max)s" % {'base': base_url,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
317 'item_id': main_data['id'],
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
318 'max': main_data['comments_count']}).encode('utf-8')
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
319 text = D_("Show %(count)d previous %(comments)s") % {'count': delta,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
320 'comments': D_('comments') if delta > 1 else D_('comment')}
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
321 request.write("""<a href="%(link)s" class="comments_link">%(text)s</a>""" % {'link': link, 'text': text})
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
322
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
323 comments = sorted(comments, key=lambda entry: (float(entry.get('published', 0))))
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
324 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
325 self.__render_html_entry(comment, base_url, request)
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
326
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
327 # display navigation footer
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
328 request.write("""<div class="footer">""")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
329 if not display_single and after_tag:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
330 request.write(after_tag)
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
331 request.write("""</div>""")
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
332
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
333 request.write('</body></html>')
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
334 request.finish()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 229
diff changeset
335
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
336 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
337 """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
338 @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
339 @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
340 @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
341 """
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 388
diff changeset
342 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
343 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
344 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
345
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 388
diff changeset
346 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
347 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
348 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
349 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
350 processor = addURLToText if key.startswith('content') else sanitizeHtml
588
c8cca1a373dd server_side: static blog: convert \n in raw text message to <br/>
souliane <souliane@mailoo.org>
parents: 586
diff changeset
351 return convertNewLinesToXHTML(processor(entry[key])).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
352 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
353
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 388
diff changeset
354 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
355 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
356 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
357 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
358
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
359 if is_comment:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
360 author = (_("from %s") % entry['author']).encode('utf-8')
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
361 item_link = ''
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
362 footer = ''
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
363 else:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
364 author = '&nbsp;'
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
365 item_link = ("%(base)s/%(item_id)s" % {'base': base_url, 'item_id': entry['id']}).encode('utf-8')
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
366 comments_count = int(entry['comments_count'])
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
367 comments_text = (D_('comments') if comments_count > 1 else D_('comment')).encode('utf-8')
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
368 footer = addMainItemLink("""<div class="mblog_footer mblog_footer_main">
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
369 <div class="mblog_metadata">
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
370 <div class="mblog_comments">%(count)s %(comments)s</div>
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
371 </div>
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
372 </div>""" % {'count': comments_count,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
373 'comments': comments_text})
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
374
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
375 header = """<div class="mblog_header %(class)s">
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
376 <div class="mblog_metadata">
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
377 <div class="mblog_author">%(author)s</div>
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
378 <div class="mblog_timestamp">%(date)s</div>
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
379 </div>
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
380 </div>""" % {'author': author, 'date': datetime_,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
381 'class': '' if is_comment else 'mblog_header_main'}
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
382 if not is_comment:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
383 header = addMainItemLink(header)
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
384
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 388
diff changeset
385 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
386 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
387 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
388 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
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
390 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
391 %(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
392 <span class="mblog_content">%(content)s</span>
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
393 %(footer)s
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
394 </div>""" % {'extra_style': 'mblog_comment' if entry['type'] == 'comment' else '',
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
395 'item_link': item_link,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
396 'header': header,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
397 'content': body,
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 487
diff changeset
398 'footer': footer})
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
399
344
d7b98e499935 server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
souliane <souliane@mailoo.org>
parents: 340
diff changeset
400 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
401 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
402 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
403
12
513fe9bd0665 server: fixed wrong parameter number in blog resource
Goffi <goffi@goffi.org>
parents: 10
diff changeset
404 def render_error_blog(self, error, request, profile):
409
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
405 request.write(MicroBlog.ERROR_TEMPLATE % {'root': '../' * len(request.postpath),
35a43d0dc032 browser and server sides: display favicon
souliane <souliane@mailoo.org>
parents: 389
diff changeset
406 'message': "Can't access requested data"})
10
c28a4840e1a8 server: microblog resource
Goffi <goffi@goffi.org>
parents:
diff changeset
407 request.finish()