def create_commet(self, request): data = request.data commnent = Comment( user=request.user, product=product, rate=int(data['rate']), text=data['text'], text_plus=data['text_plus'], text_minus=data['text_minus'], ) commnent.save() return commnent
def setUp(self): self.user = User.objects.all()[0] self.video = Video.objects.all()[0] self.auth = dict(username='******', password='******') self.logged_user = User.objects.get(username=self.auth['username']) l = self.video.subtitle_language() l.language_code = "en" l.save() comment = Comment(content_object=self.video) comment.user = self.logged_user comment.content = "testme" comment.submit_date = datetime.datetime.now() comment.save() self.comment = comment
def comments(request, product_id): product = Product.objects.get(pk=product_id) if request.method == "POST": data = request.POST email, phone = check_phone_email(username=data['username'], request=request) if all(var is None for var in [email, phone]): response = {'msg': 'Введите корректный номер Телефона или Email'} return JsonResponse(response) try: if email: user = CustomUser.objects.get(email=email) elif phone: user = CustomUser.objects.get(phone=phone) except: user = CustomUser.objects.create_user(username=data['username'], data=data, request=request) if isinstance(user, CustomUser) == False: response = {'msg': user} return JsonResponse(response) # SAVE REVIEW review = Comment(parent=product, stars=int(data['stars']), user=user, text=data['text']) review.save() # SAVE IMAGES images = request.FILES.getlist('image') if len(images) > 0: for image in images: reviewImage = CommentImages(parent=review, image_l=image) reviewImage.save() # TELEGRAM # msg = 'Комментарий: ' + variant.get_absolute_url() + '\n' # msg += data['text'] # msg = urllib.parse.quote(msg) # url = "https://api.telegram.org/bot817785032:AAG-Q3s8wRhyZbkoJScSPvE2XDrCVlgZKKA/sendMessage?chat_id=-1001490724377&text=" + msg # contents = urllib.request.urlopen(url).read() response = {'html': ''} return JsonResponse(response)