Exemple #1
0
    def email_notify_admins_complaint_created(self, request):
        """Send Notification to the Platform Admins."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        for admin_name, admin_email in settings.ADMINS:
            # -----------------------------------------------------------------
            # --- Render HTML Email Content
            greetings = _(
                "Dear, %(user)s.") % {
                    "user":     admin_name,
                }
            htmlbody = _(
                "<p>Member \"<a href=\"%(profile)s\">%(member)s</a>\" has reported Complaint to %(subject)s \"<a href=\"%(url)s\">%(name)s</a>\" with the following:</p>"
                "<p>%(text)s</p>"
                "<p>Please, don\'t forget to take some Action.</p>") % {
                    "user":     admin_name,
                    "member":   self.user.get_full_name(),
                    "profile":  self.user.profile.public_url(request),
                    "subject":  self.content_type.name.capitalize(),
                    "url":      self.content_object.public_url(request),
                    "name":     self.content_object.name,
                    "text":     self.text,
                }

            # -----------------------------------------------------------------
            # --- Send Email
            send_templated_email(
                template_subj={
                    "name":     "common/emails/complaint_created_adm_subject.txt",
                    "context":  {},
                },
                template_text={
                    "name":     "common/emails/complaint_created_adm.txt",
                    "context":  {
                        "user":     self.user.get_full_name(),
                        "profile":  self.user.profile.public_url(request),
                        "subject":  self.content_type.name.capitalize(),
                        "url":      self.content_object.public_url(request),
                        "name":     self.content_object.name,
                        "text":     self.text,
                    },
                },
                template_html={
                    "name":     "emails/base.html",
                    "context":  {
                        "greetings":    greetings,
                        "htmlbody":     htmlbody,
                    },
                },
                from_email=settings.EMAIL_SENDER,
                to=[
                    admin_email,
                ],
                headers=None,
            )
Exemple #2
0
    def email_notify_invitee_inv_created(self, request):
        """Send Notification to the Invitee."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        # ---------------------------------------------------------------------
        # --- Render HTML Email Content
        greetings = _("Dear, %(user)s.") % {
            "user": self.invitee.first_name,
        }
        htmlbody = _(
            "<p>Member \"<a href=\"%(profile)s\">%(member)s</a>\" has invited you to %(subject)s \"<a href=\"%(url)s\">%(name)s</a>\" with the following:</p>"
            "<p>%(text)s</p>"
            "<p>Please, don\'t forget to accept, or reject Invitation.</p>"
        ) % {
            "profile": self.inviter.profile.public_url(request),
            "member": self.inviter.get_full_name(),
            "subject": self.content_type.name.capitalize(),
            "url": self.content_object.public_url(request),
            "name": self.content_object.name,
            "text": self.invitation_text,
        }

        # ---------------------------------------------------------------------
        # --- Send Email
        send_templated_email(
            template_subj={
                "name": "invites/emails/invite_created_usr_subject.txt",
                "context": {},
            },
            template_text={
                "name": "invites/emails/invite_created_usr.txt",
                "context": {
                    "user": self.invitee.first_name,
                    "profile": self.inviter.profile.public_url(request),
                    "member": self.inviter.get_full_name(),
                    "subject": self.content_type.name.capitalize(),
                    "url": self.content_object.public_url(request),
                    "name": self.content_object.name,
                    "text": self.invitation_text,
                },
            },
            template_html={
                "name": "emails/base.html",
                "context": {
                    "greetings": greetings,
                    "htmlbody": htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.invitee.email,
            ],
            headers=None,
        )
Exemple #3
0
    def email_notify_admin_org_newsletter_created(self,
                                                  request=None,
                                                  newsletter=None):
        """Send Notification to the Organization Admin."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        if not newsletter:
            return

        # ---------------------------------------------------------------------
        # --- Render HTML Email Content
        greetings = _("Dear, %(user)s.") % {
            "user": self.author.first_name,
        }
        htmlbody = _(
            "<p>The Organization\'s \"<a href=\"%(url)s\">%(name)s</a>\" Newsletter with the Title \"%(title)s\", was successfully created and populated.</p>"
        ) % {
            "url": self.public_url(request),
            "name": self.name,
            "title": newsletter.title,
        }

        # ---------------------------------------------------------------------
        # --- Send Email
        send_templated_email(
            template_subj={
                "name":
                "organizations/emails/organization_newsletter_admin_subject.txt",
                "context": {},
            },
            template_text={
                "name":
                "organizations/emails/organization_newsletter_admin.txt",
                "context": {
                    "admin": self.author,
                    "organization": self,
                    "organization_link": self.public_url(request),
                    "newsletter": newsletter,
                },
            },
            template_html={
                "name": "emails/base.html",
                "context": {
                    "greetings": greetings,
                    "htmlbody": htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.author.email,
            ],
            headers=None,
        )
Exemple #4
0
    def email_notify_newsletter_populate(self, request=None, newsletter=None):
        """Populate Newsletter among Organization's Subscribers."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        for subscriber in self.subscribers.all():
            newsletter.recipients.add(subscriber)

            # -----------------------------------------------------------------
            # --- Render HTML Email Content
            greetings = _(
                "The \"<a href=\"%(url)s\">%(name)s</a>\" Newsletter:<br/>\"%(title)s\""
            ) % {
                "name": self.name,
                "url": self.public_url(request),
                "title": newsletter.title,
            }
            htmlbody = _(
                "<p>%(content)s<br/>You have received this Email, because you're subscribed to the Organization's Newsletters and Activity Notifications.</p>"
            ) % {
                "content": newsletter.content,
            }

            # -----------------------------------------------------------------
            # --- Send Email
            send_templated_email(
                template_subj={
                    "name":
                    "organizations/emails/organization_newsletter_subject.txt",
                    "context": {},
                },
                template_text={
                    "name": "organizations/emails/organization_newsletter.txt",
                    "context": {
                        "user": subscriber,
                        "organization": self,
                        "organization_link": self.public_url(request),
                        "newsletter": newsletter,
                    },
                },
                template_html={
                    "name": "emails/base.html",
                    "context": {
                        "greetings": greetings,
                        "htmlbody": htmlbody,
                    },
                },
                from_email=settings.EMAIL_SENDER,
                to=[
                    subscriber.email,
                ],
                headers=None,
            )
Exemple #5
0
    def email_notify_alt_person_org_modified(self, request=None):
        """Send Notification to the Organization alternative Contact Person."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        if not self.is_alt_person:
            return

        # ---------------------------------------------------------------------
        # --- Render HTML Email Content
        greetings = _("Dear, %(user)s.") % {
            "user": self.alt_person_fullname,
        }
        htmlbody = _(
            "<p>The Organization \"<a href=\"%(url)s\">%(name)s</a>\", were you added as a Contact Person, was modified!.</p>"
        ) % {
            "url": self.public_url(request),
            "name": self.name,
        }

        # ---------------------------------------------------------------------
        # --- Send Email
        send_templated_email(
            template_subj={
                "name":
                "organizations/emails/organization_modified_subject.txt",
                "context": {},
            },
            template_text={
                "name": "organizations/emails/organization_modified_alt.txt",
                "context": {
                    "user": self.alt_person_fullname,
                    "organization": self,
                    "organization_link": self.public_url(request),
                },
            },
            template_html={
                "name": "emails/base.html",
                "context": {
                    "greetings": greetings,
                    "htmlbody": htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.alt_person_email,
            ],
            headers=None,
        )
Exemple #6
0
    def email_notify_inviter_inv_revoked(self, request):
        """Send Notification to the Inviter."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        # ---------------------------------------------------------------------
        # --- Render HTML Email Content
        greetings = _("Dear, %(user)s.") % {
            "user": self.inviter.first_name,
        }
        htmlbody = _(
            "<p>You revoked your Invitation of Member \"<a href=\"%(profile)s\">%(member)s</a>\" to %(subject)s \"<a href=\"%(url)s\">%(name)s</a>\"!</p>"
        ) % {
            "profile": self.invitee.profile.public_url(request),
            "member": self.invitee.get_full_name(),
            "subject": self.content_type.name.capitalize(),
            "url": self.content_object.public_url(request),
            "name": self.content_object.name,
        }

        # ---------------------------------------------------------------------
        # --- Send Email
        send_templated_email(
            template_subj={
                "name": "invites/emails/invite_revoked_adm_subject.txt",
                "context": {},
            },
            template_text={
                "name": "invites/emails/invite_revoked_adm.txt",
                "context": {
                    "invite": self,
                    "profile_link": self.invitee.profile.public_url(request),
                    "subject_link": self.content_object.public_url(request),
                },
            },
            template_html={
                "name": "emails/base.html",
                "context": {
                    "greetings": greetings,
                    "htmlbody": htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.inviter.email,
            ],
            headers=None,
        )
Exemple #7
0
    def email_notify_admin_org_modified(self, request=None):
        """Send Notification to the Organization Admin."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        # ---------------------------------------------------------------------
        # --- Render HTML Email Content
        greetings = _("Dear, %(user)s.") % {
            "user": self.author.first_name,
        }
        htmlbody = _(
            "<p>Your Organization \"<a href=\"%(url)s\">%(name)s</a>\" was modified.</p>"
        ) % {
            "url": self.public_url(request),
            "name": self.name,
        }

        # ---------------------------------------------------------------------
        # --- Send Email
        send_templated_email(
            template_subj={
                "name":
                "organizations/emails/organization_modified_subject.txt",
                "context": {},
            },
            template_text={
                "name": "organizations/emails/organization_modified.txt",
                "context": {
                    "admin": self.author,
                    "organization": self,
                    "organization_link": self.public_url(request),
                },
            },
            template_html={
                "name": "emails/base.html",
                "context": {
                    "greetings": greetings,
                    "htmlbody": htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.author.email,
            ],
            headers=None,
        )
Exemple #8
0
    def email_notify_password_changed(self, request=None, url=None):
        """Send Notification to the User."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        # ---------------------------------------------------------------------
        # --- Render HTML Email Content.
        greetings = _(
            "Dear, %(name)s.") % {
                "name":     request.user.first_name,
            }
        htmlbody = _(
            "<p>You have successfully reset the Password from your Account.</p>"
            "<p>To log-in, please, follow this \"<a href=\"%(login_link)s\">Link</a>\".</p>") % {
                "login_link":   url,
            }

        # --- Send Email.
        send_templated_email(
            template_subj={
                "name":     "accounts/emails/account_successful_password_reset_subject.txt",
                "context":  {},
            },
            template_text={
                "name":     "accounts/emails/account_successful_password_reset.txt",
                "context":  {
                    "user":         self.user,
                    "login_link":   url,
                },
            },
            template_html={
                "name":     "emails/base.html",
                "context":  {
                    "greetings":    greetings,
                    "htmlbody":     htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.user.email,
            ],
            headers=None,
        )
Exemple #9
0
    def email_notify_password_reset(self, request=None, url=None):
        """Send Notification to the User."""
        print colored("***" * 27, "green")
        print colored("*** INSIDE `%s`" % inspect.stack()[0][3], "green")

        # ---------------------------------------------------------------------
        # ---  Render HTML Email Content.
        greetings = _(
            "Dear, %(name)s.") % {
                "name":     self.user.first_name,
            }
        htmlbody = _(
            "<p>You are about to restore your Password on SaneSide.</p>"
            "<p>To proceed, please, follow this \"<a href=\"%(confirmation_link)s\">Link</a>\".</p>") % {
                "confirmation_link":    url,
            }

        # --- Send Email.
        send_templated_email(
            template_subj={
                "name":     "accounts/emails/account_forgot_password_notify_subject.txt",
                "context":  {},
            },
            template_text={
                "name":     "accounts/emails/account_forgot_password_notify.txt",
                "context":  {
                    "user":                 self.user,
                    "confirmation_link":    url,
                },
            },
            template_html={
                "name":     "emails/base.html",
                "context":  {
                    "greetings":    greetings,
                    "htmlbody":     htmlbody,
                },
            },
            from_email=settings.EMAIL_SENDER,
            to=[
                self.user.email,
            ],
            headers=None,
        )
Exemple #10
0
    def post(self, request):
        """POST: Send a Message

            Receive:

                name                    :uint:
                email                   :uint:
                subject                 :uint:
                message                 :uint:

            Return:

                status                  200/400/404/500

            Example Payload:

                {
                    "name":             "Artem Suvorov",
                    "email":            "*****@*****.**",
                    "Subject":          "Question",
                    "Message":          "Some Message",
                }
        """
        print colored("***" * 27, "green")
        print colored(
            "*** INSIDE `%s.%s`" %
            (self.__class__.__name__, inspect.stack()[0][3]), "green")

        # ---------------------------------------------------------------------
        # --- Retrieve Data from the Request
        # ---------------------------------------------------------------------
        name = request.data.get("name", "")
        email = request.data.get("email", "")
        subject = request.data.get("subject", "")
        message = request.data.get("message", "")

        print colored("[---  DUMP   ---] NAME    : %s" % name, "yellow")
        print colored("[---  DUMP   ---] EMAIL   : %s" % email, "yellow")
        print colored("[---  DUMP   ---] SUBJECT : %s" % subject, "yellow")
        print colored("[---  DUMP   ---] MESSAGE : %s" % message, "yellow")

        # ---------------------------------------------------------------------
        # --- Handle Errors
        # ---------------------------------------------------------------------
        if not name or not email or not subject or not message:
            return Response(
                {
                    "message":
                    _("No Name, Email, Subject or Message provided."),
                },
                status=status.HTTP_400_BAD_REQUEST)

        # ---------------------------------------------------------------------
        # --- Send the Message
        # ---------------------------------------------------------------------
        if request.user.is_authenticated():
            from_name = "{name} (registered as {account_name} <{account_email}>".format(
                name=name,
                account_name=request.user.get_full_name(),
                account_email=request.user.email,
            )
        else:
            from_name = name

        # --- Send Email
        send_templated_email(
            template_subj={
                "name": "home/emails/inquiry_subject.txt",
                "context": {},
            },
            template_text={
                "name": "home/emails/inquiry.txt",
                "context": {
                    "from_name": from_name,
                    "from_email": email,
                    "from_subject": subject,
                    "from_message": message,
                },
            },
            template_html=None,
            from_email=settings.EMAIL_SENDER,
            to=[
                settings.EMAIL_SUPPORT,
            ],
            cc=[email for admin, email in settings.ADMINS],
            headers=None,
        )

        return Response({
            "message": _("Successfully sent the Message."),
        },
                        status=status.HTTP_200_OK)