本文整理汇总了Python中models.Feed.get_or_construct方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.get_or_construct方法的具体用法?Python Feed.get_or_construct怎么用?Python Feed.get_or_construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Feed
的用法示例。
在下文中一共展示了Feed.get_or_construct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subscribe
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_or_construct [as 别名]
def subscribe(rss_url):
'''Logic to add a given rss feed to the db, if required, and subscribe the current user to this feed'''
try:
feed = Feed.get_or_construct(rss_url)
except NotAFeed:
return jsonify(dict(status = 'Error', message='The given url is not an rss feed url'))
new_subscription = Subscription(feed_id = feed.id)
#atomically add new feed subscription to current user
number_of_items_affected = User.objects(id = current_user.id).update_one(add_to_set__subscriptions = new_subscription)
new_reader = Reader(user_id = current_user.id)
#atomically add current user to readers of all articles in subscribed feed
Article.objects(feed_id = feed.id).update(add_to_set__readers = new_reader)
if number_of_items_affected is 1:
return jsonify(dict(status = 'Success'))
else:
return jsonify(dict(\
status = 'Error'\
, message = 'Unable to subscribe'\
))