本文整理汇总了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
示例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