def format_args(self):
     return {
         "title": self.question.title,
         "content": self.answer.content,
         "replier": display_name(self.answer.creator),
         "question_id": self.question.id,
         "answer_id": self.answer.id,
         "locale": "",
         "asker": display_name(self.question.creator),
     }
示例#2
0
 def format_args(self):
     return {
         'title': self.question.title,
         'content': self.answer.content,
         'replier': display_name(self.answer.creator),
         'question_id': self.question.id,
         'answer_id': self.answer.id,
         'locale': '',
         'asker': display_name(self.question.creator),
     }
示例#3
0
 def format_args(self):
     return {
         'title': self.question.title,
         'content': self.answer.content,
         'replier': display_name(self.answer.creator),
         'question_id': self.question.id,
         'answer_id': self.answer.id,
         'locale': '',
         'asker': display_name(self.question.creator),
     }
示例#4
0
    def _send_mail(locale):
        # Avoid circular import issues
        from kitsune.users.helpers import display_name

        subject = _(u'[SUMO] You have a new private message from [{sender}]')
        subject = subject.format(
            sender=display_name(inbox_message.sender))

        msg_url = reverse('messages.read', kwargs={'msgid': inbox_message.id})
        settings_url = reverse('users.edit_settings')

        from kitsune.sumo.helpers import add_utm
        context = {
            'sender': inbox_message.sender,
            'message': inbox_message.message,
            'message_html': inbox_message.content_parsed,
            'message_url': add_utm(msg_url, 'messages-new'),
            'unsubscribe_url': add_utm(settings_url, 'messages-new'),
            'host': Site.objects.get_current().domain}

        mail = make_mail(subject=subject,
                         text_template='messages/email/private_message.ltxt',
                         html_template='messages/email/private_message.html',
                         context_vars=context,
                         from_email=settings.TIDINGS_FROM_ADDRESS,
                         to_email=inbox_message.to.email)

        send_messages([mail])
示例#5
0
文件: events.py 项目: huub52/kitsune
        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
示例#6
0
        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
    def test_solution_notification(self, get_current):
        """Assert that hitting the watch toggle toggles and that proper mails
        are sent to anonymous and registered watchers."""
        # TODO: Too monolithic. Split this test into several.
        get_current.return_value.domain = "testserver"

        u = user(save=True)
        q = self._toggle_watch_question("solution", u, turn_on=True)
        QuestionSolvedEvent.notify("*****@*****.**", q)

        a = answer(question=q, save=True)

        # Mark a solution
        self.client.login(username=q.creator.username, password="******")
        post(self.client, "questions.solve", args=[q.id, a.id])

        # Order of emails is not important.
        # Note: we skip the first email because it is a reply notification
        # to the asker.
        attrs_eq(mail.outbox[1], to=[u.email], subject="Solution found to Firefox Help question")
        starts_with(
            mail.outbox[1].body,
            SOLUTION_EMAIL.format(
                to_user=display_name(u),
                replier=display_name(a.creator),
                title=q.title,
                asker=display_name(q.creator),
                question_id=q.id,
                answer_id=a.id,
                locale="en-US/",
            ),
        )

        attrs_eq(mail.outbox[2], to=["*****@*****.**"], subject="Solution found to Firefox Help question")
        starts_with(
            mail.outbox[2].body,
            SOLUTION_EMAIL_TO_ANONYMOUS.format(
                replier=display_name(a.creator),
                title=q.title,
                asker=display_name(q.creator),
                question_id=q.id,
                answer_id=a.id,
                locale="en-US/",
            ),
        )
示例#8
0
    def test_solution_notification(self, get_current):
        """Assert that hitting the watch toggle toggles and that proper mails
        are sent to anonymous and registered watchers."""
        # TODO: Too monolithic. Split this test into several.
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        q = self._toggle_watch_question('solution', u, turn_on=True)
        QuestionSolvedEvent.notify('*****@*****.**', q)

        a = answer(question=q, save=True)

        # Mark a solution
        self.client.login(username=q.creator.username, password='******')
        post(self.client, 'questions.solve', args=[q.id, a.id])

        # Order of emails is not important.
        # Note: we skip the first email because it is a reply notification
        # to the asker.
        attrs_eq(mail.outbox[1],
                 to=[u.email],
                 subject='Solution found to Firefox Help question')
        starts_with(
            mail.outbox[1].body,
            SOLUTION_EMAIL.format(to_user=display_name(u),
                                  replier=display_name(a.creator),
                                  title=q.title,
                                  asker=display_name(q.creator),
                                  question_id=q.id,
                                  answer_id=a.id,
                                  locale='en-US/'))

        attrs_eq(mail.outbox[2],
                 to=['*****@*****.**'],
                 subject='Solution found to Firefox Help question')
        starts_with(
            mail.outbox[2].body,
            SOLUTION_EMAIL_TO_ANONYMOUS.format(replier=display_name(a.creator),
                                               title=q.title,
                                               asker=display_name(q.creator),
                                               question_id=q.id,
                                               answer_id=a.id,
                                               locale='en-US/'))
示例#9
0
    def test_notify_asker(self):
        """Test that the answer is notified of answers, without registering."""
        self.makeAnswer()

        eq_(1, len(mail.outbox))
        notification = mail.outbox[0]

        eq_([self.question.creator.email], notification.to)
        eq_(u'{0} posted an answer to your question "{1}"'
            .format(display_name(self.answer.creator), self.question.title),
            notification.subject)

        body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body)
        starts_with(body, ANSWER_EMAIL_TO_ASKER.format(**self.format_args()))
示例#10
0
    def test_notify_asker(self):
        """Test that the answer is notified of answers, without registering."""
        self.makeAnswer()

        eq_(1, len(mail.outbox))
        notification = mail.outbox[0]

        eq_([self.question.creator.email], notification.to)
        eq_('{0} posted an answer to your question "{1}"'
            .format(display_name(self.answer.creator), self.question.title),
            notification.subject)

        body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body)
        starts_with(body, ANSWER_EMAIL_TO_ASKER.format(**self.format_args()))
示例#11
0
    def test_notify_arbitrary(self):
        """Test that arbitrary users are notified of new answers."""
        watcher = user(save=True)
        QuestionReplyEvent.notify(watcher, self.question)
        self.makeAnswer()

        # One for the asker's email, and one for the watcher's email.
        eq_(2, len(mail.outbox))
        notification = [m for m in mail.outbox if m.to == [watcher.email]][0]

        eq_([watcher.email], notification.to)
        eq_("Re: {0}".format(self.question.title), notification.subject)

        body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body)
        starts_with(body, ANSWER_EMAIL.format(to_user=display_name(watcher), **self.format_args()))
示例#12
0
    def test_notify_arbitrary(self):
        """Test that arbitrary users are notified of new answers."""
        watcher = UserFactory()
        QuestionReplyEvent.notify(watcher, self.question)
        self.makeAnswer()

        # One for the asker's email, and one for the watcher's email.
        eq_(2, len(mail.outbox))
        notification = [m for m in mail.outbox if m.to == [watcher.email]][0]

        eq_([watcher.email], notification.to)
        eq_(u'Re: {0}'.format(self.question.title), notification.subject)

        body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body)
        starts_with(body, ANSWER_EMAIL.format(to_user=display_name(watcher), **self.format_args()))
示例#13
0
 def test_display_name(self):
     eq_(self.u.profile.name, display_name(self.u))
     self.u.profile.name = u"Test User"
     self.u.profile.save()
     eq_(u"Test User", display_name(self.u))
示例#14
0
 def test_display_name(self):
     eq_(u'testuser', display_name(self.u))
     p = profile(user=self.u, name=u'Test User')
     eq_(u'Test User', display_name(self.u))
示例#15
0
 def test_display_name(self):
     eq_(u"testuser", display_name(self.u))
     profile(user=self.u, name=u"Test User")
     eq_(u"Test User", display_name(self.u))
示例#16
0
 def test_display_name(self):
     eq_(u'testuser', display_name(self.u))
     p = profile(user=self.u, name=u'Test User')
     eq_(u'Test User', display_name(self.u))
示例#17
0
 def test_display_name_anonymous(self):
     eq_(u'', display_name(AnonymousUser()))
示例#18
0
 def test_display_name(self):
     eq_(self.u.profile.name, display_name(self.u))
     self.u.profile.name = u'Test User'
     self.u.profile.save()
     eq_(u'Test User', display_name(self.u))
示例#19
0
 def test_display_name(self):
     eq_(u'testuser', display_name(self.u))
     profile(user=self.u, name=u'Test User')
     eq_(u'Test User', display_name(self.u))
     eq_(u'', display_name(AnonymousUser()))
示例#20
0
 def test_display_name_anonymous(self):
     eq_(u"", display_name(AnonymousUser()))
示例#21
0
 def test_display_name(self):
     eq_(u'testuser', display_name(self.u))
     profile(user=self.u, name=u'Test User')
     eq_(u'Test User', display_name(self.u))
     eq_(u'', display_name(AnonymousUser()))
示例#22
0
文件: events.py 项目: runt18/kitsune
        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