本文整理汇总了Python中apps.social.models.MSharedStory类的典型用法代码示例。如果您正苦于以下问题:Python MSharedStory类的具体用法?Python MSharedStory怎么用?Python MSharedStory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MSharedStory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: story_public_comments
def story_public_comments(request):
format = request.REQUEST.get('format', 'json')
relative_user_id = request.REQUEST.get('user_id', None)
feed_id = int(request.REQUEST['feed_id'])
story_id = request.REQUEST['story_id']
if not relative_user_id:
relative_user_id = get_user(request).pk
stories = MSharedStory.objects.filter(story_feed_id=feed_id, story_guid=story_id).limit(1)
stories = Feed.format_stories(stories)
stories, profiles = MSharedStory.stories_with_comments_and_profiles(stories, relative_user_id,
check_all=True,
public=True)
if format == 'html':
stories = MSharedStory.attach_users_to_stories(stories, profiles)
return render_to_response('social/story_comments.xhtml', {
'story': stories[0],
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'comments': stories[0]['public_comments'],
'user_profiles': profiles,
})
示例2: run
def run(self, **kwargs):
logging.debug(" ---> Finding spammers...")
_, spammer_user_ids = MSharedStory.count_potential_spammers()
logging.debug(" ---> Found %s spammers, deleting..." % len(spammer_user_ids))
for user_id in spammer_user_ids:
user = User.objects.get(pk=user_id)
user.profile.delete_user(confirm=True, fast=True)
logging.debug(" ---> Sharing popular stories...")
MSharedStory.share_popular_stories(interactive=False)
示例3: forwards
def forwards(self, orm):
from apps.rss_feeds.models import MStarredStory
from apps.social.models import MSharedStory
db = settings.MONGODB
starred_count = MStarredStory.objects.count()
print " ---> Saving %s starred stories..." % starred_count
shared_count = MSharedStory.objects.count()
print " ---> Saving %s shared stories..." % shared_count
start = 0
user_count = User.objects.latest('pk').pk
for user_id in xrange(start, user_count):
if user_id % 1000 == 0:
print " ---> %s/%s" % (user_id, user_count)
stories = MStarredStory.objects(user_id=user_id, story_hash__exists=False)\
.only('id', 'story_feed_id', 'story_guid')\
.read_preference(
pymongo.ReadPreference.SECONDARY
)
for i, story in enumerate(stories):
db.newsblur.starred_stories.update({"_id": story.id}, {"$set": {
"story_hash": story.feed_guid_hash
}})
stories = MSharedStory.objects(user_id=user_id, story_hash__exists=False)\
.only('id', 'user_id', 'story_feed_id', 'story_guid')\
.read_preference(
pymongo.ReadPreference.SECONDARY
)
for i, story in enumerate(stories):
db.newsblur.shared_stories.update({"_id": story.id}, {"$set": {
"story_hash": story.feed_guid_hash
}})
示例4: remove_like_comment
def remove_like_comment(request):
code = 1
feed_id = int(request.POST['story_feed_id'])
story_id = request.POST['story_id']
comment_user_id = request.POST['comment_user_id']
format = request.REQUEST.get('format', 'json')
shared_story = MSharedStory.objects.get(user_id=comment_user_id,
story_feed_id=feed_id,
story_guid=story_id)
shared_story.remove_liking_user(request.user.pk)
comment, profiles = shared_story.comment_with_author_and_profiles()
comment_user = User.objects.get(pk=shared_story.user_id)
logging.user(request, "~BB~FMRemoving like on comment by ~SB%s~SN: %s" % (
comment_user.username,
shared_story.comments[:30],
))
if format == 'html':
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response('social/story_comment.xhtml', {
'comment': comment,
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'code': code,
'comment': comment,
'user_profiles': profiles,
})
示例5: mark_story_as_unshared
def mark_story_as_unshared(request):
feed_id = int(request.POST['feed_id'])
story_id = request.POST['story_id']
format = request.REQUEST.get('format', 'json')
original_story_found = True
story = MStory.objects(story_feed_id=feed_id, story_guid=story_id).limit(1).first()
if not story:
original_story_found = False
shared_story = MSharedStory.objects(user_id=request.user.pk,
story_feed_id=feed_id,
story_guid=story_id).limit(1).first()
if not shared_story:
return json.json_response(request, {'code': -1, 'message': 'Shared story not found.'})
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=request.user.pk)
for socialsub in socialsubs:
socialsub.needs_unread_recalc = True
socialsub.save()
logging.user(request, "~FC~SKUn-sharing ~FM%s: ~SB~FB%s" % (shared_story.story_title[:20],
shared_story.comments[:30]))
shared_story.delete()
if original_story_found:
story.count_comments()
else:
story = shared_story
story = Feed.format_story(story)
stories, profiles = MSharedStory.stories_with_comments_and_profiles([story],
request.user.pk,
check_all=True)
if format == 'html':
stories = MSharedStory.attach_users_to_stories(stories, profiles)
return render_to_response('social/story_share.xhtml', {
'story': stories[0],
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'code': 1,
'message': "Story unshared.",
'story': stories[0],
'user_profiles': profiles,
})
示例6: mark_story_as_unshared
def mark_story_as_unshared(request):
feed_id = int(request.POST["feed_id"])
story_id = request.POST["story_id"]
relative_user_id = request.POST.get("relative_user_id") or request.user.pk
format = request.REQUEST.get("format", "json")
original_story_found = True
story = MStory.objects(story_feed_id=feed_id, story_guid=story_id).limit(1).first()
if not story:
original_story_found = False
shared_story = (
MSharedStory.objects(user_id=request.user.pk, story_feed_id=feed_id, story_guid=story_id).limit(1).first()
)
if not shared_story:
return json.json_response(request, {"code": -1, "message": "Shared story not found."})
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=request.user.pk)
for socialsub in socialsubs:
socialsub.needs_unread_recalc = True
socialsub.save()
logging.user(
request, "~FC~SKUn-sharing ~FM%s: ~SB~FB%s" % (shared_story.story_title[:20], shared_story.comments[:30])
)
shared_story.delete()
if original_story_found:
story.count_comments()
else:
story = shared_story
story = Feed.format_story(story)
stories, profiles = MSharedStory.stories_with_comments_and_profiles([story], relative_user_id, check_all=True)
if format == "html":
stories = MSharedStory.attach_users_to_stories(stories, profiles)
return render_to_response(
"social/social_story.xhtml", {"story": stories[0]}, context_instance=RequestContext(request)
)
else:
return json.json_response(
request, {"code": 1, "message": "Story unshared.", "story": stories[0], "user_profiles": profiles}
)
示例7: story_public_comments
def story_public_comments(request):
format = request.REQUEST.get("format", "json")
relative_user_id = request.REQUEST.get("user_id", None)
feed_id = int(request.REQUEST["feed_id"])
story_id = request.REQUEST["story_id"]
if not relative_user_id:
relative_user_id = get_user(request).pk
stories = MSharedStory.objects.filter(story_feed_id=feed_id, story_guid=story_id).limit(1)
stories = Feed.format_stories(stories)
stories, profiles = MSharedStory.stories_with_comments_and_profiles(
stories, relative_user_id, check_all=True, public=True
)
if format == "html":
stories = MSharedStory.attach_users_to_stories(stories, profiles)
return render_to_response(
"social/story_comments.xhtml", {"story": stories[0]}, context_instance=RequestContext(request)
)
else:
return json.json_response(request, {"comments": stories[0]["public_comments"], "user_profiles": profiles})
示例8: like_comment
def like_comment(request):
code = 1
feed_id = int(request.POST['story_feed_id'])
story_id = request.POST['story_id']
comment_user_id = request.POST['comment_user_id']
format = request.REQUEST.get('format', 'json')
if comment_user_id == request.user.pk:
return json.json_response(request, {'code': -1, 'message': 'You cannot favorite your own shared story comment.'})
shared_story = MSharedStory.objects.get(user_id=comment_user_id,
story_feed_id=feed_id,
story_guid=story_id)
shared_story.add_liking_user(request.user.pk)
comment, profiles = shared_story.comment_with_author_and_profiles()
comment_user = User.objects.get(pk=shared_story.user_id)
logging.user(request, "~BB~FMLiking comment by ~SB%s~SN: %s" % (
comment_user.username,
shared_story.comments[:30],
))
MActivity.new_comment_like(liking_user_id=request.user.pk,
comment_user_id=comment['user_id'],
story_id=story_id,
story_title=shared_story.story_title,
comments=shared_story.comments)
MInteraction.new_comment_like(liking_user_id=request.user.pk,
comment_user_id=comment['user_id'],
story_id=story_id,
story_title=shared_story.story_title,
comments=shared_story.comments)
if format == 'html':
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response('social/story_comment.xhtml', {
'comment': comment,
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'code': code,
'comment': comment,
'user_profiles': profiles,
})
示例9: like_comment
def like_comment(request):
code = 1
feed_id = int(request.POST["story_feed_id"])
story_id = request.POST["story_id"]
comment_user_id = request.POST["comment_user_id"]
format = request.REQUEST.get("format", "json")
if comment_user_id == request.user.pk:
return json.json_response(
request, {"code": -1, "message": "You cannot favorite your own shared story comment."}
)
shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
shared_story.add_liking_user(request.user.pk)
comment, profiles = shared_story.comment_with_author_and_profiles()
comment_user = User.objects.get(pk=shared_story.user_id)
logging.user(request, "~BB~FMLiking comment by ~SB%s~SN: %s" % (comment_user.username, shared_story.comments[:30]))
MActivity.new_comment_like(
liking_user_id=request.user.pk,
comment_user_id=comment["user_id"],
story_id=story_id,
story_title=shared_story.story_title,
comments=shared_story.comments,
)
MInteraction.new_comment_like(
liking_user_id=request.user.pk,
comment_user_id=comment["user_id"],
story_id=story_id,
story_title=shared_story.story_title,
comments=shared_story.comments,
)
if format == "html":
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response(
"social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
)
else:
return json.json_response(request, {"code": code, "comment": comment, "user_profiles": profiles})
示例10: remove_like_comment
def remove_like_comment(request):
code = 1
feed_id = int(request.POST["story_feed_id"])
story_id = request.POST["story_id"]
comment_user_id = request.POST["comment_user_id"]
format = request.REQUEST.get("format", "json")
shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
shared_story.remove_liking_user(request.user.pk)
comment, profiles = shared_story.comment_with_author_and_profiles()
comment_user = User.objects.get(pk=shared_story.user_id)
logging.user(
request, "~BB~FMRemoving like on comment by ~SB%s~SN: %s" % (comment_user.username, shared_story.comments[:30])
)
if format == "html":
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response(
"social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
)
else:
return json.json_response(request, {"code": code, "comment": comment, "user_profiles": profiles})
示例11: check_share_on_site
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
示例12: remove_comment_reply
def remove_comment_reply(request):
code = 1
feed_id = int(request.POST['story_feed_id'])
story_id = request.POST['story_id']
comment_user_id = request.POST['comment_user_id']
reply_id = request.POST.get('reply_id')
format = request.REQUEST.get('format', 'json')
original_message = None
shared_story = MSharedStory.objects.get(user_id=comment_user_id,
story_feed_id=feed_id,
story_guid=story_id)
replies = []
for story_reply in shared_story.replies:
if ((story_reply.user_id == request.user.pk or request.user.is_staff) and
story_reply.reply_id == ObjectId(reply_id)):
original_message = story_reply.comments
# Skip reply
else:
replies.append(story_reply)
shared_story.replies = replies
shared_story.save()
logging.user(request, "~FCRemoving comment reply in ~FM%s: ~SB~FB%s~FM" % (
shared_story.story_title[:20], original_message and original_message[:30]))
comment, profiles = shared_story.comment_with_author_and_profiles()
# Interaction for every other replier and original commenter
MActivity.remove_comment_reply(user_id=request.user.pk,
comment_user_id=comment['user_id'],
reply_content=original_message,
story_id=story_id,
story_feed_id=feed_id)
MInteraction.remove_comment_reply(user_id=comment['user_id'],
reply_user_id=request.user.pk,
reply_content=original_message,
story_id=story_id,
story_feed_id=feed_id)
reply_user_ids = [reply['user_id'] for reply in comment['replies']]
for user_id in set(reply_user_ids).difference([comment['user_id']]):
if request.user.pk != user_id:
MInteraction.remove_reply_reply(user_id=user_id,
comment_user_id=comment['user_id'],
reply_user_id=request.user.pk,
reply_content=original_message,
story_id=story_id,
story_feed_id=feed_id)
if format == 'html':
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response('social/story_comment.xhtml', {
'comment': comment,
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'code': code,
'comment': comment,
'user_profiles': profiles
})
示例13: save_comment_reply
def save_comment_reply(request):
code = 1
feed_id = int(request.POST['story_feed_id'])
story_id = request.POST['story_id']
comment_user_id = request.POST['comment_user_id']
reply_comments = request.POST.get('reply_comments')
reply_id = request.POST.get('reply_id')
format = request.REQUEST.get('format', 'json')
original_message = None
if not reply_comments:
return json.json_response(request, {'code': -1, 'message': 'Reply comments cannot be empty.'})
shared_story = MSharedStory.objects.get(user_id=comment_user_id,
story_feed_id=feed_id,
story_guid=story_id)
reply = MCommentReply()
reply.user_id = request.user.pk
reply.publish_date = datetime.datetime.now()
reply.comments = reply_comments
if reply_id:
replies = []
for story_reply in shared_story.replies:
if (story_reply.user_id == reply.user_id and
story_reply.reply_id == ObjectId(reply_id)):
reply.publish_date = story_reply.publish_date
reply.reply_id = story_reply.reply_id
original_message = story_reply.comments
replies.append(reply)
else:
replies.append(story_reply)
shared_story.replies = replies
logging.user(request, "~FCUpdating comment reply in ~FM%s: ~SB~FB%s~FM" % (
shared_story.story_title[:20], reply_comments[:30]))
else:
reply.reply_id = ObjectId()
logging.user(request, "~FCReplying to comment in: ~FM%s: ~SB~FB%s~FM" % (
shared_story.story_title[:20], reply_comments[:30]))
shared_story.replies.append(reply)
shared_story.save()
comment, profiles = shared_story.comment_with_author_and_profiles()
# Interaction for every other replier and original commenter
MActivity.new_comment_reply(user_id=request.user.pk,
comment_user_id=comment['user_id'],
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title)
if comment['user_id'] != request.user.pk:
MInteraction.new_comment_reply(user_id=comment['user_id'],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title)
reply_user_ids = list(r['user_id'] for r in comment['replies'])
for user_id in set(reply_user_ids).difference([comment['user_id']]):
if request.user.pk != user_id:
MInteraction.new_reply_reply(user_id=user_id,
comment_user_id=comment['user_id'],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title)
EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id,
reply_id=reply.reply_id), countdown=60)
if format == 'html':
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response('social/story_comment.xhtml', {
'comment': comment,
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'code': code,
'comment': comment,
'reply_id': reply.reply_id,
'user_profiles': profiles
})
示例14: save_comment_reply
def save_comment_reply(request):
code = 1
feed_id = int(request.POST["story_feed_id"])
story_id = request.POST["story_id"]
comment_user_id = request.POST["comment_user_id"]
reply_comments = request.POST.get("reply_comments")
reply_id = request.POST.get("reply_id")
format = request.REQUEST.get("format", "json")
original_message = None
if not reply_comments:
return json.json_response(request, {"code": -1, "message": "Reply comments cannot be empty."})
shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
reply = MCommentReply()
reply.user_id = request.user.pk
reply.publish_date = datetime.datetime.now()
reply.comments = reply_comments
if reply_id:
replies = []
for story_reply in shared_story.replies:
if story_reply.user_id == reply.user_id and story_reply.reply_id == ObjectId(reply_id):
reply.publish_date = story_reply.publish_date
reply.reply_id = story_reply.reply_id
original_message = story_reply.comments
replies.append(reply)
else:
replies.append(story_reply)
shared_story.replies = replies
logging.user(
request,
"~FCUpdating comment reply in ~FM%s: ~SB~FB%s~FM" % (shared_story.story_title[:20], reply_comments[:30]),
)
else:
reply.reply_id = ObjectId()
logging.user(
request,
"~FCReplying to comment in: ~FM%s: ~SB~FB%s~FM" % (shared_story.story_title[:20], reply_comments[:30]),
)
shared_story.replies.append(reply)
shared_story.save()
comment, profiles = shared_story.comment_with_author_and_profiles()
# Interaction for every other replier and original commenter
MActivity.new_comment_reply(
user_id=request.user.pk,
comment_user_id=comment["user_id"],
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title,
)
if comment["user_id"] != request.user.pk:
MInteraction.new_comment_reply(
user_id=comment["user_id"],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title,
)
reply_user_ids = list(r["user_id"] for r in comment["replies"])
for user_id in set(reply_user_ids).difference([comment["user_id"]]):
if request.user.pk != user_id:
MInteraction.new_reply_reply(
user_id=user_id,
comment_user_id=comment["user_id"],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title,
)
EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id, reply_id=reply.reply_id), countdown=60)
if format == "html":
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response(
"social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
)
else:
return json.json_response(
request, {"code": code, "comment": comment, "reply_id": reply.reply_id, "user_profiles": profiles}
)
示例15: load_social_stories
def load_social_stories(request, user_id, username=None):
start = time.time()
user = get_user(request)
social_user_id = int(user_id)
social_user = get_object_or_404(User, pk=social_user_id)
offset = int(request.REQUEST.get('offset', 0))
limit = int(request.REQUEST.get('limit', 6))
page = request.REQUEST.get('page')
order = request.REQUEST.get('order', 'newest')
read_filter = request.REQUEST.get('read_filter', 'all')
stories = []
if page: offset = limit * (int(page) - 1)
now = localtime_for_timezone(datetime.datetime.now(), user.profile.timezone)
UNREAD_CUTOFF = datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD)
social_profile = MSocialProfile.get_user(social_user.pk)
try:
socialsub = MSocialSubscription.objects.get(user_id=user.pk, subscription_user_id=social_user_id)
except MSocialSubscription.DoesNotExist:
socialsub = None
mstories = MSharedStory.objects(user_id=social_user.pk).order_by('-shared_date')[offset:offset+limit]
stories = Feed.format_stories(mstories)
if socialsub and (read_filter == 'unread' or order == 'oldest'):
story_ids = socialsub.get_stories(order=order, read_filter=read_filter, offset=offset, limit=limit)
story_date_order = "%sshared_date" % ('' if order == 'oldest' else '-')
if story_ids:
mstories = MSharedStory.objects(user_id=social_user.pk,
story_db_id__in=story_ids).order_by(story_date_order)
stories = Feed.format_stories(mstories)
else:
mstories = MSharedStory.objects(user_id=social_user.pk).order_by('-shared_date')[offset:offset+limit]
stories = Feed.format_stories(mstories)
if not stories:
return dict(stories=[])
checkpoint1 = time.time()
stories, user_profiles = MSharedStory.stories_with_comments_and_profiles(stories, user.pk, check_all=True)
story_feed_ids = list(set(s['story_feed_id'] for s in stories))
usersubs = UserSubscription.objects.filter(user__pk=user.pk, feed__pk__in=story_feed_ids)
usersubs_map = dict((sub.feed_id, sub) for sub in usersubs)
unsub_feed_ids = list(set(story_feed_ids).difference(set(usersubs_map.keys())))
unsub_feeds = Feed.objects.filter(pk__in=unsub_feed_ids)
unsub_feeds = [feed.canonical(include_favicon=False) for feed in unsub_feeds]
date_delta = UNREAD_CUTOFF
if socialsub and date_delta < socialsub.mark_read_date:
date_delta = socialsub.mark_read_date
# Get intelligence classifier for user
classifier_feeds = list(MClassifierFeed.objects(user_id=user.pk, social_user_id=social_user_id))
classifier_authors = list(MClassifierAuthor.objects(user_id=user.pk, social_user_id=social_user_id))
classifier_titles = list(MClassifierTitle.objects(user_id=user.pk, social_user_id=social_user_id))
classifier_tags = list(MClassifierTag.objects(user_id=user.pk, social_user_id=social_user_id))
# Merge with feed specific classifiers
classifier_feeds = classifier_feeds + list(MClassifierFeed.objects(user_id=user.pk, feed_id__in=story_feed_ids))
classifier_authors = classifier_authors + list(MClassifierAuthor.objects(user_id=user.pk, feed_id__in=story_feed_ids))
classifier_titles = classifier_titles + list(MClassifierTitle.objects(user_id=user.pk, feed_id__in=story_feed_ids))
classifier_tags = classifier_tags + list(MClassifierTag.objects(user_id=user.pk, feed_id__in=story_feed_ids))
checkpoint2 = time.time()
story_ids = [story['id'] for story in stories]
userstories_db = MUserStory.objects(user_id=user.pk,
feed_id__in=story_feed_ids,
story_id__in=story_ids).only('story_id')
userstories = set(us.story_id for us in userstories_db)
starred_stories = MStarredStory.objects(user_id=user.pk,
story_feed_id__in=story_feed_ids,
story_guid__in=story_ids).only('story_guid', 'starred_date')
shared_stories = MSharedStory.objects(user_id=user.pk,
story_feed_id__in=story_feed_ids,
story_guid__in=story_ids)\
.only('story_guid', 'shared_date', 'comments')
starred_stories = dict([(story.story_guid, story.starred_date) for story in starred_stories])
shared_stories = dict([(story.story_guid, dict(shared_date=story.shared_date, comments=story.comments))
for story in shared_stories])
for story in stories:
story['social_user_id'] = social_user_id
story_feed_id = story['story_feed_id']
# story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
shared_date = localtime_for_timezone(story['shared_date'], user.profile.timezone)
story['short_parsed_date'] = format_story_link_date__short(shared_date, now)
story['long_parsed_date'] = format_story_link_date__long(shared_date, now)
if not socialsub:
story['read_status'] = 1
elif story['id'] in userstories:
story['read_status'] = 1
elif story['shared_date'] < date_delta:
story['read_status'] = 1
elif not usersubs_map.get(story_feed_id):
story['read_status'] = 0
elif not story.get('read_status') and story['story_date'] < usersubs_map[story_feed_id].mark_read_date:
story['read_status'] = 1
#.........这里部分代码省略.........