本文整理匯總了Python中web.controllers.ArticleController.get方法的典型用法代碼示例。如果您正苦於以下問題:Python ArticleController.get方法的具體用法?Python ArticleController.get怎麽用?Python ArticleController.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web.controllers.ArticleController
的用法示例。
在下文中一共展示了ArticleController.get方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_article
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def get_article(article_id, parse=False):
locale = get_locale()
contr = ArticleController(current_user.id)
article = contr.get(id=article_id)
if not article.readed:
article['readed'] = True
contr.update({'id': article_id}, {'readed': True})
article['category_id'] = article.category_id or 0
feed = FeedController(current_user.id).get(id=article.feed_id)
article['icon_url'] = url_for('icon.icon', url=feed.icon_url) \
if feed.icon_url else None
readability_available = bool(current_user.readability_key
or conf.PLUGINS_READABILITY_KEY)
article['date'] = format_datetime(localize(article.date), locale=locale)
article['readability_available'] = readability_available
if parse or (not article.readability_parsed
and feed.readability_auto_parse and readability_available):
try:
new_content = readability.parse(article.link,
current_user.readability_key
or conf.PLUGINS_READABILITY_KEY)
except Exception as error:
flash("Readability failed with %r" % error, "error")
article['readability_parsed'] = False
else:
article['readability_parsed'] = True
article['content'] = clean_urls(new_content, article['link'])
new_attr = {'readability_parsed': True, 'content': new_content}
contr.update({'id': article['id']}, new_attr)
return article
示例2: get_menu
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def get_menu():
categories_order = [0]
categories = {0: {'name': 'No category', 'id': 0}}
for cat in CategoryController(current_user.id).read().order_by('name'):
categories_order.append(cat.id)
categories[cat.id] = cat
unread = ArticleController(current_user.id).count_by_feed(readed=False)
for cat_id in categories:
categories[cat_id]['unread'] = 0
categories[cat_id]['feeds'] = []
feeds = {feed.id: feed for feed in FeedController(current_user.id).read()}
for feed_id, feed in feeds.items():
feed['created_stamp'] = timegm(feed.created_date.timetuple()) * 1000
feed['last_stamp'] = timegm(feed.last_retrieved.timetuple()) * 1000
feed['category_id'] = feed.category_id or 0
feed['unread'] = unread.get(feed.id, 0)
if not feed.filters:
feed['filters'] = []
if feed.icon_url:
feed['icon_url'] = url_for('icon.icon', url=feed.icon_url)
categories[feed['category_id']]['unread'] += feed['unread']
categories[feed['category_id']]['feeds'].append(feed_id)
return {'feeds': feeds, 'categories': categories,
'categories_order': categories_order,
'crawling_method': conf.CRAWLING_METHOD,
'max_error': conf.DEFAULT_MAX_ERROR,
'error_threshold': conf.ERROR_THRESHOLD,
'is_admin': current_user.is_admin,
'all_unread_count': sum(unread.values())}
示例3: like
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def like(article_id=None):
"""
Mark or unmark an article as favorites.
"""
art_contr = ArticleController(current_user.id)
article = art_contr.get(id=article_id)
art_contr = art_contr.update({'id': article_id},
{'like': not article.like})
return redirect(redirect_url())
示例4: get_article
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def get_article(article_id):
contr = ArticleController(g.user.id)
article = contr.get(id=article_id).dump()
if not article['readed']:
contr.update({'id': article_id}, {'readed': True})
article['category_id'] = article['category_id'] or 0
feed = FeedController(g.user.id).get(id=article['feed_id'])
article['icon_url'] = url_for('icon.icon', url=feed.icon_url) \
if feed.icon_url else None
return jsonify(**article)
示例5: get_article
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def get_article(article_id, parse=False):
locale = get_locale()
contr = ArticleController(current_user.id)
article = contr.get(id=article_id)
if not article.readed:
article['readed'] = True
contr.update({'id': article_id}, {'readed': True})
article['category_id'] = article.category_id or 0
feed = FeedController(current_user.id).get(id=article.feed_id)
article['icon_url'] = url_for('icon.icon', url=feed.icon_url) \
if feed.icon_url else None
article['date'] = format_datetime(localize(article.date), locale=locale)
return article
示例6: get_menu
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def get_menu():
now, locale = datetime.now(), get_locale()
categories_order = [0]
categories = {0: {'name': 'No category', 'id': 0}}
for cat in CategoryController(current_user.id).read().order_by('name'):
categories_order.append(cat.id)
categories[cat.id] = cat
unread = ArticleController(current_user.id).count_by_feed(readed=False)
for cat_id in categories:
categories[cat_id]['unread'] = 0
categories[cat_id]['feeds'] = []
feeds = {feed.id: feed for feed in FeedController(current_user.id).read()}
for feed_id, feed in feeds.items():
feed['created_rel'] = format_timedelta(feed.created_date - now,
add_direction=True, locale=locale)
feed['last_rel'] = format_timedelta(feed.last_retrieved - now,
add_direction=True, locale=locale)
feed['created_date'] = format_datetime(localize(feed.created_date),
locale=locale)
feed['last_retrieved'] = format_datetime(localize(feed.last_retrieved),
locale=locale)
feed['category_id'] = feed.category_id or 0
feed['unread'] = unread.get(feed.id, 0)
if not feed.filters:
feed['filters'] = []
if feed.icon_url:
feed['icon_url'] = url_for('icon.icon', url=feed.icon_url)
categories[feed['category_id']]['unread'] += feed['unread']
categories[feed['category_id']]['feeds'].append(feed_id)
return {'feeds': feeds, 'categories': categories,
'categories_order': categories_order,
'crawling_method': conf.CRAWLER_TYPE,
'max_error': conf.FEED_ERROR_MAX,
'error_threshold': conf.FEED_ERROR_THRESHOLD,
'is_admin': current_user.is_admin,
'all_unread_count': sum(unread.values())}
示例7: redirect_to_article
# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import get [as 別名]
def redirect_to_article(article_id):
contr = ArticleController(current_user.id)
article = contr.get(id=article_id)
if not article.readed:
contr.update({'id': article.id}, {'readed': True})
return redirect(article.link)