Esempio n. 1
0
def public_posts(request, post_id=None):
    """Return all posts marked as public on the server.
    If a post_id is specified, only return a single post with the provided id.
    """
    if request.user.is_authenticated():
        if request.method == 'GET':
            try:
                response = utils._get_posts(request, post_id, POST)

                return HttpResponse(json.dumps(response),
                                    content_type='application/json',
                                    status=200)
            except Exception as e:
                return HttpResponse(e.message,
                                    content_type='text/plain',
                                    status=500)

        elif request.method == 'POST' or request.method == 'PUT':
            try:
                post_data = json.loads(request.body)
                response = post_utils.updatePost(post_data)

                return HttpResponse(json.dumps(response),
                                    content_type='application/json',
                                    status=200)
            except Exception as e:
                return HttpResponse(e.message,
                                    content_type='text/plain',
                                    status=500)

    return HttpResponse(status=403)
def public_posts(request, post_id=None):
    """Return all posts marked as public on the server.
    If a post_id is specified, only return a single post with the provided id.
    """
    if request.user.is_authenticated():
        if request.method == 'GET':
            try:
                response = utils._get_posts(request, post_id, POST)

                return HttpResponse(json.dumps(response),
                                    content_type='application/json',
                                    status=200)
            except Exception as e:
                return HttpResponse(e.message,
                                    content_type='text/plain',
                                    status=500)

        elif request.method == 'POST' or request.method == 'PUT':
            try:
                post_data = json.loads(request.body)
                response = post_utils.updatePost(post_data)

                return HttpResponse(json.dumps(response),
                                    content_type='application/json',
                                    status=200)
            except Exception as e:
                return HttpResponse(e.message,
                                    content_type='text/plain',
                                    status=500)

    return HttpResponse(status=403)
def posts(request, author_id=None):
    """Return the posts that are visible to the current authenticated user.
    If author id is specified, only posts for the specified author will be
    returned.
    """

    if request.user.is_authenticated():
        if request.method == 'GET':
            try:
                response = utils._get_posts(request, author_id, AUTHOR)
            except Exception as e:
                return HttpResponse(e.message,
                                    content_type='text/plain',
                                    status=500)
            return HttpResponse(json.dumps(response), content_type='application/json')

    return HttpResponse(status=403)
Esempio n. 4
0
def posts(request, author_id=None):
    """Return the posts that are visible to the current authenticated user.
    If author id is specified, only posts for the specified author will be
    returned.
    """

    if request.user.is_authenticated():
        if request.method == 'GET':
            try:
                response = utils._get_posts(request, author_id, AUTHOR)
            except Exception as e:
                return HttpResponse(e.message,
                                    content_type='text/plain',
                                    status=500)
            return HttpResponse(json.dumps(response),
                                content_type='application/json')

    return HttpResponse(status=403)