def update(request): """ Updating a paste. return to display if succed. return to edit if fail. """ paste = Paste.get(request.matchdict['idContent']) password = _buildPassword(paste.username, paste.created, request.POST['password']) if password == paste.password: paste.title = request.POST['title'] paste.content = request.POST['content'] paste.save() request.session.flash(u"Updated") # TODO translatoion return HTTPFound(request.route_path('oneContent', idContent=paste._id)) request.session.flash(u"Wrong password") # TODO translatoion return HTTPFound(request.route_path('edit', idContent=paste._id))
def contentRaw(request): """ Display a raw content paste. """ paste = Paste.get(request.matchdict['idContent']) # TODO type/mime return paste.content
def edit(request): """ Edit a paste. """ paste = Paste.get(request.matchdict['idContent']) return {'lexers': lexers(), 'paste': paste,}
def content(request): """ Display a content Paste. """ paste = Paste.get(request.matchdict['idContent']) lexer = get_lexer_by_name(paste.typeContent, stripall=True) result = highlight(paste['content'], lexer, formatter) return {'paste': paste, 'content': result,}
def deleteConfirm(request): """ Ask confirmation on delete. """ paste = Paste.get(request.matchdict['idContent']) if not(paste.username and paste.password): return HTTPFound(request.route_path('oneContent', idContent=paste._id)) lexer = get_lexer_by_name(paste.typeContent, stripall=True) result = highlight(paste['content'], lexer, formatter) return {'paste': paste, 'content': result,}
def delete(request): """ Delete a paste. return to / if succed return to deleteConfigm is fail. """ paste = Paste.get(request.matchdict['idContent']) password = _buildPassword(paste.username, paste.created, request.POST['password']) if password == paste.password: paste.delete() request.session.flash(u"Deleted") # TODO translatoion return HTTPFound(request.route_path('home', )) request.session.flash(u"Wrong password") # TODO translatoion return HTTPFound(request.route_path('deleteConfirm', idContent=paste._id))
def __call__(self, context, request): try: request.paste = Paste.get(request.matchdict['idContent']) return True except couchdbkit.exceptions.ResourceNotFound: return False