def post_detail(request, id_): post = Post.objects.get(id=id_) rel_post = Post.objects.order_by('-date_posted').filter( tag=post.tag, for_cooperative__exact=False).all() if request.method == 'POST': content = str(request.POST.get('content', False)) if content: comment = Comment() comment.author_id = request.user.id comment.author_status = author_status(request.user.id) comment.date_posted = timezone.now() comment.content = content comment.post = post comment.save() return redirect('/post/' + str(id_) + '/') else: return render(request, 'post/post_detail.html', { 'post': post, 'related': rel_post }) return render(request, 'post/post_detail.html', { 'post': post, 'related': rel_post })
def add_comment_to_post(request, slug): post = get_object_or_404(Post, slug=slug) if request.method == "POST": comment = Comment() comment.text = request.POST.get("commentBox") comment.post = post comment.comment_user = request.user comment.save() return redirect('post:postlist') else: return redirect('post:postlist')
def save(self): post = self.initial["post"] user = self.initial["user"] parent_object = self.initial["parent_object"] new_comment = Comment() new_comment.comment = self.cleaned_data["comment"] new_comment.post = post new_comment.user = user new_comment.object_id = parent_object.id new_comment.content_type = ContentType.objects.get_for_model(parent_object) new_comment.is_active = True new_comment.activation_code = 0 new_comment.save()
def save(self): post = self.initial["post"] user = self.initial["user"] parent_object = self.initial["parent_object"] new_comment = Comment() new_comment.comment = self.cleaned_data["comment"] new_comment.post = post new_comment.user = user new_comment.object_id = parent_object.id new_comment.content_type = ContentType.objects.get_for_model( parent_object) new_comment.is_active = True new_comment.activation_code = 0 new_comment.save()
def save(self): parent_object = self.initial["parent_object"] email = self.cleaned_data["email"] post = self.initial["post"] random_int = random.random()*9999 activation_code = hashlib.sha224("%s:%s"%(email,random_int)).hexdigest()[:50] print activation_code new_comment = Comment() new_comment.comment = self.cleaned_data["comment"] new_comment.email = email new_comment.post = post new_comment.activation_code = activation_code new_comment.object_id = parent_object.id new_comment.content_type = ContentType.objects.get_for_model(parent_object) new_comment.is_active = False new_comment.save() send_comment_activation_mail.delay(activation_code, email)
def add_comment(request, post_id): post = get_object_or_404(Post, id=post_id) if request.method == 'POST': user = request.POST['name'] name = request.POST['name'] email = request.POST['email'] text = request.POST['text'] newComment = Comment(user=user, name=name, email=email, text=text, post=post) newComment.post = post newComment.save() messages.success(request, 'Comment added') return redirect(reverse('post_details', kwargs={"post_id": post_id}))
def save(self): parent_object = self.initial["parent_object"] email = self.cleaned_data["email"] post = self.initial["post"] random_int = random.random() * 9999 activation_code = hashlib.sha224("%s:%s" % (email, random_int)).hexdigest()[:50] print activation_code new_comment = Comment() new_comment.comment = self.cleaned_data["comment"] new_comment.email = email new_comment.post = post new_comment.activation_code = activation_code new_comment.object_id = parent_object.id new_comment.content_type = ContentType.objects.get_for_model( parent_object) new_comment.is_active = False new_comment.save() send_comment_activation_mail.delay(activation_code, email)
def post_detail_view(request, slug): post = get_object_or_404(Post, slug=slug) post_tags_ids = Tag.objects.all().values_list('id', flat=True) related_posts = Post.objects.filter(status='same_tags').filter( tags__in=post_tags_ids).exclude(slug=post.slug) related_posts = related_posts.annotate(same_tags=Count('tags')).order_by( '-same_tags', '-created')[:4] comments = post.comments.filter(active=True).order_by('-created') category = Category.objects.all() feature = Post.objects.filter(is_featured=True).order_by('-created') if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): body = form.cleaned_data.get('body') new_comment = Comment( body=body, user=request.user, ) new_comment.post = post new_comment.save() return redirect('post-detail', slug=post.slug) else: form = CommentForm() context = { 'post': post, 'related_posts': related_posts, 'feature': feature, 'category': category, 'form': form, 'comments': comments, } return render(request, 'post/detail_page.html', context)