def save(self, request):
        """
        Saves a new comment and sends any notification emails.
        """
        comment = self.get_comment_object()
        obj = comment.content_object
        if request.user.is_authenticated():
            comment.user = request.user
        comment.by_author = request.user == getattr(obj, "user", None)
        comment.ip_address = ip_for_request(request)
        comment.replied_to_id = self.data.get("replied_to")

        # YaCms's duplicate check that also checks `replied_to_id`.
        lookup = {
            "content_type": comment.content_type,
            "object_pk": comment.object_pk,
            "user_name": comment.user_name,
            "user_email": comment.user_email,
            "user_url": comment.user_url,
            "replied_to_id": comment.replied_to_id,
        }
        for duplicate in self.get_comment_model().objects.filter(**lookup):
            if (duplicate.submit_date.date() == comment.submit_date.date() and
                    duplicate.comment == comment.comment):
                return duplicate

        comment.save()
        comment_was_posted.send(sender=comment.__class__, comment=comment,
                                request=request)
        notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
        if notify_emails:
            subject = ugettext("New comment for: ") + str(obj)
            context = {
                "comment": comment,
                "comment_url": add_cache_bypass(comment.get_absolute_url()),
                "request": request,
                "obj": obj,
            }
            send_mail_template(subject, "email/comment_notification",
                               settings.DEFAULT_FROM_EMAIL, notify_emails,
                               context)
        return comment
def save ( self , request ) : comment = self . get_comment_object ( ) obj = comment . content_object if request . user . is_authenticated ( ) : comment . user = request . user comment . by_author = request . user == getattr ( obj , "user" , None ) comment . ip_address = ip_for_request ( request ) comment . replied_to_id = self . data . get ( "replied_to" ) lookup = { "content_type" : comment . content_type , "object_pk" : comment . object_pk , "user_name" : comment . user_name , "user_email" : comment . user_email , "user_url" : comment . user_url , "replied_to_id" : comment . replied_to_id , } for duplicate in self . get_comment_model ( ) . objects . filter ( ** lookup ) : if ( duplicate . submit_date . date ( ) == comment . submit_date . date ( ) and duplicate . comment == comment . comment ) : return duplicate comment . save ( ) comment_was_posted . send ( sender = comment . __class__ , comment = comment , request = request ) notify_emails = split_addresses ( settings . COMMENTS_NOTIFICATION_EMAILS ) if notify_emails : subject = ugettext ( "New comment for: " ) + str ( obj ) context = { "comment" : comment , "comment_url" : add_cache_bypass ( comment . get_absolute_url ( ) ) , "request" : request , "obj" : obj , } send_mail_template ( subject , "email/comment_notification" , settings . DEFAULT_FROM_EMAIL , notify_emails , context ) return comment
Saves a new comment and sends any notification emails.