def post_comment_action(): bd = app.config['bd'] slug = request.args.get('slug', '') comment = { 'text': request.form['comment_text'], 'author': request.form['comment_author'], 'aurl': request.form['comment_aurl'], } post_comment(bd, request.args.get('slug', ''), comment) tgu = template_fns.template_get_url(bd.config) return redirect(tgu('/'+bd.posts_by_slug[slug].get_url()))
def blog_page(path): bd = app.config['bd'] print("Got path " + path) destpath = bd.config.outpathto(path) if destpath[-1] == '/': destpath += 'index.html' try: return send_file(destpath) except IOError as e: if e.errno == errno.ENOENT: abort(404) elif e.errno == errno.EISDIR: # "Is a directory" tgu = template_fns.template_get_url(bd.config) return redirect(tgu(path + '/'))
def load_templates(self): env = Environment(loader=FileSystemLoader(self.config.pathto('templates'))) env.globals['blogdata'] = self env.globals['user_options'] = self.config.get_user_options() env.globals['get_asset'] = template_fns.template_get_asset(self.config) env.globals['get_url'] = template_fns.template_get_url(self.config) env.globals['pretty_date'] = template_fns.template_pretty_date env.globals['linkify_tweet'] = template_fns.template_linkify_tweet env.globals['utcnow'] = template_fns.template_utcnow env.globals['dt_iso'] = template_fns.template_dt_iso templates = {} for t in ['index', 'blogpost_page', 'tag_archive', 'atom_feed', 'dt_archive', 'page']: tname = self.config.get('templates', t) if not tname: print("Warning: missing template def " + t) continue try: templates[t] = env.get_template(tname) except TemplateNotFound as e: print("Warning: template " + e.name + " not found!") # Social templates for s in ['twitter']: tname = self.config.get(s, 'template') try: templates[s] = env.get_template(tname) except TemplateNotFound as e: print("Warning: template " + e.name + " not found!") self.templates = templates