0

we are using django-contrib-comments in are project for communication between stuff and clients. Staff communication work's internally and I've made a custom email notification system which will notify you every time some other stuff member left a comment on your page.

Now the problem that I'm facing is that the user who want's to reply to a comment will only notify it's self and not the staff member who left a comment.

Email notification setup is made of two parts, first part is for the staff member who is leaving a comment and second is for the user who is replying to the comment.

Problem is how to refer to the user who all ready left a comment, I need his email, so I could add him to the recipient list so he will be notify when someone else replies to the comment.

comment.user and comment.user_email are things on which you refer on the comment model, but I can not find how to refer to user_email who's all ready left a comment when you want to reply to it, this part of the documentation explain model fields, I can understand that

user_email - The email of the user who posted the comment.

and it is perfect in the first part, but in the second it will refer to the user who is leaving a comment and that is why the other one will not be notified, so can someone please help me better understand how to refer to the user_email on which I'm replying, so I can make it work properly.

def send_comment_posted_emails(self, comment):
    comment_user = comment.user
    comment_user_email = comment.user_email
    comment_text = comment.comment
    handler_user = self.account_handler
    handler_email = handler_user.email

    # First part
    if handler_email is not None and handler_email != comment_user.email:
        current_site = Site.objects.get_current()
        sub_org_url = self.get_view_url() + "#CommentsDiv"
        ctx = {"sub_org_url": sub_org_url, "site_name": current_site.name, "sub_org_sn": self.serial_number,
               "posted_name": user_util.get_user_full_name_or_user_name(comment_user),
               "comment_text": comment_text}
        subject = render_to_string("clients/emails/email_sub_org_comment_posted_subject.txt", ctx)
        subject = "".join(subject.splitlines())
        message = render_to_string("clients/emails/email_sub_org_comment_posted_message.html", ctx)

        MailManager.send_mail_with_error_handler(subject, message, settings.DEFAULT_FROM_EMAIL,
                                                 [handler_email, comment_user_email], message_html=message)

    # Second part
    if handler_email is not None and handler_email == comment_user.email:
        current_site = Site.objects.get_current()
        sub_org_url = self.get_view_url() + "#CommentsDiv"
        ctx = {"sub_org_url": sub_org_url, "site_name": current_site.name, "sub_org_sn": self.serial_number,
               "posted_name": user_util.get_user_full_name_or_user_name(comment_user),
               "comment_text": comment_text}
        subject = render_to_string("clients/emails/reply_to_email_sub_org_comment_posted_subject.txt", ctx)
        subject = "".join(subject.splitlines())
        message = render_to_string("clients/emails/reply_to_email_sub_org_comment_posted_message.html", ctx)

        MailManager.send_mail_with_error_handler(subject, message, settings.DEFAULT_FROM_EMAIL,
                                                 [handler_email, comment_user_email], message_html=message)
copser
  • 2,523
  • 5
  • 38
  • 73

1 Answers1

0

I found that django-contrib-comments are now composed/divided out in two separate libraries,

  1. django-fluent-comments
  2. django-threadedcomments

so in the threadedcomments there is a parent model field on which you can related when you are replying to a comment so, I've just made something like comment.parent.user_email and I've checked if parent is defined, and not None, and problem solved.

copser
  • 2,523
  • 5
  • 38
  • 73