def GET(self): i = web.input(pid=None, cid=None, opt="") option = i.pop('opt') try: # getting the requested paper i.pid = int(i.pid) paper = Paper(i.pid) if not paper.enabled: raise except (TypeError, IndexError): raise web.notfound() try: # getting the specified comment i.cid = int(i.cid) comment = paper.comments[i.cid] if not comment['enabled']: raise IndexError except (TypeError, IndexError): return render().item(paper) if option and comment['username'] == session()['uname'] \ and session()['logged']: # TODO: or session()['admin'] if option == "delete": paper.activate_comment(i.cid, state=False) return render().item(paper) if option == "edit": return render().edit(i.pid, i.cid, comment) return render().comment(i.pid, i.cid, comment)
def POST(self): """Organize/sort the comments according to votes, author, time, etc (heuristic) POST route to add a comment to a paper side effects: - handles votes / karma """ i = web.input(pid=None, cid=None, comment="", opt="", enabled=True) option = i.pop('opt') try: # getting the requested paper i.pid = int(i.pid) paper = Paper(i.pid) except (TypeError, IndexError): # TODO: Log # IndexEror("No such paper") or # TypeError("int() arg must be str or number, not 'NoneType'") raise web.notfound() if not i.comment: return render().item(paper) if not session().logged: raise web.seeother('/login?redir=/item?pid=%s' % i.pid) else: i.username = session()['uname'] if option == "edit": try: paper.edit_comment(i.cid, content=i.comment, enabled=i.enabled) except (TypeError, ValueError) as e: # XXX Log error e return render().item(paper) else: i.cid = paper.add_comment(i.cid, session()['uname'], content=i.comment, votes=paper.votes, enabled=i.enabled) record_comment(session()['uname'], i.pid, i.cid) return render().item(paper)
def redir2login(redir="/", msg=""): if web.ctx.homedomain: return web.seeother("{}/login?redir={}".format(web.ctx.homedomain, redir)) return web.notfound()
def GET(self, err=None): raise web.notfound("404")
def GET(self, err=None): raise web.notfound('404')
def GET(self, **kwargs): raise web.notfound("404")
def GET(self, post): path = '%s/blog/posts/%s' % (_path, post) if os.path.isfile(path): with open(path) as p: return render().post(markdown.markdown(p.read())) raise web.notfound()