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])
def _mails(self, users_and_watches): revision = self.revision document = revision.document log.debug('Sending ready for review email for revision (id=%s)' % revision.id) subject = _lazy(u'{title} is ready for review ({creator})') url = reverse('wiki.review_revision', locale=document.locale, args=[document.slug, revision.id]) context = context_dict(revision) context['revision_url'] = add_utm(url, 'wiki-ready-review') context['locale'] = document.locale context['title'] = document.title context['creator'] = revision.creator context['comment'] = revision.comment users = [] for u, w in users_and_watches: if document.allows(u, 'review_revision'): users.append((u, w)) return email_utils.emails_with_users_and_watches( subject=subject, text_template='wiki/email/ready_for_review.ltxt', html_template='wiki/email/ready_for_review.html', context_vars=context, users_and_watches=users, default_locale=document.locale)
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)
def _mails(self, users_and_watches): revision = self.revision document = revision.document log.debug('Sending edited notification email for document (id=%s)' % document.id) subject = _lazy(u'{title} was edited by {creator}') url = reverse('wiki.document_revisions', locale=document.locale, args=[document.slug]) context = context_dict(revision) context['revisions_url'] = add_utm(url, 'wiki-edit') context['locale'] = document.locale context['title'] = document.title context['creator'] = revision.creator context['comment'] = revision.comment return email_utils.emails_with_users_and_watches( subject=subject, text_template='wiki/email/edited.ltxt', html_template='wiki/email/edited.html', context_vars=context, users_and_watches=users_and_watches, default_locale=document.locale)
def _make_mail(locale, user, watches): if (is_ready and ReadyRevisionEvent.event_type in (w.event_type for w in watches)): c = context_dict(revision, ready_for_l10n=True) # TODO: Expose all watches c['watch'] = watches[0] url = django_reverse( 'wiki.select_locale', args=[document.slug]) c['l10n_url'] = add_utm(url, 'wiki-ready-l10n') subject = _(u'{title} has a revision ready for ' 'localization') text_template = 'wiki/email/ready_for_l10n.ltxt' html_template = 'wiki/email/ready_for_l10n.html' else: c = context_dict(revision, revision_approved=True) approved_url = reverse('wiki.document', locale=document.locale, args=[document.slug]) c['document_url'] = add_utm(approved_url, 'wiki-approved') # TODO: Expose all watches. c['watch'] = watches[0] c['reviewer'] = revision.reviewer subject = _(u'{title} ({locale}) has a new approved ' 'revision ({reviewer})') text_template = 'wiki/email/approved.ltxt' html_template = 'wiki/email/approved.html' subject = subject.format( title=document.title, reviewer=revision.reviewer.username, locale=document.locale) mail = email_utils.make_mail( subject=subject, text_template=text_template, html_template=html_template, context_vars=c, from_email=settings.TIDINGS_FROM_ADDRESS, to_email=user.email) return mail
def _make_mail(locale, user, watches): if is_ready and ReadyRevisionEvent.event_type in (w.event_type for w in watches): c = context_dict(revision, ready_for_l10n=True) # TODO: Expose all watches c["watch"] = watches[0] url = django_reverse("wiki.select_locale", args=[document.slug]) c["l10n_url"] = add_utm(url, "wiki-ready-l10n") subject = _(u"{title} has a revision ready for " "localization") text_template = "wiki/email/ready_for_l10n.ltxt" html_template = "wiki/email/ready_for_l10n.html" else: c = context_dict(revision, revision_approved=True) approved_url = reverse("wiki.document", locale=document.locale, args=[document.slug]) c["document_url"] = add_utm(approved_url, "wiki-approved") # TODO: Expose all watches. c["watch"] = watches[0] c["reviewer"] = revision.reviewer subject = _(u"{title} ({locale}) has a new approved " "revision ({reviewer})") text_template = "wiki/email/approved.ltxt" html_template = "wiki/email/approved.html" subject = subject.format(title=document.title, reviewer=revision.reviewer.username, locale=document.locale) mail = email_utils.make_mail( subject=subject, text_template=text_template, html_template=html_template, context_vars=c, from_email=settings.TIDINGS_FROM_ADDRESS, to_email=user.email, ) return mail
def _mails(self, users_and_watches): post_url = add_utm(self.post.thread.get_absolute_url(), 'forums-thread') c = {'post': self.post.content, 'post_html': self.post.content_parsed, 'author': self.post.author.username, 'host': Site.objects.get_current().domain, 'thread': self.post.thread.title, 'forum': self.post.thread.forum.name, 'post_url': post_url} return emails_with_users_and_watches( subject=_lazy(u'{forum} - {thread}'), text_template='forums/email/new_thread.ltxt', html_template='forums/email/new_thread.html', context_vars=c, users_and_watches=users_and_watches)
def _mails(self, users_and_watches): question = self.instance # Cache solution.question as a workaround for replication lag # (bug 585029) question.solution = self.answer question.solution.question = question @email_utils.safe_translation def _make_mail(locale, user, context): subject = _(u"Solution found to Firefox Help question") mail = email_utils.make_mail( subject=subject, text_template="questions/email/solution.ltxt", html_template="questions/email/solution.html", context_vars=context, from_email=settings.TIDINGS_FROM_ADDRESS, to_email=user.email, ) return mail solution_url = add_utm(question.solution.get_absolute_url(), "questions-solved") c = { "answerer": question.solution.creator, "asker": question.creator, "question_title": question.title, "host": Site.objects.get_current().domain, "solution_url": solution_url, } for u, w in users_and_watches: c["to_user"] = u # '' if anonymous 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)
def _mails(self, users_and_watches): question = self.instance # Cache solution.question as a workaround for replication lag # (bug 585029) question.solution = self.answer question.solution.question = question @email_utils.safe_translation def _make_mail(locale, user, context): subject = _(u'Solution found to Firefox Help question') mail = email_utils.make_mail( subject=subject, text_template='questions/email/solution.ltxt', html_template='questions/email/solution.html', context_vars=context, from_email=settings.TIDINGS_FROM_ADDRESS, to_email=user.email) return mail solution_url = add_utm(question.solution.get_absolute_url(), 'questions-solved') c = { 'answerer': question.solution.creator, 'asker': question.creator, 'question_title': question.title, 'host': Site.objects.get_current().domain, 'solution_url': solution_url } for u, w in users_and_watches: c['to_user'] = u # '' if anonymous 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)
def new_thread_mails(post, users_and_watches): """Return an interable of EmailMessages to send when a new thread is created.""" post_url = add_utm(post.thread.get_absolute_url(), 'kbforums-thread') c = {'post': post.content, 'post_html': post.content_parsed, 'author': post.creator, 'host': Site.objects.get_current().domain, 'thread': post.thread.title, 'forum': post.thread.document.title, 'post_url': post_url} return emails_with_users_and_watches( subject=_lazy(u'{forum} - {thread}'), text_template='kbforums/email/new_thread.ltxt', html_template='kbforums/email/new_thread.html', context_vars=c, users_and_watches=users_and_watches)
def _mails(self, users_and_watches): question = self.instance # Cache solution.question as a workaround for replication lag # (bug 585029) question.solution = self.answer question.solution.question = question @email_utils.safe_translation def _make_mail(locale, user, context): subject = _(u'Solution found to Firefox Help question') mail = email_utils.make_mail( subject=subject, text_template='questions/email/solution.ltxt', html_template='questions/email/solution.html', context_vars=context, from_email=settings.TIDINGS_FROM_ADDRESS, to_email=user.email) return mail solution_url = add_utm( question.solution.get_absolute_url(), 'questions-solved') c = {'answerer': question.solution.creator, 'asker': question.creator.username, 'question_title': question.title, 'host': Site.objects.get_current().domain, 'solution_url': solution_url} for u, w in users_and_watches: c['username'] = u.username # '' if anonymous 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)
def _mails(self, users_and_watches): post_url = add_utm(self.reply.get_absolute_url(), 'forums-post') c = { 'post': self.reply.content, 'post_html': self.reply.content_parsed, 'author': self.reply.author.username, 'host': Site.objects.get_current().domain, 'thread': self.reply.thread.title, 'forum': self.reply.thread.forum.name, 'post_url': post_url } return emails_with_users_and_watches( subject=_lazy(u'Re: {forum} - {thread}'), text_template='forums/email/new_post.ltxt', html_template='forums/email/new_post.html', context_vars=c, users_and_watches=users_and_watches)
def _mails(self, users_and_watches): """Send readiness mails.""" revision = self.revision document = revision.document log.debug('Sending ready notifications for revision (id=%s)' % revision.id) subject = _lazy(u'{title} has a revision ready for localization') url = django_reverse('wiki.select_locale', args=[document.slug]) context = context_dict(revision, ready_for_l10n=True) context['l10n_url'] = add_utm(url, 'wiki-ready-l10n') context['title'] = document.title return email_utils.emails_with_users_and_watches( subject=subject, text_template='wiki/email/ready_for_l10n.ltxt', html_template='wiki/email/ready_for_l10n.html', context_vars=context, users_and_watches=users_and_watches, default_locale=document.locale)
def _mails(self, users_and_watches): revision = self.revision document = revision.document log.debug("Sending ready for review email for revision (id={0!s})".format(revision.id)) subject = _lazy(u"{title} is ready for review ({creator})") url = reverse("wiki.review_revision", locale=document.locale, args=[document.slug, revision.id]) context = context_dict(revision) context["revision_url"] = add_utm(url, "wiki-ready-review") context["locale"] = document.locale context["title"] = document.title context["creator"] = revision.creator context["comment"] = revision.comment return email_utils.emails_with_users_and_watches( subject=subject, text_template="wiki/email/ready_for_review.ltxt", html_template="wiki/email/ready_for_review.html", context_vars=context, users_and_watches=users_and_watches, default_locale=document.locale, )
def _mails(self, users_and_watches): """Send readiness mails.""" revision = self.revision document = revision.document log.debug("Sending ready notifications for revision (id={0!s})".format(revision.id)) subject = _lazy(u"{title} has a revision ready for localization") url = django_reverse("wiki.select_locale", args=[document.slug]) context = context_dict(revision, ready_for_l10n=True) context["l10n_url"] = add_utm(url, "wiki-ready-l10n") context["title"] = document.title return email_utils.emails_with_users_and_watches( subject=subject, text_template="wiki/email/ready_for_l10n.ltxt", html_template="wiki/email/ready_for_l10n.html", context_vars=context, users_and_watches=users_and_watches, default_locale=document.locale, )
def _mails(self, users_and_watches): revision = self.revision document = revision.document log.debug("Sending edited notification email for document (id={0!s})".format(document.id)) subject = _lazy(u"{title} was edited by {creator}") url = reverse("wiki.document_revisions", locale=document.locale, args=[document.slug]) context = context_dict(revision) context["revisions_url"] = add_utm(url, "wiki-edit") context["locale"] = document.locale context["title"] = document.title context["creator"] = revision.creator context["comment"] = revision.comment return email_utils.emails_with_users_and_watches( subject=subject, text_template="wiki/email/edited.ltxt", html_template="wiki/email/edited.html", context_vars=context, users_and_watches=users_and_watches, default_locale=document.locale, )
def _activation_url(cls, watch): url = reverse('questions.activate_watch', args=[watch.id, watch.secret]) return add_utm(url, 'questions-activate')
def _activation_url(cls, watch): url = reverse("questions.activate_watch", args=[watch.id, watch.secret]) return add_utm(url, "questions-activate")
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)
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)