示例#1
0
文件: events.py 项目: psbots/kitsune
    def _mails(self, users_and_watches):
        """Send one kind of mail to the asker and another to other watchers."""
        # Cache answer.question, similar to caching solution.question below.
        self.answer.question = self.instance
        asker_id = self.answer.question.creator.id

        c = {
            'answer': self.answer.content,
            'answer_html': self.answer.content_parsed,
            'answerer': self.answer.creator.username,
            'question_title': self.instance.title,
            'host': Site.objects.get_current().domain
        }

        @email_utils.safe_translation
        def _make_mail(locale, user, context):
            is_asker = asker_id == user.id
            if is_asker:
                subject = _(
                    u'%s posted an answer to your question "%s"' %
                    (self.answer.creator.username, self.instance.title))
                text_template = 'questions/email/new_answer_to_asker.ltxt'
                html_template = 'questions/email/new_answer_to_asker.html'
            else:
                subject = _(u'%s commented on a Firefox question '
                            "you're watching" % self.answer.creator.username)
                text_template = 'questions/email/new_answer.ltxt'
                html_template = 'questions/email/new_answer.html'

            mail = email_utils.make_mail(
                subject=subject,
                text_template=text_template,
                html_template=html_template,
                context_vars=context,
                from_email=settings.TIDINGS_FROM_ADDRESS,
                to_email=user.email)

            return mail

        for u, w in users_and_watches:
            auth_str = get_auth_str(self.answer.question.creator)
            answer_url = self.answer.get_absolute_url()
            helpful_url = self.answer.get_helpful_answer_url()
            solution_url = self.answer.get_solution_url(watch=w[0])

            c['answer_url'] = urlparams(answer_url, auth=auth_str)
            c['helpful_url'] = urlparams(helpful_url, auth=auth_str)
            c['solution_url'] = urlparams(solution_url, auth=auth_str)
            c['username'] = u.username
            c['watch'] = w[0]  # TODO: Expose all watches.

            # u here can be a Django User model or a Tidings EmailUser
            # model. In the case of the latter, there is no associated
            # profile, so we set the locale to en-US.
            if hasattr(u, 'profile'):
                locale = u.profile.locale
            else:
                locale = 'en-US'

            yield _make_mail(locale, u, c)
示例#2
0
        def _make_mail(locale, user, context):
            # Avoid circular import issues
            from kitsune.users.templatetags.jinja_helpers import display_name

            is_asker = asker_id == user.id
            extra_params = {}
            if is_asker:
                auth_str = get_auth_str(user)
                extra_params['auth'] = auth_str
                subject = _(
                    u'%s posted an answer to your question "%s"' %
                    (display_name(self.answer.creator), self.instance.title))
                text_template = 'questions/email/new_answer_to_asker.ltxt'
                html_template = 'questions/email/new_answer_to_asker.html'
            else:
                subject = _(u'Re: %s' % self.instance.title)
                text_template = 'questions/email/new_answer.ltxt'
                html_template = 'questions/email/new_answer.html'

            for k in ['answer_url', 'helpful_url', 'solution_url']:
                context[k] = add_utm(urlparams(context[k], **extra_params),
                                     'questions-reply')

            mail = email_utils.make_mail(subject=subject,
                                         text_template=text_template,
                                         html_template=html_template,
                                         context_vars=context,
                                         from_email='Mozilla Support Forum '
                                         '<*****@*****.**>',
                                         to_email=user.email)

            return mail
示例#3
0
    def _mails(self, users_and_watches):
        """Send one kind of mail to the asker and another to other watchers."""
        # Cache answer.question, similar to caching solution.question below.
        self.answer.question = self.instance
        asker_id = self.answer.question.creator.id

        c = {'answer': self.answer.content,
             'answer_html': self.answer.content_parsed,
             'answerer': self.answer.creator,
             'created': self.answer.created,
             'question_title': self.instance.title,
             'host': Site.objects.get_current().domain}

        @email_utils.safe_translation
        def _make_mail(locale, user, context):
            is_asker = asker_id == user.id
            if is_asker:
                subject = _(u'%s posted an answer to your question "%s"' %
                            (self.answer.creator.username,
                             self.instance.title))
                text_template = 'questions/email/new_answer_to_asker.ltxt'
                html_template = 'questions/email/new_answer_to_asker.html'
            else:
                subject = _(u'Re: %s' % self.instance.title)
                text_template = 'questions/email/new_answer.ltxt'
                html_template = 'questions/email/new_answer.html'

            mail = email_utils.make_mail(
                subject=subject,
                text_template=text_template,
                html_template=html_template,
                context_vars=context,
                from_email='Mozilla Support Forum <*****@*****.**>',
                to_email=user.email)

            return mail

        for u, w in users_and_watches:
            auth_str = get_auth_str(self.answer.question.creator)

            c['answer_url'] = self.answer.get_absolute_url()
            c['helpful_url'] = self.answer.get_helpful_answer_url()
            c['solution_url'] = self.answer.get_solution_url(watch=w[0])

            for k in ['answer_url', 'helpful_url', 'solution_url']:
                c[k] = add_utm(
                    urlparams(c[k], auth=auth_str), 'questions-reply')

            c['username'] = u.username
            c['watch'] = w[0]  # TODO: Expose all watches.

            # u here can be a Django User model or a Tidings EmailUser
            # model. In the case of the latter, there is no associated
            # profile, so we set the locale to en-US.
            if hasattr(u, 'profile'):
                locale = u.profile.locale
            else:
                locale = 'en-US'

            yield _make_mail(locale, u, c)
示例#4
0
文件: events.py 项目: huub52/kitsune
    def _mails(self, users_and_watches):
        """Send one kind of mail to the asker and another to other watchers."""
        # Cache answer.question, similar to caching solution.question below.
        self.answer.question = self.instance
        asker_id = self.answer.question.creator.id

        c = {
            "answer": self.answer.content,
            "answer_html": self.answer.content_parsed,
            "answerer": self.answer.creator,
            "question_title": self.instance.title,
            "host": Site.objects.get_current().domain,
        }

        @email_utils.safe_translation
        def _make_mail(locale, user, context):
            # Avoid circular import issues
            from kitsune.users.helpers import display_name

            is_asker = asker_id == user.id
            if is_asker:
                subject = _(
                    u'%s posted an answer to your question "%s"'
                    % (display_name(self.answer.creator), self.instance.title)
                )
                text_template = "questions/email/new_answer_to_asker.ltxt"
                html_template = "questions/email/new_answer_to_asker.html"
            else:
                subject = _(u"Re: %s" % self.instance.title)
                text_template = "questions/email/new_answer.ltxt"
                html_template = "questions/email/new_answer.html"

            mail = email_utils.make_mail(
                subject=subject,
                text_template=text_template,
                html_template=html_template,
                context_vars=context,
                from_email="Mozilla Support Forum <*****@*****.**>",
                to_email=user.email,
            )

            return mail

        for u, w in users_and_watches:
            auth_str = get_auth_str(self.answer.question.creator)

            c["answer_url"] = self.answer.get_absolute_url()
            c["helpful_url"] = self.answer.get_helpful_answer_url()
            c["solution_url"] = self.answer.get_solution_url(watch=w[0])

            for k in ["answer_url", "helpful_url", "solution_url"]:
                c[k] = add_utm(urlparams(c[k], auth=auth_str), "questions-reply")

            c["to_user"] = u
            c["watch"] = w[0]  # TODO: Expose all watches.

            # u here can be a Django User model or a Tidings EmailUser
            # model. In the case of the latter, there is no associated
            # profile, so we set the locale to en-US.
            if hasattr(u, "profile"):
                locale = u.profile.locale
                tzinfo = u.profile.timezone
            else:
                locale = "en-US"
                tzinfo = timezone(settings.TIME_ZONE)

            c["created"] = format_datetime(self.answer.created, tzinfo=tzinfo, locale=locale.replace("-", "_"))

            yield _make_mail(locale, u, c)
示例#5
0
    def _mails(self, users_and_watches):
        """Send one kind of mail to the asker and another to other watchers."""
        # Cache answer.question, similar to caching solution.question below.
        self.answer.question = self.instance
        asker_id = self.answer.question.creator.id

        c = {
            'answer': self.answer.content,
            'answer_html': self.answer.content_parsed,
            'answerer': self.answer.creator,
            'question_title': self.instance.title,
            'host': Site.objects.get_current().domain
        }

        @email_utils.safe_translation
        def _make_mail(locale, user, context):
            # Avoid circular import issues
            from kitsune.users.helpers import display_name

            is_asker = asker_id == user.id
            if is_asker:
                subject = _(
                    u'%s posted an answer to your question "%s"' %
                    (display_name(self.answer.creator), self.instance.title))
                text_template = 'questions/email/new_answer_to_asker.ltxt'
                html_template = 'questions/email/new_answer_to_asker.html'
            else:
                subject = _(u'Re: %s' % self.instance.title)
                text_template = 'questions/email/new_answer.ltxt'
                html_template = 'questions/email/new_answer.html'

            mail = email_utils.make_mail(subject=subject,
                                         text_template=text_template,
                                         html_template=html_template,
                                         context_vars=context,
                                         from_email='Mozilla Support Forum '
                                         '<*****@*****.**>',
                                         to_email=user.email)

            return mail

        for u, w in users_and_watches:
            auth_str = get_auth_str(self.answer.question.creator)

            c['answer_url'] = self.answer.get_absolute_url()
            c['helpful_url'] = self.answer.get_helpful_answer_url()
            c['solution_url'] = self.answer.get_solution_url(watch=w[0])

            for k in ['answer_url', 'helpful_url', 'solution_url']:
                c[k] = add_utm(urlparams(c[k], auth=auth_str),
                               'questions-reply')

            c['to_user'] = u
            c['watch'] = w[0]  # TODO: Expose all watches.

            # u here can be a Django User model or a Tidings EmailUser
            # model. In the case of the latter, there is no associated
            # profile, so we set the locale to en-US.
            if hasattr(u, 'profile'):
                locale = u.profile.locale
                tzinfo = u.profile.timezone
            else:
                locale = 'en-US'
                tzinfo = timezone(settings.TIME_ZONE)

            c['created'] = format_datetime(self.answer.created,
                                           tzinfo=tzinfo,
                                           locale=locale.replace('-', '_'))

            yield _make_mail(locale, u, c)
示例#6
0
文件: events.py 项目: runt18/kitsune
    def _mails(self, users_and_watches):
        """Send one kind of mail to the asker and another to other watchers."""
        # Cache answer.question, similar to caching solution.question below.
        self.answer.question = self.instance
        asker_id = self.answer.question.creator.id

        c = {'answer': self.answer.content,
             'answer_html': self.answer.content_parsed,
             'answerer': self.answer.creator,
             'question_title': self.instance.title,
             'host': Site.objects.get_current().domain}

        @email_utils.safe_translation
        def _make_mail(locale, user, context):
            # Avoid circular import issues
            from kitsune.users.helpers import display_name

            is_asker = asker_id == user.id
            if is_asker:
                subject = _(u'{0!s} posted an answer to your question "{1!s}"'.format(display_name(self.answer.creator),
                             self.instance.title))
                text_template = 'questions/email/new_answer_to_asker.ltxt'
                html_template = 'questions/email/new_answer_to_asker.html'
            else:
                subject = _(u'Re: {0!s}'.format(self.instance.title))
                text_template = 'questions/email/new_answer.ltxt'
                html_template = 'questions/email/new_answer.html'

            mail = email_utils.make_mail(
                subject=subject,
                text_template=text_template,
                html_template=html_template,
                context_vars=context,
                from_email='Mozilla Support Forum '
                           '<*****@*****.**>',
                to_email=user.email)

            return mail

        for u, w in users_and_watches:
            auth_str = get_auth_str(self.answer.question.creator)

            c['answer_url'] = self.answer.get_absolute_url()
            c['helpful_url'] = self.answer.get_helpful_answer_url()
            c['solution_url'] = self.answer.get_solution_url(watch=w[0])

            for k in ['answer_url', 'helpful_url', 'solution_url']:
                c[k] = add_utm(
                    urlparams(c[k], auth=auth_str), 'questions-reply')

            c['to_user'] = u
            c['watch'] = w[0]  # TODO: Expose all watches.

            # u here can be a Django User model or a Tidings EmailUser
            # model. In the case of the latter, there is no associated
            # profile, so we set the locale to en-US.
            if hasattr(u, 'profile'):
                locale = u.profile.locale
                tzinfo = u.profile.timezone
            else:
                locale = 'en-US'
                tzinfo = timezone(settings.TIME_ZONE)

            c['created'] = format_datetime(self.answer.created, tzinfo=tzinfo,
                                           locale=locale.replace('-', '_'))

            yield _make_mail(locale, u, c)