def get(self, id): nickname = "*****@*****.**" wk = Workspace.get_by_id(int(id)) if not wk: self.response.out.write("No such workspace") return user = users.get_current_user() if user: nickname = user.nickname() if wk.user.google_id != user.user_id() and not wk.demo: self.response.out.write("Not your workspace, %s" % nickname) return if not user and not wk.demo: self.redirect(users.create_login_url(self.request.uri)) else: path = 'templates/workspace.html' template = Template(file=path) template.user = nickname template.logout_url = users.create_logout_url("/") template.wk = Workspace.get_by_id(int(id)) template.id = id template.indent_strings = workspace.indent_strings template.indent_styles = workspace.indent_styles template.font_sizes = workspace.font_sizes template.font_faces = workspace.font_faces template.encodings = workspace.encodings template.sample_stylesheets = css.sample_stylesheets self.response.out.write(template)
def get(self, id, format): wk = Workspace.get_by_id(int(id)) if not wk: self.response.out.write("No such workspace") return # Check access if self.request.get("key") and wk.sharing_key == self.request.get("key"): pass elif wk.demo: pass else: user = users.get_current_user() if not user or wk.user.google_id != user.user_id(): self.response.out.write("Not logged in as the right user") return x = xhtml.parse(wk.content_xml(), wk, format) w = writer.Writer(wk) xhtml.recurse(x.documentElement, w, format, wk) html = w.to_html() # Re-encode the whole thing, in case out-of-range characters were in # elements names or attributes. html = encoding.encode_html(html, wk.encoding) if format == "text": self.response.headers["Content-Type"] = "text/plain; charset=%s" % wk.encoding self.response.out.write(html) else: path = 'templates/%s.html' % format template = Template(file=path) template.wk = wk if format == "code": html = cgi.escape(html) if format != "text": html = xhtml.expand_annotations(html) template.html = html template.id = id self.response.headers["Content-Type"] = "text/html; charset=%s" % wk.encoding if wk.encoding == "utf-8": self.response.out.write(unicode(template)) else: self.response.out.write(unicode(template).encode(wk.encoding))