comparison libervia_server/blog.py @ 409:35a43d0dc032

browser and server sides: display favicon
author souliane <souliane@mailoo.org>
date Mon, 17 Mar 2014 18:30:07 +0100
parents 2d782349b88a
children bbdbee25123a
comparison
equal deleted inserted replaced
408:ee8ebfe23e16 409:35a43d0dc032
33 class MicroBlog(Resource): 33 class MicroBlog(Resource):
34 isLeaf = True 34 isLeaf = True
35 35
36 ERROR_TEMPLATE = """ 36 ERROR_TEMPLATE = """
37 <html> 37 <html>
38 <head> 38 <head profile="http://www.w3.org/2005/10/profile">
39 <link rel="icon" type="image/png" href="%(root)ssat_logo_16.png">
39 <title>MICROBLOG ERROR</title> 40 <title>MICROBLOG ERROR</title>
40 </head> 41 </head>
41 <body> 42 <body>
42 <h1 style='text-align: center; color: red;'>%s</h1> 43 <h1 style='text-align: center; color: red;'>%(message)s</h1>
43 </body> 44 </body>
44 </html> 45 </html>
45 """ 46 """
46 47
47 def __init__(self, host): 48 def __init__(self, host):
50 if not host.bridge.isConnected("libervia"): # FIXME: hard coded value for test 51 if not host.bridge.isConnected("libervia"): # FIXME: hard coded value for test
51 host.bridge.connect("libervia") 52 host.bridge.connect("libervia")
52 53
53 def render_GET(self, request): 54 def render_GET(self, request):
54 if not request.postpath: 55 if not request.postpath:
55 return MicroBlog.ERROR_TEMPLATE % "You must indicate a nickname" 56 return MicroBlog.ERROR_TEMPLATE % {'root': '',
57 'message': "You must indicate a nickname"}
56 else: 58 else:
57 prof_requested = request.postpath[0] 59 prof_requested = request.postpath[0]
58 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here 60 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here
59 prof_found = self.host.bridge.getProfileName(prof_requested) 61 prof_found = self.host.bridge.getProfileName(prof_requested)
60 if not prof_found or prof_found == 'libervia': 62 if not prof_found or prof_found == 'libervia':
61 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" 63 return MicroBlog.ERROR_TEMPLATE % {'root': '../' * len(request.postpath),
64 'message': "Invalid nickname"}
62 else: 65 else:
63 def got_jid(pub_jid_s): 66 def got_jid(pub_jid_s):
64 pub_jid = JID(pub_jid_s) 67 pub_jid = JID(pub_jid_s)
65 d2 = defer.Deferred() 68 d2 = defer.Deferred()
66 item_id = None 69 item_id = None
122 <html> 125 <html>
123 <head> 126 <head>
124 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 127 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
125 <link rel="alternate" type="application/atom+xml" href="%(base)s/atom.xml"/> 128 <link rel="alternate" type="application/atom+xml" href="%(base)s/atom.xml"/>
126 <link rel="stylesheet" type="text/css" href="%(root)scss/blog.css" /> 129 <link rel="stylesheet" type="text/css" href="%(root)scss/blog.css" />
130 <link rel="icon" type="image/png" href="%(root)ssat_logo_16.png">
127 <title>%(user)s's microblog</title> 131 <title>%(user)s's microblog</title>
128 </head> 132 </head>
129 <body> 133 <body>
130 <div class="mblog_title"><a href="%(base)s">%(banner_elt)s</a></div> 134 <div class="mblog_title"><a href="%(base)s">%(banner_elt)s</a></div>
131 """ % {'base': base_url, 135 """ % {'base': base_url,
195 def render_atom_feed(self, feed, request): 199 def render_atom_feed(self, feed, request):
196 request.write(feed.encode('utf-8')) 200 request.write(feed.encode('utf-8'))
197 request.finish() 201 request.finish()
198 202
199 def render_error_blog(self, error, request, profile): 203 def render_error_blog(self, error, request, profile):
200 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") 204 request.write(MicroBlog.ERROR_TEMPLATE % {'root': '../' * len(request.postpath),
205 'message': "Can't access requested data"})
201 request.finish() 206 request.finish()