コード例 #1
0
ファイル: views.py プロジェクト: ashur-k/New_Django_project
def addcomment(request, id):
    category = Category.objects.all()
    product = Product.objects.get(pk=id)
    images = Images.objects.filter(product_id=id)
    comments = Comment.objects.filter(product_id=id, status='True')

    url = request.META.get('HTTP_REFERER')  # get last url
    # return HttpResponse(url)
    if request.method == 'POST':  # check post
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()  # create relation with model
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()  # save data to table
            messages.success(request, "Your review has ben sent.")

    context = {
        'product': product,
        'category': category,
        'images': images,
        'comments': comments,
    }

    return render(request, 'product_detail.html', context)
コード例 #2
0
 def post(self, request, pk):
     product = get_object_or_404(Product, id=pk)
     comment = Comment(text=request.POST['comment'],
                       owner=request.user,
                       product=product)
     comment.save()
     return redirect(reverse('products:product_detail', args=[pk]))
コード例 #3
0
def addcomment(request,id):
    url = request.META.get('HTTP_REFERER') #get last url
    if request.method == 'POST':
        data = Comment()  # create relation with model
        data.subject = request.POST.get('subject')
        data.comment = request.POST.get('comment')
        data.rate = request.POST.get('rate')
        data.ip = request.META.get('REMOTE_ADDR')
        data.product_id=id
        current_user= request.user
        data.user_id=current_user.id
        data.save()  # save data to table
        messages.success(request, "Your review has ben sent. Thank you for your interest.")
        return HttpResponseRedirect(url)
コード例 #4
0
def addcoment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()
            messages.success(request, "Your review has been sent.")
            return HttpResponseRedirect(url)
    return HttpResponseRedirect(url)
コード例 #5
0
ファイル: views.py プロジェクト: ovibinzia1885/smartEcom
def Comment_Add(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        pos = CommenttForm(request.POST)
        if pos.is_valid():
            data = Comment()
            data.subject = pos.cleaned_data['subject']
            data.comment = pos.cleaned_data['comment']
            data.rate = pos.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()
            messages.success(request, 'Your informative comment has been sent')
            return HttpResponseRedirect(url)
    return HttpResponseRedirect(url)
コード例 #6
0
def create_comment(body, rating, customer_id, product_id):
    customer = Customer.objects.get(pk=customer_id)
    product = Product.objects.get(pk=product_id)

    new_comment = Comment(product=product, customer=customer)
    new_comment.timestamp = timezone.now()
    new_comment.body = body

    rating_types = {v: k for k, v in dict(new_comment.RATES).items()}
    new_comment.rating = rating_types[rating]

    # exit()
    # customer.comment_set.add(new_comment)

    # product.comment_set.get(new_comment)
    new_comment.save()
    return new_comment
コード例 #7
0
ファイル: views.py プロジェクト: Daouda46/e_shop
def comment(request, id):
    url = request.META.get('HTTP_REFERER')  # Le dernier url
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.produit_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()
            messages.success(request, 'votre avis compte')
            return HttpResponseRedirect(url)

    return HttpResponseRedirect(url)
コード例 #8
0
ファイル: views.py プロジェクト: nataliakushnir/steelkiwi
def single_product(request, slug):
    product = Product.objects.get(slug=slug)
    start_date = datetime.datetime.now() - datetime.timedelta(days=1)
    end_date = start_date + datetime.timedelta(days=1)
    if request.POST:
        comment = Comment()
        comment.product = Product.objects.get(slug=slug)
        if len(request.POST.get("text", )) != 0:
            comment.text = request.POST.get("text", )
            comment.save()
            messages.success(request, 'Your comment added!')
        else:
            messages.error(request, 'Comment`s field can`t be blank!')
    form = CommentForm()
    comments = Comment.objects.filter(product=product, date_time__range=[start_date, end_date]).order_by('-date_time')
    return render(request, 'product.html', {'product': product,
                                            'comments': comments,
                                            'form': form,
                                            })
コード例 #9
0
ファイル: views.py プロジェクト: saurya3d/django-shopping
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')  # get last url
    # return HttpResponse(url)
    if request.method == 'POST':  # check post
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()  # create relation with model
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()  # save data to table
            messages.success(request, "Your review has ben sent. Thank you for your interest.")
            return HttpResponseRedirect(url)

    return HttpResponseRedirect(url)
コード例 #10
0
ファイル: views.py プロジェクト: SEKAPLAN/DjangoMysite1
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user
            data = Comment()
            data.user_id = current_user.id
            data.produce_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(
                request, "Yorumunuz başarı ile göndeilmiştir.TEŞEKKÜR EDERİZ.")
            return HttpResponseRedirect(url)
    messages.warning(request,
                     "Yorumunuz Kaydedilemedi.Lütfen kontrol ediniz!!!")
    return HttpResponseRedirect(url)
コード例 #11
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    # return HttpResponse(url)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()
            data.subject = form.cleaned_data['subject'],
            data.comment = form.cleaned_data['comment'],
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()
            messages.success(request,
                             "your message is sent . Thank you For Message")
            return HttpResponseRedirect(url)
        else:
            messages.warning(request, "something is wrong")
    return HttpResponseRedirect(url)
コード例 #12
0
ファイル: views.py プロジェクト: zduranel/Python-Arac-Ticaret
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user

            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.email = form.cleaned_data['email']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(request, "Yorum Gönderildi")

            return HttpResponseRedirect(url)
    messages.warning(request, "Yorum Gönderilemedi !  ")
    return HttpResponseRedirect(url)
コード例 #13
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')  # get last url
    # return HttpResponse(url)
    if request.method == 'POST':  # check post
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()  # create relation with model
            data.name = form.cleaned_data['name']
            data.email = form.cleaned_data['email']
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()  # save data to table
            messages.success(request, "پیام شما با موفقیت ارسال شد.")
            return HttpResponseRedirect(url)

    return HttpResponseRedirect(url)
コード例 #14
0
ファイル: views.py プロジェクト: NurUcar/DjangoProje
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        form = CommentFrom(request.POST)
        if form.is_valid():
            current_user = request.user  # Access User session info
            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(
                request,
                "Yorumunuz başarı ile gönderilmiştir. Teşekkür Ederiz..")
            return HttpResponseRedirect('/')
        messages.warning("Yorumunuz Gönderilemedi. Lütfen kontrol ediniz..")
    return HttpResponseRedirect(url)
コード例 #15
0
def addcomment(request,id):
        url = request.META.get('HTTP_REFERER')  # en son url'e dönüş yapmak için
        if request.method=='POST':
            form =CommentForm(request.POST)
            if form.is_valid():
                current_user = request.user

                data = Comment()
                data.user_id = current_user.id
                data.product_id = id
                data.subject = form.cleaned_data['subject'] #fields
                data.comment = form.cleaned_data['comment']
                data.rate = form.cleaned_data['rate']
                data.ip = request.META.get('REMOTE_ADDR')
                data.save()
                messages.success(request,"Yorumunuz başarıyla Gönderilmiştir. Teşekkür ederiz..")

                return HttpResponseRedirect(url)
        messages.warning(request,'Yorum Gönderilmedi')
        return HttpResponseRedirect(url)
コード例 #16
0
def addcomment(request, id):
    url = request.META.get("HTTP_REFERER")
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user

            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(request, "Yorumunuz başarıyla gönderilmiştir.")
            return HttpResponseRedirect(url)

    messages.warning(request,
                     "Yorumunuz gönderilemedi. Lütfen puan belirtiniz.")
    return HttpResponseRedirect(url)
コード例 #17
0
ファイル: views.py プロジェクト: ibrohimyakubov/Kitoblar.uz
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')  #get last url
    #return HttpResponse(url)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()  # create relation with model
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()  # save data to table
            messages.success(
                request,
                "Sizning kommentariyangiz yuborildi,qiziqish uchun rahmat!")
            return HttpResponseRedirect(url)

    return HttpResponseRedirect(url)
コード例 #18
0
def addcomment(request, id):

    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        print(request)
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user
            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(request, 'Yorum Başarılı')
            return HttpResponseRedirect(url)

    messages.warning(request, "Yorum Kaydedilemedi.")
    return HttpResponseRedirect(url)
コード例 #19
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')  # get last url
    if request.method == 'POST':  # form post edildiyse
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user  # Access User Session information
            data = Comment()  # model ile bağlantı kur
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get(
                'REMOTE_ADDR')  # Client computer ip address
            data.save()  # veritabanına kaydet
            messages.success(
                request,
                "Yorumunuz başarı ile gönderilmiştir. Teşekkür Ederiz")
            return HttpResponseRedirect(url)
            #return HttpResponse("Kaydedildi")
    messages.warning(request, "Yorumunuz kaydedilmedi. Lütfen kontrol ediniz")
    return HttpResponseRedirect(url)
コード例 #20
0
ファイル: views.py プロジェクト: keniiy/Django-Ecommerce
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    #return HttpResponse(url)
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = CommentForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            data = Comment()  #create relation with model
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip_address = request.META['REMOTE_ADDR']
            data.product_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()  #save data to table
            messages.success(
                request, "Your Review has been sent. Thanks for Reviewing")
            return HttpResponseRedirect(url)
    return HttpResponseRedirect(url)
コード例 #21
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')

    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user
            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(
                request,
                "Yorumunuz alınmıştır. Görüşleriniz için teşekkkür ederiz")
            return HttpResponseRedirect(url)

    messages.warning(request,
                     "Yorumunuz kaydedilmedi. Lütfen tekrar deneyiniz.")
    return HttpResponseRedirect(url)
コード例 #22
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')  # get last url
    if request.method == 'POST':  # form post edildiyse
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user

            data = Comment()  # model ile bağlantı kur
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(
                request,
                "Yorumunuz başarı ile gönderilmiştir.Teşekkür Ederiz.")

            return HttpResponseRedirect(url)
    messages.warning(request, "Yorumunuz gönderilememiştir tekrar deneyiniz.")
    return HttpResponseRedirect(url)
コード例 #23
0
ファイル: views.py プロジェクト: yagizoral/Ozel-2
def addcomment(request,id):
     url = request.META.get('HTTP_REFERER')
     if request.method == 'POST': #POST EDİLDİYSE
         form = CommentForm(request.POST)
         if form.is_valid():
             current_user=request.user#access user session information

             data = Comment()
             data.user_id = current_user.id
             data.product_id = id
             data.subject = form.cleaned_data['subject']
             data.comment = form.cleaned_data['comment']
            #data.rate = form.cleaned_data['rate']
             data.ip = request.META.get('REMOTE_ADDR')
             data.save()#veritabanına kaydet

             messages.success(request, "yorum gönderildi saolun")


             return HttpResponseRedirect(url)

     messages.warning(request, "yorum gönderilemedi lan bişey bozuk")
     return HttpResponseRedirect(url)
コード例 #24
0
def addcomment(request, id):
    url = request.META.get(
        "HTTP_REFERER"
    )  # get last url yani post edilen url (yorum yazılan yer)
    if request.method == 'POST':  # form post edildiyse
        form = CommentForm(request.POST)
        if form.is_valid():  # form geçerli ise
            current_user = request.user  #user bilgisini aldık
            data = Comment()  # model ile bağlantı kur
            data.user_id = current_user.id
            data.car_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')  #pc id alıyoruz
            data.save()  # veritabanına kaydet
            messages.success(
                request,
                "Yorumunuz başarı ile gönderilmişitir.Teşekkür ederiz")

            return HttpResponseRedirect(url)
    messages.warning(request, "Yorumunuz kaydedilemedi.")
    return HttpResponseRedirect(url)
コード例 #25
0
def addcomment(request, id):
    url = request.META.get(
        'HTTP_REFERER')  # mesaj gittikten sonra olduğumuz yere dönmek için
    if request.method == 'POST':  # form post edildiyse
        form = CommentForm(request.POST)
        if form.is_valid():  # form geldi mi gelmedi mi kontrol eder
            current_user = request.user  # login olan userı getirir

            data = Comment()  # model ile bağlantı kur
            data.user_id = current_user.id
            data.product_id = id
            data.rate = form.cleaned_data['rate']
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.ip = request.META.get(
                'REMOTE_ADDR')  # client computer ip adress
            data.save()  # veritabanını kaydet

            messages.success(
                request, "Yorumunuz başarı ile gönderilmiştir.Teşekkür ederiz")
            return HttpResponseRedirect(url)
    messages.error(request, "Yorumunuz kaydedilmedi.Lütfen kontrol ediniz!")
    return HttpResponseRedirect(url)
コード例 #26
0
ファイル: views.py プロジェクト: cagatayygumuss/DjangoProjem
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':  #form post edildiyse
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user

            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(
                request,
                "Yorumunuz başarı ile gerçekleştirilmiştir. Teşekkür ederiz")

            return HttpResponseRedirect(url)

    messages.warning(request, "Yorumunuz kaydedilmedi. Lütfen kontrol ediniz")
    return HttpResponseRedirect(url)
コード例 #27
0
ファイル: views.py プロジェクト: kubraaysesosun/DjangoProje
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user  #Access User Session Information

            data = Comment()  #model ile bağlantı kur
            data.user_id = current_user.id
            data.pictures_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']  #formdan bilgiyi al
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()  #veritabanına kaydet
            messages.success(
                request,
                'Yorumunuz başarıyla gönderilmiştir. Teşekkür ederiz...')

            return HttpResponseRedirect(url)

    messages.warning(request,
                     "Yorumunuz kaydedilmedi. Lütfen kontrol ediniz..")
    return HttpResponseRedirect(url)
コード例 #28
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':  #form post edildiyse demek
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user
            data = Comment()  #model ile bağlantı kuruyor
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            # data.rate = form.changed_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(
                request,
                "Yorumunuz başarı ile gönderilmiştir, Teşekkür Ederiz")

            return HttpResponseRedirect(url)

        messages.warning(request,
                         "Yorumunuz Kaydedilmedi. Lütfen Kontrol Ediniz!")
        # return HttpResponse("Kaydedilme İşlemi Gerçekleşmedi")
        return HttpResponseRedirect(url)
コード例 #29
0
ファイル: views.py プロジェクト: reeplayed/AltaStore-backend
def add_comment(request):
    data = request.data
    comment = Comment(content=data['comment'], author=request.user, product=Product.objects.get(id=data['id']), rating=data['rate'])
    comment.save()
    return Response({'new_comment': CommentSerializer(comment).data})