Exemplo n.º 1
0
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,
        })
Exemplo n.º 2
0
Arquivo: views.py Projeto: 76/NewsBlur
def api_user_info(request):
    user = request.user
    
    return json.json_response(request, {"data": {
        "name": user.username,
        "id": user.pk,
    }})
Exemplo n.º 3
0
def api_user_info(request):
    user = request.user
    
    return json.json_response(request, {"data": {
        "name": user.username,
        "id": user.pk,
    }})
Exemplo n.º 4
0
def load_activities(request):
    user_id = request.REQUEST.get("user_id", None)
    if user_id:
        user_id = int(user_id)
        user = User.objects.get(pk=user_id)
    else:
        user = get_user(request)
        user_id = user.pk

    public = user_id != request.user.pk
    page = max(1, int(request.REQUEST.get("page", 1)))
    limit = request.REQUEST.get("limit", 4)
    activities, has_next_page = MActivity.user(user_id, page=page, limit=limit, public=public)
    format = request.REQUEST.get("format", None)

    data = {
        "activities": activities,
        "page": page,
        "has_next_page": has_next_page,
        "username": (user.username if public else "You"),
    }

    if format == "html":
        return render_to_response("reader/activities_module.xhtml", data, context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
Exemplo n.º 5
0
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,
        })
Exemplo n.º 6
0
def load_activities(request):
    user_id = request.REQUEST.get('user_id', None)
    if user_id:
        user_id = int(user_id)
        user = User.objects.get(pk=user_id)
    else:
        user = get_user(request)
        user_id = user.pk
        
    public = user_id != request.user.pk
    page = max(1, int(request.REQUEST.get('page', 1)))
    limit = request.REQUEST.get('limit', 4)
    activities, has_next_page = MActivity.user(user_id, page=page, limit=limit, public=public)
    format = request.REQUEST.get('format', None)
    
    data = {
        'activities': activities,
        'page': page,
        'has_next_page': has_next_page,
        'username': (user.username if public else 'You'),
    }
    
    if format == 'html':
        return render_to_response('reader/activities_module.xhtml', data,
                                  context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
Exemplo n.º 7
0
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,
        })
Exemplo n.º 8
0
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,
        })
Exemplo n.º 9
0
def api_user_info(request):
    user = request.user
    
    if user.is_anonymous():
        return HttpResponse(content="{}", status=401)
    
    return json.json_response(request, {"data": {
        "name": user.username,
        "id": user.pk,
    }})
Exemplo n.º 10
0
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}
        )
Exemplo n.º 11
0
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})
Exemplo n.º 12
0
def load_interactions(request):
    user_id = request.REQUEST.get("user_id", None)
    if not user_id:
        user_id = get_user(request).pk
    page = max(1, int(request.REQUEST.get("page", 1)))
    limit = request.REQUEST.get("limit")
    interactions, has_next_page = MInteraction.user(user_id, page=page, limit=limit)
    format = request.REQUEST.get("format", None)

    data = {"interactions": interactions, "page": page, "has_next_page": has_next_page}

    if format == "html":
        return render_to_response("reader/interactions_module.xhtml", data, context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
Exemplo n.º 13
0
def load_interactions(request):
    user_id = request.REQUEST.get('user_id', None)
    if not user_id:
        user_id = get_user(request).pk
    page = max(1, int(request.REQUEST.get('page', 1)))
    limit = request.REQUEST.get('limit')
    interactions, has_next_page = MInteraction.user(user_id, page=page, limit=limit)
    format = request.REQUEST.get('format', None)
    
    data = {
        'interactions': interactions,
        'page': page,
        'has_next_page': has_next_page
    }
    
    if format == 'html':
        return render_to_response('reader/interactions_module.xhtml', data,
                                  context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
Exemplo n.º 14
0
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})
Exemplo n.º 15
0
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})
Exemplo n.º 16
0
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})
Exemplo n.º 17
0
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
        })
Exemplo n.º 18
0
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
        })
Exemplo n.º 19
0
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}
        )
Exemplo n.º 20
0
def mark_story_as_shared(request):
    code = 1
    feed_id = int(request.POST["feed_id"])
    story_id = request.POST["story_id"]
    comments = request.POST.get("comments", "")
    source_user_id = request.POST.get("source_user_id")
    relative_user_id = request.POST.get("relative_user_id") or request.user.pk
    post_to_services = request.POST.getlist("post_to_services")
    format = request.REQUEST.get("format", "json")

    MSocialProfile.get_user(request.user.pk)

    story, original_story_found = MStory.find_story(feed_id, story_id)

    if not story:
        return json.json_response(
            request, {"code": -1, "message": "Could not find the original story and no copies could be found."}
        )

    shared_story = (
        MSharedStory.objects.filter(user_id=request.user.pk, story_feed_id=feed_id, story_guid=story_id)
        .limit(1)
        .first()
    )
    if not shared_story:
        story_db = dict([(k, v) for k, v in story._data.items() if k is not None and v is not None])
        story_values = dict(
            user_id=request.user.pk, comments=comments, has_comments=bool(comments), story_db_id=story.id
        )
        story_db.update(story_values)
        shared_story = MSharedStory.objects.create(**story_db)
        if source_user_id:
            shared_story.set_source_user_id(int(source_user_id))
        socialsubs = MSocialSubscription.objects.filter(subscription_user_id=request.user.pk)
        for socialsub in socialsubs:
            socialsub.needs_unread_recalc = True
            socialsub.save()
        logging.user(request, "~FCSharing ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30]))
    else:
        shared_story.comments = comments
        shared_story.has_comments = bool(comments)
        shared_story.save()
        logging.user(request, "~FCUpdating shared story ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30]))

    if original_story_found:
        story.count_comments()
    shared_story.publish_update_to_subscribers()

    story = Feed.format_story(story)
    check_all = not original_story_found
    stories, profiles = MSharedStory.stories_with_comments_and_profiles([story], relative_user_id, check_all=check_all)
    story = stories[0]
    story["shared_comments"] = strip_tags(shared_story["comments"] or "")
    story["shared_by_user"] = True

    if post_to_services:
        for service in post_to_services:
            if service not in shared_story.posted_to_services:
                PostToService.delay(shared_story_id=shared_story.id, service=service)

    if shared_story.source_user_id and shared_story.comments:
        EmailStoryReshares.apply_async(
            kwargs=dict(shared_story_id=shared_story.id), countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS
        )

    if format == "html":
        stories = MSharedStory.attach_users_to_stories(stories, profiles)
        return render_to_response(
            "social/social_story.xhtml", {"story": story}, context_instance=RequestContext(request)
        )
    else:
        return json.json_response(request, {"code": code, "story": story, "user_profiles": profiles})
Exemplo n.º 21
0
def mark_story_as_shared(request):
    code     = 1
    feed_id  = int(request.POST['feed_id'])
    story_id = request.POST['story_id']
    comments = request.POST.get('comments', '')
    source_user_id = request.POST.get('source_user_id')
    post_to_services = request.POST.getlist('post_to_services')
    format = request.REQUEST.get('format', 'json')
    
    MSocialProfile.get_user(request.user.pk)
    
    story, original_story_found = MStory.find_story(feed_id, story_id)

    if not story:
        return json.json_response(request, {
            'code': -1, 
            'message': 'Could not find the original story and no copies could be found.'
        })
    
    shared_story = MSharedStory.objects.filter(user_id=request.user.pk, 
                                               story_feed_id=feed_id, 
                                               story_guid=story_id).limit(1).first()
    if not shared_story:
        story_db = dict([(k, v) for k, v in story._data.items() 
                                if k is not None and v is not None])
        story_values = dict(user_id=request.user.pk, comments=comments, 
                            has_comments=bool(comments), story_db_id=story.id)
        story_db.update(story_values)
        shared_story = MSharedStory.objects.create(**story_db)
        if source_user_id:
            shared_story.set_source_user_id(int(source_user_id))
        socialsubs = MSocialSubscription.objects.filter(subscription_user_id=request.user.pk)
        for socialsub in socialsubs:
            socialsub.needs_unread_recalc = True
            socialsub.save()
        logging.user(request, "~FCSharing ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30]))
    else:
        shared_story.comments = comments
        shared_story.has_comments = bool(comments)
        shared_story.save()
        logging.user(request, "~FCUpdating shared story ~FM%s: ~SB~FB%s" % (
                     story.story_title[:20], comments[:30]))
    
    if original_story_found:
        story.count_comments()
    shared_story.publish_update_to_subscribers()
    
    story = Feed.format_story(story)
    check_all = not original_story_found
    stories, profiles = MSharedStory.stories_with_comments_and_profiles([story], request.user.pk,
                                                                        check_all=check_all)
    story = stories[0]
    story['shared_comments'] = strip_tags(shared_story['comments'] or "")
    
    if post_to_services:
        for service in post_to_services:
            if service not in shared_story.posted_to_services:
                PostToService.delay(shared_story_id=shared_story.id, service=service)
    
    if shared_story.source_user_id and shared_story.comments:
        EmailStoryReshares.apply_async(kwargs=dict(shared_story_id=shared_story.id), countdown=60)
    
    if format == 'html':
        stories = MSharedStory.attach_users_to_stories(stories, profiles)
        return render_to_response('social/story_share.xhtml', {
            'story': story,
        }, context_instance=RequestContext(request))
    else:
        return json.json_response(request, {
            'code': code, 
            'story': story, 
            'user_profiles': profiles,
        })