Exemple #1
0
 def preview(self):
     comment = super(CommentForm, self).save(commit=False)
     comment.post = self.post
     comment.ip = self.ip
     comment.words = wordify( comment.comment )
     comment.comment = sanitize_html( comment.comment )
     return comment
Exemple #2
0
 def save(self, force_insert=False, force_update=False, commit=True):
     
     comment = super(CommentForm, self).save(commit=False)
     
     comment.post = self.post
     comment.ip = self.ip
     comment.words = wordify( comment.comment )
     comment.comment = sanitize_html( comment.comment )
     
     # check for duplicate comment
     try:
         comment = Comment.objects.get(
             author=comment.author,
             post=comment.post,
             words=comment.words,
             comment=comment.comment,
         )
         # return old comment silently
         return comment
     except Comment.DoesNotExist:
         pass
     
     comment.save()
     
     if BLOG_NOTIFY_NEW_COMMENT:
         context = {
             "comment": strip_tags(comment.comment),
             "author": comment.author,
             "url": comment.post.get_absolute_url(),
             "current_site": Site.objects.get_current(),
         }
         subject = render_to_string('blog/emails/new_comment_subject.txt', context)
         message = render_to_string('blog/emails/new_comment_body.txt', context)
         sender = BLOG_NEW_COMMENT_SENDER
         to = BLOG_NEW_COMMENT_TO
         email = EmailMessage( subject, message, sender, [to] )
         email.send()
     
     return comment