Mercurial > libervia-web
annotate server_side/blog.py @ 291:89818bca1a33
browser_side: set the ideal width for the blog post update dialog
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 10 Dec 2013 13:04:51 +0100 |
parents | 63e9b680d3e7 |
children | 52b1afd7ac3f |
rev | line source |
---|---|
10 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
10 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from server_side.html_tools import sanitizeHtml | |
23 from twisted.internet import reactor, defer | |
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 | |
28 | |
229
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
29 # Security limit for Libervia server_side |
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
30 SECURITY_LIMIT = -1 |
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() |
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
66 d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None) |
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
67 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
|
68 |
149
f78761e1be8e
server side: fixed public microblog
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
69 d1 = defer.Deferred() |
229
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
70 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', 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
|
71 d1.addCallbacks(got_jid) |
10 | 72 |
73 return server.NOT_DONE_YET | |
74 | |
75 def render_html_blog(self, mblog_data, request, profile): | |
76 user = sanitizeHtml(profile).encode('utf-8') | |
77 request.write(""" | |
78 <html> | |
79 <head> | |
175
764ca916e56e
browser side: fixed charset in public blog page
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
80 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
10 | 81 <link rel="stylesheet" type="text/css" href="../css/blog.css" /> |
82 <title>%(user)s's microblog</title> | |
83 </head> | |
84 <body> | |
85 <div class='mblog_title'>%(user)s</div> | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
86 """ % {'user': user}) |
176
b9edfa058786
server side: fixed public blog items order
Goffi <goffi@goffi.org>
parents:
175
diff
changeset
|
87 #mblog_data.reverse() |
10 | 88 for entry in mblog_data: |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
89 timestamp = float(entry.get('timestamp', 0)) |
10 | 90 _datetime = datetime.fromtimestamp(timestamp) |
228
6efd189e8d78
server_side: put the blog entry content in its own span + CSS customization
souliane <souliane@mailoo.org>
parents:
176
diff
changeset
|
91 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> |
6efd189e8d78
server_side: put the blog entry content in its own span + CSS customization
souliane <souliane@mailoo.org>
parents:
176
diff
changeset
|
92 <span class='mblog_content'>%(content)s</span></div>""" % { |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
93 'date': _datetime, |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
94 'content': sanitizeHtml(entry['content']).encode('utf-8')}) |
10 | 95 request.write('</body></html>') |
96 request.finish() | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
97 |
12
513fe9bd0665
server: fixed wrong parameter number in blog resource
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
98 def render_error_blog(self, error, request, profile): |
10 | 99 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") |
100 request.finish() |