def details(request, year, month, slug): if not _is_blog_installed(): return HttpResponseRedirect(reverse('blogango_install')) entry = BlogEntry.objects.get(created_on__year=year, created_on__month=month, slug=slug, is_published=True) if not entry.is_published: raise Http404 if request.method == 'POST': comment_f = bforms.CommentForm(request.POST) if comment_f.is_valid(): comment_by = request.user if request.user.is_authenticated() else None comment = Comment(text=comment_f.cleaned_data['text'], created_by=comment_by, comment_for=entry, user_name=comment_f.cleaned_data['name'], user_url=comment_f.cleaned_data['url'], email_id=comment_f.cleaned_data['email']) if AKISMET_COMMENT: comment.is_spam = check_comment_spam(request, comment) comment.save() return HttpResponseRedirect('.') else: comment_f = bforms.CommentForm() comments = Comment.objects.filter(comment_for=entry, is_spam=False) # tags = Tag.objects.filter(tag_for=entry) payload = {'entry': entry, 'comments': comments, 'comment_form': comment_f} return render('blogango/details.html', request, payload)
def details(request, year, month, slug): if not _is_blog_installed(): return HttpResponseRedirect(reverse('blogango_install')) entry = BlogEntry.default.get(created_on__year=year, created_on__month=month, slug=slug) # published check needs to be handled here to allow previews if not entry.is_published: if request.user.is_staff and 'preview' in request.GET: pass else: raise Http404 if request.method == 'POST': comment_f = bforms.CommentForm(request.POST) if comment_f.is_valid(): comment_by = request.user if request.user.is_authenticated() else None comment = Comment(text=comment_f.cleaned_data['text'], created_by=comment_by, comment_for=entry, user_name=comment_f.cleaned_data['name'], user_url=comment_f.cleaned_data['url'], email_id=comment_f.cleaned_data['email']) comment.is_public = getattr(settings, 'AUTO_APPROVE_COMMENTS', True) if AKISMET_COMMENT: try: comment.is_spam = check_comment_spam(request, comment) except AkismetError: # Most likely could be a timeout to a spam message comment.is_spam = True if not comment.is_spam: request.session["name"] = comment_f.cleaned_data['name'] request.session["email"] = comment_f.cleaned_data['email'] request.session["url"] = comment_f.cleaned_data['url'] comment.save() return HttpResponseRedirect('#comment-%s' % comment.pk) else: init_data = {} if request.user.is_authenticated(): init_data['name'] = request.user.get_full_name() or request.user.username init_data['email'] = request.user.email else: init_data['name'] = request.session.get("name", "") init_data['email'] = request.session.get("email", "") init_data['url'] = request.session.get("url", "") comment_f = bforms.CommentForm(initial=init_data) comments = Comment.objects.filter(comment_for=entry, is_spam=False) reactions = Reaction.objects.filter(comment_for=entry) # tags = Tag.objects.filter(tag_for=entry) payload = {'entry': entry, 'comments': comments, 'reactions': reactions, 'comment_form': comment_f} return render('blogango/details.html', request, payload)
def post(self, *args, **kwargs): self.object = self.get_object() request = self.request context = self.get_context_data(object=self.object) comment_f = bforms.CommentForm(self.request.POST) if comment_f.is_valid(): comment_by = self.request.user if self.request.user.is_authenticated( ) else None comment = Comment(text=comment_f.cleaned_data['text'], created_by=comment_by, comment_for=self.object, user_name=comment_f.cleaned_data['name'], user_url=comment_f.cleaned_data['url'], email_id=comment_f.cleaned_data['email']) comment.is_public = getattr(settings, 'AUTO_APPROVE_COMMENTS', True) comment.user_ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META.get('HTTP_USER_AGENT', '') if AKISMET_COMMENT: try: comment.is_spam = check_comment_spam(self.request, comment) except AkismetError: # Most likely could be a timeout to a spam message comment.is_spam = True if not comment.is_spam: self.request.session["name"] = comment_f.cleaned_data['name'] self.request.session["email"] = comment_f.cleaned_data['email'] self.request.session["url"] = comment_f.cleaned_data['url'] comment.save() return HttpResponseRedirect('#comment-%s' % comment.pk) context.update({'comment_form': comment_f}) return self.render_to_response(context)
def get_context_data(self, **kwargs): context = super(DetailsView, self).get_context_data(**kwargs) init_data = {} if self.request.user.is_authenticated(): init_data['name'] = self.request.user.get_full_name( ) or self.request.user.username init_data['email'] = self.request.user.email else: init_data['name'] = self.request.session.get("name", "") init_data['email'] = self.request.session.get("email", "") init_data['url'] = self.request.session.get("url", "") entry = context['entry'] comment_f = bforms.CommentForm(initial=init_data) comments = Comment.objects.filter(comment_for=entry, is_spam=False) reactions = Reaction.objects.filter(comment_for=entry) payload = { 'comments': comments, 'reactions': reactions, 'comment_form': comment_f } context.update(payload) return context