예제 #1
0
def comment_create(request, slug):
    try:
        item = Item.objects.get(slug=slug)
    except Item.MultipleObjectsReturned:
        item = item.objects.filter(slug=slug).last()
    except Item.DoesNotExist:
        item = None
    if request.method == 'POST':
        if request.user.is_authenticated and request.user.is_customer():
            response_data = {}
            data = request.POST['comment']
            comment = Comment()
            comment.comment = data
            comment.fiscal_year = FiscalYear.get_active_fiscal_year()
            comment.item = item
            comment.user = request.user
            comment.save()

            response_data['result'] = 'Create post successful!'
            response_data['postpk'] = str(comment.pk)
            response_data['comment'] = str(comment.comment)
            response_data['created'] = str(comment.created_at)
            response_data['image'] = str(request.user.userprofile.pic)
            response_data['author'] = str(comment.user.full_name)
            return JsonResponse(response_data)
    else:
        return JsonResponse({'data': 'hello owrld'})
예제 #2
0
    def form_valid(seld, form):
        post = self.get_object()
        comment = Comment(**form.cleaned_data)
        comment.comment = post

        if self.request.user.is_authenticated:
            comment.author = self.request.user

        comment.save()
        messages.success(self.request, 'Comment sent successfully.')
        return redirect('post_single', id=post.id)
예제 #3
0
def newComment(request):
    nickname=request.COOKIES['nickname']
    accessToken=request.COOKIES['accessToken']
    if authenticate(nickname, accessToken):
        comment=Comment()
        commenter=CubeUser.objects.get(nickname=nickname)
        comment.commenter=commenter
        comment.comment=request.POST['comment']
        id=request.POST['viz']
        viz=Viz.objects.get(pk=id)
        comment.viz=viz
        comment.save()
        response='{ "status":"ok", "nickname":"%s"}' % nickname            
    else: 
       response='{ "status":"error", "error":"user is not authenticated"}'       
    return HttpResponse(response, content_type="application/json")
예제 #4
0
def newComment(request):
    nickname = request.COOKIES['nickname']
    accessToken = request.COOKIES['accessToken']
    if authenticate(nickname, accessToken):
        comment = Comment()
        commenter = CubeUser.objects.get(nickname=nickname)
        comment.commenter = commenter
        comment.comment = request.POST['comment']
        id = request.POST['viz']
        viz = Viz.objects.get(pk=id)
        comment.viz = viz
        comment.save()
        response = '{ "status":"ok", "nickname":"%s"}' % nickname
    else:
        response = '{ "status":"error", "error":"user is not authenticated"}'
    return HttpResponse(response, content_type="application/json")