def recommend(post_id, comment_id=None, text=None): try: try: posts.recommend(post_id, comment_id, text) return xmpp_template('recommendation_sent', post_id=post_id, comment_id=comment_id) except RecommendationExists: try: posts.unrecommend(post_id, comment_id) return xmpp_template('recommendation_cancel_sent', post_id=post_id, comment_id=comment_id) except RecommendationNotFound: pass except PostNotFound: return xmpp_template('post_not_found', post_id=post_id) except CommentNotFound: return xmpp_template('comment_not_found', post_id=post_id, comment_id=comment_id) except PostReadonlyError: return xmpp_template('post_readonly', post_id=post_id) except RecommendationError: return xmpp_template('post_recommend_denied', post_id=post_id) except PostAuthorError: return xmpp_template('post_denied', post_id=post_id)
def recommend_comment(id, comment_id): text = env.request.args('text') rcid = posts.recommend(id, comment_id, text) if rcid: return {"comment_id": rcid}
def recommend_post(id): text = env.request.args("text") rcid = posts.recommend(id, None, text) if rcid: return {"comment_id": rcid}
def recommend(post_id, comment_id=None, text=None): try: try: posts.recommend(post_id, comment_id, text) return xmpp_template('recommendation_sent', post_id=post_id, comment_id=comment_id) except RecommendationExists: try: posts.unrecommend(post_id, comment_id) return xmpp_template('recommendation_cancel_sent', post_id=post_id, comment_id=comment_id) except RecommendationNotFound: pass except PostNotFound: return xmpp_template('post_not_found', post_id=post_id) except CommentNotFound: return xmpp_template('comment_not_found', post_id=post_id, comment_id=comment_id) except RecommendationError: return xmpp_template('post_recommend_denied', post_id=post_id) except PostAuthorError: return xmpp_template('post_denied', post_id=post_id)
def recommend(id): comment_id = env.request.args('comment_id') text = env.request.args('text') try: rcid = posts.recommend(id, comment_id, text) except RecommendationError: raise Forbidden except RecommendationExists: return Response(redirect=env.request.referer) if rcid: rcid = '#%s' % rcid else: rcid = '' if env.owner and env.owner.login: login = env.owner.login.lower() else: post = Post(id) login = post.author.login.lower() return Response(redirect='%s://%s.%s/%s%s' % \ (env.request.protocol, login, settings.domain, id, rcid))