Exemplo n.º 1
0
def load_timeline(request, name, select_id, microblogging_load_type):
    """
    Use this function to get the timeline for the given user.

    Referenced posts will show up in the timeline as the originals do.
    Hiding of the original posts for a tidy
    timeline should be done in the frontend due to performance resons.
    """
    named_user = assert_active_user(name)

    if named_user == request.user:
        followed = Q(author__profile__followers=request.user)
    else:
        followed = Q(author=named_user)
    own = Q(author=named_user)
    if not select_id:  # Get latest posts
        feed = Post.objects.filter(followed | own).\
            order_by('-time').prefetch_related('author', 'is_reference_to')[:20]
        return json_response({
            'loadMicrobloggingResponse': convert_response_list(feed)})
    else:
        if microblogging_load_type == "newer":
            startpoint = Q(id__gt=select_id)
        else:  # older
            startpoint = Q(id__lt=select_id)
        feed = Post.objects.filter(followed | own)
        feed = feed.filter(startpoint).order_by('time')
        feed = feed.prefetch_related('author', 'is_reference_to')[:20]
        return json_response({
            'loadMicrobloggingResponse': convert_response_list(reversed(feed))})
Exemplo n.º 2
0
def load_collection(request, select_id, microblogging_load_type, only_author=False):
    """
    Use this function to get a collection of blogposts regarding nodes
    which are followed by the user.
    """
    if not select_id:  # Get latest posts
        feed = Post.objects.filter(node_references__votes__user=request.user).order_by('-time')
        if only_author:
            feed = feed.filter(node_references__text__authors=request.user)
        feed = feed.prefetch_related('author', 'is_reference_to')[:20]
        return json_response({'loadMicrobloggingResponse': convert_response_list(feed)})
    else:
        if microblogging_load_type == "newer":
            startpoint = Q(id__gt=select_id)
            print("newer, select-id=" + str(select_id))
        else:  # older
            startpoint = Q(id__lt=select_id)
            print("older, select-id=" + str(select_id))
        feed = Post.objects.filter(node_references__votes__user=request.user).filter(startpoint)
        if only_author:
            feed = feed.filter(node_references__text__authors=request.user)
        feed = feed.order_by('time').prefetch_related('author', 'is_reference_to')[:20]
        return json_response({'loadMicrobloggingResponse': convert_response_list(reversed(feed))})
Exemplo n.º 3
0
def load_microblogging(request, path, select_id, microblogging_load_type):
    # TODO refactor and optimize this method
    node = assert_node_for_path(path)
    if not select_id:  # Get latest posts
        posts = list(reversed(node.microblogging_references.order_by('-time').
                              prefetch_related('author', 'is_reference_to')[:20]))
    else:
        if microblogging_load_type == "newer":
            posts = list(node.microblogging_references.filter(id__gt=select_id).
                         order_by('time').prefetch_related('author', 'is_reference_to')[:20])
        else:  # older
            posts = list(reversed(node.microblogging_references.filter(id__lt=select_id).
                                  order_by('-time').prefetch_related('author', 'is_reference_to')[:20]))
    return json_response({
        'loadMicrobloggingResponse': convert_response_list(reversed(posts))})
Exemplo n.º 4
0
def microblogging_response(query, options):
    posts = get_posts(query, options)
    return json_response(
        {'loadMicrobloggingResponse': convert_to_response_list(posts)})
Exemplo n.º 5
0
def microblogging_response(query, options):
    posts = get_posts(query, options)
    return json_response({
        'loadMicrobloggingResponse': convert_to_response_list(posts)})
Exemplo n.º 6
0
def store_microblog_post(request, path):
    assert_authentication(request)
    assert_post_parameters(request, ['microblogText'])
    create_post(request.POST['microblogText'], request.user, path)
    return json_response({'storeMicrobloggingResponse': {}})