def GET(self, page_path): try: page = get_page_by_path(page_path) if not page.is_published and not auth.get_user(): raise flash.redirect(_(page_access_forbidden_text), "/login") load_page_data(page) if auth.has_role("admin"): json_data = web.storage( page=page_to_json(page), pages=pages_to_json(get_pages_in_tree_order()), ) else: json_data = web.storage() if "edit" in web.input() and auth.has_role("admin"): json_data.update( page_block=block_to_json( get_page_block_by_page_id(page.id)), template_blocks=template_blocks_to_json() ) else: load_page_blocks(page.id) return render.pages.page(json_data) except IndexError: raise web.notfound()
def GET(self, page_id): try: page = get_page_by_id(page_id) if auth.get_user() or is_page_published(page): raise web.seeother(page.path) else: raise flash.redirect(_(page_access_forbidden_text), "/login") except IndexError: raise web.notfound()
def download_document(document): if (not auth.has_role("admin", "editor", "user") and not document.is_published): raise flash.redirect(_("Cannot download this document")) web.header("Content-Disposition", "attachment; filename=%s" % slugify(document.title) + document.extension) web.header("Content-Type", document.mimetype) f = open(os.path.join(config.upload_dir, document.filename), 'rb') while 1: buf = f.read(1024 * 8) if not buf: break yield buf