コード例 #1
0
def _get_posts(request, id, type):
    if type == AUTHOR:
        viewer = []
        if (request.user.username != ''):
            viewer = Author.objects.filter(user=request.user)
        if len(viewer) > 0:
            viewer = viewer[0]
        else:
            viewer = None

        if id is not None:
            author = Author.objects.filter(uuid=id)
            if len(author) > 0:
                author = author[0]
            else:
                return {'posts': []}
            posts = post_utils.getVisibleToAuthor(viewer=viewer,
                                                  author=author,
                                                  localOnly=True)
        else:
            posts = post_utils.getVisibleToAuthor(viewer=viewer,
                                                  localOnly=True)

    else:
        if id is not None:
            post = post_utils.getPostById(id)
            if post is not None:
                return post.getJsonObj()
            else:
                return {}
        else:
            posts = post_utils.getVisibleToAuthor(localOnly=True)

    return {'posts': posts}
コード例 #2
0
def _get_posts(request, id, type):
    if type == AUTHOR:
        viewer = []
        if(request.user.username != ''):
            viewer = Author.objects.filter(user=request.user)
        if len(viewer) > 0:
            viewer = viewer[0]
        else:
            viewer = None

        if id is not None:
            author = Author.objects.filter(uuid=id)
            if len(author) > 0:
                author = author[0]
            else:
                return {'posts': []}
            posts = post_utils.getVisibleToAuthor(viewer=viewer, author=author, localOnly=True)
        else:
            posts = post_utils.getVisibleToAuthor(viewer=viewer, localOnly=True)

    else:
        if id is not None:
            post = post_utils.getPostById(id)
            if post is not None:
                return post.getJsonObj()
            else:
                return {}
        else:
            posts = post_utils.getVisibleToAuthor(localOnly=True)

    return {'posts': posts}
コード例 #3
0
def taggedPosts(request, tag):
    context = RequestContext(request)

    if request.method == 'GET':
        try:
            if request.user.is_authenticated():
                postList = []
                viewer = Author.objects.get(user=request.user)
                posts = post_utils.getVisibleToAuthor(viewer)
                taggedPosts = PostCategory.getPostWithCategory(tag)

                for categorizedPost in taggedPosts:
                    jsonPost = post_utils.get_post_json(categorizedPost.post)
                    if jsonPost in posts:
                        postList.append(jsonPost)

                context['posts'] = _getDetailedPosts(postList)
                context['visibility'] = post_utils.getVisibilityTypes()
                context['page_header'] = 'Posts tagged as %s' % tag
                context['specific'] = True

                return render_to_response('index.html', context)
        except Exception as e:
            print "Error in posts: %s" % e

    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
コード例 #4
0
def _getAllPosts(viewer, postAuthor=None, time_line=False, remoteOnly=False):
    data = {}

    if remoteOnly:
        post_list = remote_helper.api_getPostByAuthorID(viewer, postAuthor)
        print(len(post_list))
    else:
        post_list = post_utils.getVisibleToAuthor(viewer=viewer,
                                                  author=postAuthor,
                                                  time_line=time_line)
        if viewer is not None:
            post_list.extend(_get_github_events(viewer))

    data['posts'] = _getDetailedPosts(post_list)
    data['visibility'] = post_utils.getVisibilityTypes()

    return data