def unban(): data = request.get_json() id = data.get('id') user = User.find_by_pk(id) if user: user.unban(commit=True) return json_data(data) else: return json_error_invalid_request()
def ban(): data = request.get_json() id = data.get('id') reason = data.get('reason', 'You have been banned') user = User.find_by_pk(id) if user: user.ban(reason=reason, commit=True) return json_data(data) else: return json_error_invalid_request()
def avatar(): id = request.args.get('id') size = request.args.get('size', 100) user = User.find_by_pk(id) if not user: return json_error_invalid_request() avatar = None if user.login_type == 'facebook': avatar = "http://graph.facebook.com/%s/picture?width=%s&height=%s" % ( user.login_id, size, size) elif user.login_type == 'github': avatar = "http://www.gravatar.com/avatar/%s?s=%s" % ( user.social_data.get('gravatar_id'), size) elif user.login_type == 'google': avatar = user.social_data.get('picture') + "?sz=" + size if not avatar: return json_error_invalid_request() return redirect(avatar, 302)
def decorated_function(*args, **kwargs): data = request.get_json() # support both json and normal request if not data: data = request.args # now kiss data = dict(request.args.items() + kwargs.items()) topic_id = data.get('id') topic_id = data.get('topic_id', topic_id) topic = Topic.find_by_pk(topic_id) if not topic: if json: return json_error_invalid_request() else: return abort(400) g.topic = topic return f(*args, **kwargs)
def decorated_function(*args, **kwargs): data = request.get_json() # support both json and normal request if not data: data = request.args # now kiss data = dict(request.args.items() + kwargs.items()) article_id = data.get('id') article_id = data.get('article_id', article_id) article = Article.find_by_pk(article_id) if not article: if json: return json_error_invalid_request() else: return abort(400) g.article = article return f(*args, **kwargs)
def decorated_function(*args, **kwargs): data = request.get_json() # support both json and normal request if not data: data = request.args # now kiss data = dict(request.args.items() + kwargs.items()) question_id = data.get('id') question_id = data.get('question_id', question_id) question = Question.find_by_pk(question_id) if not question: if json: return json_error_invalid_request() else: return abort(400) g.question = question return f(*args, **kwargs)
def decorated_function(*args, **kwargs): data = request.get_json() # support both json and normal request if not data: data = request.args # now kiss data = dict(request.args.items() + kwargs.items()) question_id = data.get('id') question_id = data.get('question_id', question_id) question = Question.find_by_pk(question_id) if not question: if json: return json_error_invalid_request() else: return abort(400) g.question = question return f(*args, **kwargs)
def decorated_function(*args, **kwargs): data = request.get_json() # support both json and normal request if not data: data = request.args # now kiss data = dict(request.args.items() + kwargs.items()) article_id = data.get('id') article_id = data.get('article_id', article_id) article = Article.find_by_pk(article_id) if not article: if json: return json_error_invalid_request() else: return abort(400) g.article = article return f(*args, **kwargs)
def decorated_function(*args, **kwargs): data = request.get_json() # support both json and normal request if not data: data = request.args # now kiss data = dict(request.args.items() + kwargs.items()) topic_id = data.get('id') topic_id = data.get('topic_id', topic_id) topic = Topic.find_by_pk(topic_id) if not topic: if json: return json_error_invalid_request() else: return abort(400) g.topic = topic return f(*args, **kwargs)
def comment_delete(): data = request.get_json() id = data.get('id') comment = Comment.find_by_pk(id) if comment: try: comment.article.update_comment_count(offset=-1) comment.article.update_user_comment_count(offset=-1, user_id=comment.user_id) comment.delete() db_session.commit() cache.update_article(comment.article.id, comment.article) cache.update_sorted_articles(comment.article, 'comment_count') return json_data(data) except Exception: db_session.rollback() return json_error_database() else: return json_error_invalid_request()
def comment_delete(): data = request.get_json() id = data.get('id') comment = Comment.find_by_pk(id) if comment: try: comment.topic.update_comment_count(offset=-1) comment.topic.update_user_comment_count(offset=-1, user_id=comment.user_id) comment.delete() db_session.commit() cache.update_topic(comment.topic.id, comment.topic) cache.update_sorted_topics(comment.topic, 'comment_count') return json_data(data) except Exception: db_session.rollback() return json_error_database() else: return json_error_invalid_request()
user_points = 1 if vote.up: user_points = 5 topic.user.update_points(up=not vote.up, points=user_points) db_session.commit() data = {"points": topic.points} cache.update_topic(topic.id, topic) cache.update_sorted_topics(topic, 'points') return jsonify({"data": data}) except Exception, e: logging.error(e) return json_error_database() else: return json_error_invalid_request() @api_topics.route('/topics/search', methods=["GET"]) def search(): query = request.args.get('query') limit = int(request.args.get('limit', 10)) offset = int(request.args.get('offset', 0)) result = Topic.search(query, offset=offset, limit=limit) topics = result.get('data') pagination = dict(limit=limit, offset=offset, total=Topic.count_search(query))
user_points = 10 article.user.update_points(up= not vote.up, points=user_points) db_session.commit() data = { "points": article.points } cache.update_article(article.id, article) cache.update_sorted_articles(article, 'points') return jsonify({"data": data}) except Exception, e: logging.error(e) return json_error_database() else: return json_error_invalid_request() @api_articles.route('/articles/search', methods=["GET"]) def search(): query = request.args.get('query') limit = int(request.args.get('limit', 10)) offset = int(request.args.get('offset', 0)) result = Article.search(query, offset=offset, limit=limit) articles = result.get('data') pagination = dict( limit=limit, offset=offset, total=Article.count_search(query) )