Mercurial > libervia-web
annotate server_side/blog.py @ 110:dfc02690deb4
browser side: CSS: header, unibox, tabs + drag'n' drop reworked
author | Adrien Vigneron <adrienvigneron@mailoo.org> |
---|---|
date | Wed, 29 Jun 2011 23:52:00 +0200 |
parents | 9d8e79ac4c9c |
children | ddfcc4cb6cee |
rev | line source |
---|---|
10 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
6 Copyright (C) 2011 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 | |
29 class MicroBlog(Resource): | |
30 isLeaf = True | |
31 | |
32 ERROR_TEMPLATE = """ | |
33 <html> | |
34 <head> | |
35 <title>MICROBLOG ERROR</title> | |
36 </head> | |
37 <body> | |
38 <h1 style='text-align: center; color: red;'>%s</h1> | |
39 </body> | |
40 </html> | |
41 """ | |
42 | |
43 def __init__(self,host): | |
44 self.host = host | |
45 Resource.__init__(self) | |
46 if not host.bridge.isConnected("libervia"): #FIXME: hard coded value for test | |
47 host.bridge.connect("libervia") | |
48 | |
49 def render_GET(self, request): | |
50 if not request.postpath: | |
51 return MicroBlog.ERROR_TEMPLATE % "You must indicate a nickname" | |
52 else: | |
53 prof_requested = request.postpath[0] | |
54 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here | |
55 prof_found = self.host.bridge.getProfileName(prof_requested) | |
56 if not prof_found or prof_found=='libervia': | |
57 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" | |
58 else: | |
59 pub_jid=JID(self.host.bridge.getParamA('JabberID','Connection','value',prof_found)) | |
60 d = defer.Deferred() | |
61 d.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None) | |
62 self.host.bridge.getLastMicroblogs(pub_jid.userhost(), 10, 'libervia', d.callback, d.errback) | |
63 | |
64 return server.NOT_DONE_YET | |
65 | |
66 def render_html_blog(self, mblog_data, request, profile): | |
67 user = sanitizeHtml(profile).encode('utf-8') | |
68 request.write(""" | |
69 <html> | |
70 <head> | |
71 <link rel="stylesheet" type="text/css" href="../css/blog.css" /> | |
72 <title>%(user)s's microblog</title> | |
73 </head> | |
74 <body> | |
75 <div class='mblog_title'>%(user)s</div> | |
76 """ % {'user':user}) | |
15
78bfc398926b
public blog is now shown i reverse order
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
77 mblog_data.reverse() |
10 | 78 for entry in mblog_data: |
79 timestamp = float(entry.get('timestamp',0)) | |
80 _datetime = datetime.fromtimestamp(timestamp) | |
81 request.write("<div class='mblog_content'><span class='mblog_timestamp'>%(date)s</span>%(content)s</div>" % { | |
82 'date':_datetime, | |
83 'content':sanitizeHtml(entry['content']).encode('utf-8')}) | |
84 request.write('</body></html>') | |
85 request.finish() | |
86 | |
12
513fe9bd0665
server: fixed wrong parameter number in blog resource
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
87 def render_error_blog(self, error, request, profile): |
10 | 88 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") |
89 request.finish() |