本文整理汇总了Python中models.Article.check_vote方法的典型用法代码示例。如果您正苦于以下问题:Python Article.check_vote方法的具体用法?Python Article.check_vote怎么用?Python Article.check_vote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.check_vote方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import check_vote [as 别名]
def get_article(id, user=None):
"""Gets a single article (formatted by json_data) from redis or postgresql
And performs some pre-filters for the current user
Args:
id (int): id
user (User): the current user
Returns:
None if the article is not existed or a dict of article data
"""
id = int(id)
key = Article.cache_key(id)
redis_client = get_client(key)
article = None
if not redis_client.exists(key):
article = Article.find_by_pk(id)
if article:
data = article.json_data()
redis_client.set(key, json.dumps(data))
article = data
else:
if redis_client.type(key) == 'hash':
print redis_client
article = json.loads(redis_client.get(key))
article['user_vote'] = Article.check_vote(user, article['id'])
return article
示例2: view
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import check_vote [as 别名]
def view(slug, id):
article = g.article
user = g.user
if article.update_view_count(ip=request.remote_addr, user=user, commit=True):
cache.update_article(article.id, article)
cache.update_sorted_articles(article, 'view_count')
article_data = article.json_data()
article_data['comments'] = article.get_comments(json=True)
article_data['user_vote'] = Article.check_vote(user, article.id)
article_data['user_comment'] = Article.check_comment(user, article.id)
context = {
'js_module': 'view_article',
'style': 'view_article',
'article': article_data,
'sub_title': article.title
}
return render_template('article/view.html', **context)