Skip to content

Commit

Permalink
[bug 970214] Send a weekly "Ready for review" digest
Browse files Browse the repository at this point in the history
  • Loading branch information
rehandalal committed Jul 2, 2014
1 parent 1d1c8ac commit c641962
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 1 deletion.
59 changes: 58 additions & 1 deletion kitsune/wiki/cron.py
@@ -1,9 +1,19 @@
import cronjobs
import waffle

from itertools import chain

from django.conf import settings
from django.contrib.auth.models import User
from django.db.models import F, Q, ObjectDoesNotExist

from statsd import statsd
from tower import ugettext as _

from kitsune.search.tasks import index_task
from kitsune.sumo import email_utils
from kitsune.wiki import tasks
from kitsune.wiki.models import DocumentMappingType
from kitsune.wiki.models import Document, DocumentMappingType, Revision, Locale


@cronjobs.register
Expand All @@ -19,3 +29,50 @@ def rebuild_kb():
def reindex_kb():
"""Reindex wiki_document."""
index_task.delay(DocumentMappingType, DocumentMappingType.get_indexable())


@cronjobs.register
def send_weekly_ready_for_review_digest():
"""Sends out the weekly "Ready for review" digest email."""

@email_utils.safe_translation
def _send_mail(locale, user, context):
subject = _('[Reviews Pending] SUMO needs your help!')

mail = email_utils.make_mail(
subject=subject,
text_template='wiki/email/ready_for_review_weekly_digest.ltxt',
html_template='wiki/email/ready_for_review_weekly_digest.html',
context_vars=context,
from_email=settings.TIDINGS_FROM_ADDRESS,
to_email=user.email)

email_utils.send_messages([mail])

# Get the list of revisions ready for review
revs = Revision.objects.filter(reviewed=None).filter(
Q(document__current_revision_id__lt=F('id')) |
Q(document__current_revision_id=None))

locales = revs.values_list('document__locale', flat=True).distinct()

for l in locales:
docs = revs.filter(document__locale=l).values_list(
'document', flat=True).distinct()
docs = Document.objects.filter(id__in=docs)

try:
leaders = Locale.objects.get(locale=l).leaders.all()
reviewers = Locale.objects.get(locale=l).reviewers.all()
users = list(chain(leaders, reviewers))
except ObjectDoesNotExist:
# Locale does not exist, so skip to the next locale
continue

for u in users:
_send_mail(l, u, {
'recipient': u,
'docs': docs,
})

statsd.incr('wiki.cron.weekly-digest-mail')
@@ -0,0 +1,51 @@
{% extends 'email/base.html' %}

{% block styles %}
ul {
padding: 0;
}
{% endblock %}

{% block content %}
<p>
{{ _('Hi {username},')|f(username=display_name(recipient)) }}
</p>

<p>
{% trans %}
Our contributors have been working hard on articles and it would be great
if you could review them. The faster we get them published the faster
they start helping users.
{% endtrans %}
</p>

<p>
{% trans %}
If you have a moment please help us by reviewing these articles:
{% endtrans %}
</p>

<ul>
{% for d in docs %}
<li>
<a href="{{ url('wiki.document_revisions', d.slug) }}">
{{ d.title }}
</a>
</li>
{% endfor %}
</ul>

<p>
{% trans %}
Many thanks for your contribution in behalf of SUMO and the happy users
who get help!
{% endtrans %}
</p>

<p>
{% trans %}
Regards,
<br />The SUMO team.
{% endtrans %}
</p>
{% endblock %}
@@ -0,0 +1,28 @@
{# This is an email. Whitespace matters! #}
{% autoescape false %}
{{ _('Hi {username}')|f(username=display_name(recipient)) }}

{% trans %}
Our contributors have been working hard on articles and it would be great if
you could review them. The faster we get them published the faster they start
helping users.
{% endtrans %}

{{ _('If you have a moment please review these articles:') }}

{% for d in docs %}
{{ d.title }}
({{ url('wiki.document_revisions', d.slug) }})

{% endfor %}

{% trans %}
Many thanks for your contribution on behalf of SUMO and the happy users who are
helped by your work!
{% endtrans %}

{% trans %}
Regards,
The SUMO team
{% endtrans %}
{% endautoescape %}
1 change: 1 addition & 0 deletions scripts/crontab/crontab.tpl
Expand Up @@ -41,6 +41,7 @@ HOME = /tmp

# Once per week.
21 03 * * 3 {{ django }} purge_hashes
0 4 * * 5 {{ cron }} send_weekly_ready_for_review_digest

# Once per month.
0 0 1 * * {{ cron }} update_l10n_contributor_metrics
Expand Down

0 comments on commit c641962

Please sign in to comment.