def destroy(request, id): user = request.user p = Post.objects.filter(id=id) if p and p[0].user == user: p[0].delete() response = jsonize_post(p[0]) else: rq = reverse(destroy, kwargs={'id':id}) response = dict(request=rq, error="That's not yours.") return HttpResponse(json.dumps(response), mimetype='application/json')
def update(request): user = request.user status = request.POST['status'] post = uapi.new_post(user, status) return HttpResponse(json.dumps(jsonize_post(post)), mimetype='application/json')
def show(request, id): post = jsonize_post(Post.objects.get(id=id)) return HttpResponse(json.dumps(post), mimetype='application/json')
def public_timeline(request): posts = uapi.public_timeline(paginated=False)[:20] posts = [jsonize_post(i) for i in posts] return HttpResponse(json.dumps(posts), mimetype='application/json')
def friends_timeline(request, username): posts = uapi.friends_timeline(username)[:20] posts = [jsonize_post(i) for i in posts] return HttpResponse(json.dumps(posts), mimetype='application/json')
def replies(request): posts = get_replies(request)[:20] posts = [jsonize_post(i) for i in posts] return HttpResponse(json.dumps(posts), mimetype='application/json')
def user_timeline(request, username): posts = uapi.user_timeline(username, paginated=False)[:20] posts = [jsonize_post(i) for i in posts] return HttpResponse(json.dumps(posts), mimetype='application/json')