当前位置: 首页>>代码示例>>Python>>正文


Python MUserStory.read_date方法代码示例

本文整理汇总了Python中apps.reader.models.MUserStory.read_date方法的典型用法代码示例。如果您正苦于以下问题:Python MUserStory.read_date方法的具体用法?Python MUserStory.read_date怎么用?Python MUserStory.read_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.reader.models.MUserStory的用法示例。


在下文中一共展示了MUserStory.read_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mark_story_as_read

# 需要导入模块: from apps.reader.models import MUserStory [as 别名]
# 或者: from apps.reader.models.MUserStory import read_date [as 别名]
def mark_story_as_read(request):
    story_ids = request.REQUEST.getlist('story_id')
    feed_id = int(request.REQUEST['feed_id'])

    try:
        usersub = UserSubscription.objects.select_related('feed').get(user=request.user, feed=feed_id)
    except (UserSubscription.DoesNotExist, Feed.DoesNotExist):
        duplicate_feed = DuplicateFeed.objects.filter(duplicate_feed_id=feed_id)
        if duplicate_feed:
            try:
                usersub = UserSubscription.objects.get(user=request.user, 
                                                       feed=duplicate_feed[0].feed)
            except (UserSubscription.DoesNotExist, Feed.DoesNotExist):
                return dict(code=-1)
        else:
            return dict(code=-1)
                
    if not usersub.needs_unread_recalc:
        usersub.needs_unread_recalc = True
        usersub.save()
        
    data = dict(code=0, payload=story_ids)
    
    if len(story_ids) > 1:
        logging.user(request, "~FYRead %s stories in feed: %s" % (len(story_ids), usersub.feed))
    else:
        logging.user(request, "~FYRead story in feed: %s" % (usersub.feed))
        
    for story_id in story_ids:
        try:
            story = MStory.objects.get(story_feed_id=feed_id, story_guid=story_id)
        except MStory.DoesNotExist:
            # Story has been deleted, probably by feed_fetcher.
            continue
        now = datetime.datetime.utcnow()
        date = now if now > story.story_date else story.story_date # For handling future stories
        m = MUserStory(story=story, user_id=request.user.pk, feed_id=feed_id, read_date=date, story_id=story_id)
        try:
            m.save()
        except OperationError:
            logging.user(request, "~BRMarked story as read: Duplicate Story -> %s" % (story_id))
            logging.user(request, "~BRRead now date: %s, story_date: %s, story_id: %s." % (m.read_date, story.story_date, story.story_guid))
            logging.user(request, "~BRSubscription mark_read_date: %s, oldest_unread_story_date: %s" % (
                usersub.mark_read_date, usersub.oldest_unread_story_date))
            m = MUserStory.objects.get(story=story, user_id=request.user.pk, feed_id=feed_id)
            logging.user(request, "~BROriginal read date: %s, story id: %s, story.id: %s" % (m.read_date, m.story_id, m.story.id))
            m.story_id = story_id
            m.read_date = date
            m.save()
    
    return data
开发者ID:mrcrabby,项目名称:NewsBlur,代码行数:53,代码来源:views.py


注:本文中的apps.reader.models.MUserStory.read_date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。