コード例 #1
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),
     }
コード例 #2
0
ファイル: tasks.py プロジェクト: 1234-/kitsune
    def _send_mail(locale):
        # Avoid circular import issues
        from kitsune.users.templatetags.jinja_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.templatetags.jinja_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])
コード例 #3
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
コード例 #4
0
    def _send_mail(locale):
        # Avoid circular import issues
        from kitsune.users.templatetags.jinja_helpers import display_name

        subject = _("[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.templatetags.jinja_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 プロジェクト: zu83/kitsune
        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
            if is_asker:
                subject = _(
                    '%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 = _("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]), "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
コード例 #6
0
ファイル: tasks.py プロジェクト: rootmeb/kitsune
    def _send_mail(locale):
        # Avoid circular import issues
        from kitsune.users.templatetags.jinja_helpers import display_name

        subject = _('[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.templatetags.jinja_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])
コード例 #7
0
ファイル: events.py プロジェクト: vasimi/kitsune
        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
            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
コード例 #8
0
ファイル: events.py プロジェクト: davehunt/kitsune
        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
            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
コード例 #9
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 = UserFactory()
        q = self._toggle_watch_question('solution', u, turn_on=True)
        QuestionSolvedEvent.notify('*****@*****.**', q)

        a = AnswerFactory(question=q)

        # 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.
        attrs_eq(mail.outbox[0],
                 to=[u.email],
                 subject='Solution found to Firefox Help question')
        starts_with(
            mail.outbox[0].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[1],
                 to=['*****@*****.**'],
                 subject='Solution found to Firefox Help question')
        starts_with(
            mail.outbox[1].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/'))

        # make sure email has the proper static url
        self.assertIn('https://example.com/sumo/email/img/mozilla-support.png',
                      mail.outbox[1].alternatives[0][0])
コード例 #10
0
 def test_user_list(self):
     UserFactory(username='******')
     UserFactory(username='******')
     users = User.objects.all()
     list = user_list(users)
     assert isinstance(list, Markup)
     fragment = pq(list)
     eq_(len(users), len(fragment('a')))
     a = fragment('a')[1]
     assert a.attrib['href'].endswith(str(users[1].username))
     eq_(display_name(users[1]), a.text)
コード例 #11
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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 = UserFactory()
        q = self._toggle_watch_question('solution', u, turn_on=True)
        QuestionSolvedEvent.notify('*****@*****.**', q)

        a = AnswerFactory(question=q)

        # 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/'))
コード例 #12
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)

        starts_with(notification.body, ANSWER_EMAIL_TO_ASKER.format(**self.format_args()))
コード例 #13
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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()))
コード例 #14
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()))
コード例 #15
0
ファイル: test_templatetags.py プロジェクト: zu83/kitsune
 def test_display_name(self):
     eq_(self.u.profile.name, display_name(self.u))
     self.u.profile.name = "Test User"
     self.u.profile.save()
     eq_("Test User", display_name(self.u))
コード例 #16
0
ファイル: test_templatetags.py プロジェクト: 1234-/kitsune
 def test_display_name_anonymous(self):
     eq_(u'', display_name(AnonymousUser()))
コード例 #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
ファイル: test_templatetags.py プロジェクト: 1234-/kitsune
 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))