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


Python MSharedStory.get_shared_stories_from_site方法代码示例

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


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

示例1: check_share_on_site

# 需要导入模块: from apps.social.models import MSharedStory [as 别名]
# 或者: from apps.social.models.MSharedStory import get_shared_stories_from_site [as 别名]
def check_share_on_site(request, token):
    code       = 0
    story_url  = request.GET['story_url']
    rss_url    = request.GET.get('rss_url')
    callback   = request.GET['callback']
    other_stories = None
    same_stories = None
    usersub    = None
    message    = None
    user       = None
    
    if not story_url:
        code = -1
    else:
        try:
            user_profile = Profile.objects.get(secret_token=token)
            user = user_profile.user
        except Profile.DoesNotExist:
            code = -1
    
    feed = Feed.get_feed_from_url(rss_url, create=False, fetch=False)
    if not feed:
        feed = Feed.get_feed_from_url(story_url, create=False, fetch=False)
    if not feed:
        parsed_url = urlparse.urlparse(story_url)
        base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.hostname, parsed_url.path)
        feed = Feed.get_feed_from_url(base_url, create=False, fetch=False)
    if not feed:
        feed = Feed.get_feed_from_url(base_url+'/', create=False, fetch=False)
    
    if feed and user:
        try:
            usersub = UserSubscription.objects.filter(user=user, feed=feed)
        except UserSubscription.DoesNotExist:
            usersub = None
    feed_id = feed and feed.pk
    your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(feed_id,
                                              user_id=user_profile.user.pk, story_url=story_url)
    previous_stories = MSharedStory.objects.filter(user_id=user_profile.user.pk).order_by('-shared_date').limit(3)
    previous_stories = [{
        "user_id": story.user_id,
        "story_title": story.story_title,
        "comments": story.comments,
        "shared_date": story.shared_date,
        "relative_date": relative_timesince(story.shared_date),
        "blurblog_permalink": story.blurblog_permalink(),
    } for story in previous_stories]
    
    user_ids = set([user_profile.user.pk])
    for story in same_stories:
        user_ids.add(story['user_id'])
    for story in other_stories:
        user_ids.add(story['user_id'])
    
    users = {}
    profiles = MSocialProfile.profiles(user_ids)
    for profile in profiles:
        users[profile.user_id] = {
            "username": profile.username,
            "photo_url": profile.photo_url,
        }
        
    logging.user(user_profile.user, "~BM~FCChecking share from site: ~SB%s" % (story_url),
                 request=request)
    
    response = HttpResponse(callback + '(' + json.encode({
        'code'              : code,
        'message'           : message,
        'feed'              : feed,
        'subscribed'        : bool(usersub),
        'your_story'        : your_story,
        'same_stories'      : same_stories,
        'other_stories'     : other_stories,
        'previous_stories'  : previous_stories,
        'users'             : users,
    }) + ')', mimetype='text/plain')
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'GET'
    
    return response
开发者ID:adamnemecek,项目名称:NewsBlur,代码行数:82,代码来源:views.py

示例2: check_share_on_site

# 需要导入模块: from apps.social.models import MSharedStory [as 别名]
# 或者: from apps.social.models.MSharedStory import get_shared_stories_from_site [as 别名]
def check_share_on_site(request, token):
    code = 0
    story_url = request.GET["story_url"]
    rss_url = request.GET.get("rss_url")
    callback = request.GET["callback"]
    other_stories = None
    same_stories = None
    usersub = None
    message = None
    user = None

    if not story_url:
        code = -1
    else:
        try:
            user_profile = Profile.objects.get(secret_token=token)
            user = user_profile.user
        except Profile.DoesNotExist:
            code = -1

    feed = Feed.get_feed_from_url(rss_url, create=False, fetch=False)
    if not feed:
        feed = Feed.get_feed_from_url(story_url, create=False, fetch=False)
    if not feed:
        parsed_url = urlparse.urlparse(story_url)
        base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.hostname, parsed_url.path)
        feed = Feed.get_feed_from_url(base_url, create=False, fetch=False)
    if not feed:
        feed = Feed.get_feed_from_url(base_url + "/", create=False, fetch=False)

    if feed and user:
        try:
            usersub = UserSubscription.objects.filter(user=user, feed=feed)
        except UserSubscription.DoesNotExist:
            usersub = None
    feed_id = feed and feed.pk
    your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(
        feed_id, user_id=user_profile.user.pk, story_url=story_url
    )
    previous_stories = MSharedStory.objects.filter(user_id=user_profile.user.pk).order_by("-shared_date").limit(3)
    previous_stories = [
        {
            "user_id": story.user_id,
            "story_title": story.story_title,
            "comments": story.comments,
            "shared_date": story.shared_date,
            "relative_date": relative_timesince(story.shared_date),
            "blurblog_permalink": story.blurblog_permalink(),
        }
        for story in previous_stories
    ]

    user_ids = set([user_profile.user.pk])
    for story in same_stories:
        user_ids.add(story["user_id"])
    for story in other_stories:
        user_ids.add(story["user_id"])

    users = {}
    profiles = MSocialProfile.profiles(user_ids)
    for profile in profiles:
        users[profile.user_id] = {"username": profile.username, "photo_url": profile.photo_url}

    logging.user(user_profile.user, "~BM~FCChecking share from site: ~SB%s" % (story_url), request=request)

    response = HttpResponse(
        callback
        + "("
        + json.encode(
            {
                "code": code,
                "message": message,
                "feed": feed,
                "subscribed": bool(usersub),
                "your_story": your_story,
                "same_stories": same_stories,
                "other_stories": other_stories,
                "previous_stories": previous_stories,
                "users": users,
            }
        )
        + ")",
        mimetype="text/plain",
    )
    response["Access-Control-Allow-Origin"] = "*"
    response["Access-Control-Allow-Methods"] = "GET"

    return response
开发者ID:pabloav,项目名称:NewsBlur,代码行数:90,代码来源:views.py


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