コード例 #1
0
ファイル: views.py プロジェクト: aebohlin/touristteddy.com
def post_comment2(request, teddy_id, post_id):
    success = False
    if request.user.is_authenticated():
        post = get_object_or_404(Post, pk=post_id)
        comment = Comment()
        comment.comment = request.POST.get('comment')
        comment.comment_time = datetime.datetime.now()
        comment.post = post
        comment.user = request.user
        comment.save()
        success = True
    return HttpResponse(simplejson.dumps(success), mimetype='application/json')
コード例 #2
0
ファイル: views.py プロジェクト: aebohlin/touristteddy.com
def post_comment(request, teddy_id, post_id):
    request_comment = json.loads(request.body)
    comment = Comment()
    if request.user.is_authenticated():
        post = get_object_or_404(Post, pk=post_id)
        comment.comment = request_comment['comment']
        comment.comment_time = datetime.datetime.now()
        comment.post = post
        comment.user = request.user
        comment.save()

    comment_time_tz_aware = timezone.make_aware(comment.comment_time, timezone.get_default_timezone())
    json_comment = {
        'comment': comment.comment,
        'comment_time': utils.get_friendly_time(comment_time_tz_aware),
        'user_id': comment.user.id,
        'user_name': comment.user.username
    }

    return HttpResponse(json.dumps(json_comment), mimetype='application/json')