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 unrecommend(id): comment_id = env.request.args('comment_id') try: posts.unrecommend(id, comment_id) except RecommendationNotFound: pass return Response(redirect=env.request.referer)
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 unrecommend_comment(id, comment_id): posts.unrecommend(id, comment_id)
def unrecommend_post(id): posts.unrecommend(id, None)