Mercurial > libervia-web
comparison server_side/blog.py @ 243:63e9b680d3e7
browser_side, blog: better PEP8 compliance
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 15 Oct 2013 17:19:03 +0200 |
parents | e632f77c4219 |
children | 52b1afd7ac3f |
comparison
equal
deleted
inserted
replaced
242:a25aa882e09a | 243:63e9b680d3e7 |
---|---|
42 <h1 style='text-align: center; color: red;'>%s</h1> | 42 <h1 style='text-align: center; color: red;'>%s</h1> |
43 </body> | 43 </body> |
44 </html> | 44 </html> |
45 """ | 45 """ |
46 | 46 |
47 def __init__(self,host): | 47 def __init__(self, host): |
48 self.host = host | 48 self.host = host |
49 Resource.__init__(self) | 49 Resource.__init__(self) |
50 if not host.bridge.isConnected("libervia"): #FIXME: hard coded value for test | 50 if not host.bridge.isConnected("libervia"): # FIXME: hard coded value for test |
51 host.bridge.connect("libervia") | 51 host.bridge.connect("libervia") |
52 | 52 |
53 def render_GET(self, request): | 53 def render_GET(self, request): |
54 if not request.postpath: | 54 if not request.postpath: |
55 return MicroBlog.ERROR_TEMPLATE % "You must indicate a nickname" | 55 return MicroBlog.ERROR_TEMPLATE % "You must indicate a nickname" |
56 else: | 56 else: |
57 prof_requested = request.postpath[0] | 57 prof_requested = request.postpath[0] |
58 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here | 58 #TODO: char check: only use alphanumerical chars + some extra(_,-,...) here |
59 prof_found = self.host.bridge.getProfileName(prof_requested) | 59 prof_found = self.host.bridge.getProfileName(prof_requested) |
60 if not prof_found or prof_found=='libervia': | 60 if not prof_found or prof_found == 'libervia': |
61 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" | 61 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" |
62 else: | 62 else: |
63 def got_jid(pub_jid_s): | 63 def got_jid(pub_jid_s): |
64 pub_jid = JID(pub_jid_s) | 64 pub_jid = JID(pub_jid_s) |
65 d2 = defer.Deferred() | 65 d2 = defer.Deferred() |
81 <link rel="stylesheet" type="text/css" href="../css/blog.css" /> | 81 <link rel="stylesheet" type="text/css" href="../css/blog.css" /> |
82 <title>%(user)s's microblog</title> | 82 <title>%(user)s's microblog</title> |
83 </head> | 83 </head> |
84 <body> | 84 <body> |
85 <div class='mblog_title'>%(user)s</div> | 85 <div class='mblog_title'>%(user)s</div> |
86 """ % {'user':user}) | 86 """ % {'user': user}) |
87 #mblog_data.reverse() | 87 #mblog_data.reverse() |
88 for entry in mblog_data: | 88 for entry in mblog_data: |
89 timestamp = float(entry.get('timestamp',0)) | 89 timestamp = float(entry.get('timestamp', 0)) |
90 _datetime = datetime.fromtimestamp(timestamp) | 90 _datetime = datetime.fromtimestamp(timestamp) |
91 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> | 91 request.write("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> |
92 <span class='mblog_content'>%(content)s</span></div>""" % { | 92 <span class='mblog_content'>%(content)s</span></div>""" % { |
93 'date':_datetime, | 93 'date': _datetime, |
94 'content':sanitizeHtml(entry['content']).encode('utf-8')}) | 94 'content': sanitizeHtml(entry['content']).encode('utf-8')}) |
95 request.write('</body></html>') | 95 request.write('</body></html>') |
96 request.finish() | 96 request.finish() |
97 | 97 |
98 def render_error_blog(self, error, request, profile): | 98 def render_error_blog(self, error, request, profile): |
99 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") | 99 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") |
100 request.finish() | 100 request.finish() |