Skip to content
This repository was archived by the owner on Nov 11, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions notifier/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from django.conf import settings
from django.template.loader import get_template
from django.template import Context
from django.utils.html import strip_tags
from django.utils.translation import ugettext as _, activate, deactivate
from statsd import statsd
Expand Down Expand Up @@ -228,7 +227,7 @@ def render_digest(user, digest, title, description):
Returns two strings: (text_body, html_body).
"""
logger.info("rendering email message: {user_id: %s}", user['id'])
context = Context({
context = {
'user': user,
'digest': digest,
'title': title,
Expand All @@ -239,7 +238,7 @@ def render_digest(user, digest, title, description):
'logo_image_url': settings.LOGO_IMAGE_URL,
'unsubscribe_url': _get_unsubscribe_url(user),
'postal_address': settings.EMAIL_SENDER_POSTAL_ADDRESS,
})
}

with _activate_user_lang(user):
text = get_template('digest-email.txt').render(context)
Expand Down
96 changes: 50 additions & 46 deletions notifier/management/commands/forums_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
"""
import datetime

import celery
import json
import logging
from dateutil.parser import parse as date_parse
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from django.core.serializers.json import DjangoJSONEncoder
import json
import logging
from optparse import make_option
import pytz
import requests
import sys

from notifier.digest import render_digest, Digest, DigestCourse, DigestThread, DigestItem
from notifier.pull import generate_digest_content
Expand All @@ -37,44 +32,53 @@ class Command(BaseCommand):
"""
"""

option_list = BaseCommand.option_list + (
make_option('--to_datetime',
action='store',
dest='to_datetime',
default=None,
help='datetime as of which to generate digest content, in ISO-8601 format (UTC). Defaults to today at midnight (UTC).'),
make_option('--minutes',
action='store',
dest='minutes',
type='int',
default=1440,
help='number of minutes up to TO_DATETIME for which to generate digest content. Defaults to 1440 (one day).'),
make_option('--users',
action='store',
dest='users_str',
default=None,
help='send digests for the specified users only (regardless of opt-out settings!)'),
make_option('--show-content',
action='store_true',
dest='show_content',
default=None,
help='output the retrieved content only (don\'t send anything)'),
make_option('--show-users',
action='store_true',
dest='show_users',
default=None,
help='output the retrieved users only (don\'t fetch content or send anything)'),
make_option('--show-text',
action='store_true',
dest='show_text',
default=None,
help='output the rendered text body of the first user-digest generated, and exit (don\'t send anything)'),
make_option('--show-html',
action='store_true',
dest='show_html',
default=None,
help='output the rendered html body of the first user-digest generated, and exit (don\'t send anything)'),
)
def add_arguments(self, parser):

parser.add_argument('--to_datetime',
action='store',
dest='to_datetime',
default=None,
help='datetime as of which to generate digest content, in ISO-8601 format (UTC).' \
'Defaults to today at midnight (UTC).')

parser.add_argument('--minutes',
action='store',
dest='minutes',
type='int',
default=1440,
help='number of minutes up to TO_DATETIME for which to generate digest content.'\
'Defaults to 1440 (one day).')

parser.add_argument('--users',
action='store',
dest='users_str',
default=None,
help='send digests for # TODO: he specified users only (regardless of opt-out settings!)')

parser.add_argument('--show-content',
action='store_true',
dest='show_content',
default=None,
help='output the retrieved content only (don\'t send anything)')

parser.add_argument('--show-users',
action='store_true',
dest='show_users',
default=None,
help='output the retrieved users only (don\'t fetch content or send anything)')
parser.add_argument('--show-text',
action='store_true',
dest='show_text',
default=None,
help='output the rendered text body of the first user-digest generated, and ' \
'exit (don\'t send anything)')

parser.add_argument('--show-html',
action='store_true',
dest='show_html',
default=None,
help='output the rendered html body of the first user-digest generated, and ' \
'exit (don\'t send anything)')

def get_specific_users(self, user_ids):
# this makes an individual HTTP request for each user -
Expand Down
2 changes: 1 addition & 1 deletion notifier/management/commands/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from apscheduler.schedulers.blocking import BlockingScheduler
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand

from notifier.tasks import do_forums_digests

Expand Down
23 changes: 23 additions & 0 deletions notifier/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import os
import platform

# Change this
SECRET_KEY = "bI7S2DOOdOLHu3pry1hr2glKlBvBRIB9Uz9CjjI69nOdFyyhsLww06y95z3caIoC0H6RzwLQQe0B9gE43QUM4hjBy6OHhpv1Fwil"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a real key or could we set this to something like "Please_change_me"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference, I've seen both in our applications.


DATABASES = {
'default': {
# Database backend defaults to 'sqlite3', but 'mysql' is also supported.
Expand All @@ -28,6 +31,26 @@

SERVICE_NAME = 'notifier'

# Template Settings
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(SETTINGS_PATH, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


# Misc. Notifier Formatting

FORUM_DIGEST_EMAIL_SENDER = os.getenv('FORUM_DIGEST_EMAIL_SENDER', 'notifications@example.org')
Expand Down
2 changes: 1 addition & 1 deletion notifier/tests/test_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_user_lang_pref_supported(self, mock_activate, mock_deactivate):
self.user["preferences"][LANGUAGE_PREFERENCE_KEY] = user_lang
render_digest(self.user, self.digest, "dummy", "dummy")
mock_activate.assert_called_with(user_lang)
mock_deactivate.assert_called()
self.assertTrue(mock_deactivate.called)

@patch("notifier.digest.activate")
def test_user_lang_pref_unsupported(self, mock_activate):
Expand Down
34 changes: 17 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Django==1.4.22
amqp==1.4.7
APScheduler==3.0.4
autopep8==1.2.1
billiard==3.3.0.21
celery==3.1.19
coverage==4.0.1
django-celery==3.1.17
django-configurations==0.8
Django==1.11.2
amqp==2.1.4
APScheduler==3.3.1
autopep8==1.3.2
billiard==3.5.0.2
celery==3.1.25
coverage==4.4.1
django-celery==3.2.1
django-configurations==2.0
django-coverage==1.2.4
django-ses==0.7.0
django-ses==0.8.2
dogapi==1.11.1
dogstatsd-python==0.5.6
kombu==3.0.37
logilab-astng==0.24.3
logilab-common==1.1.0
mock==1.0.1
logilab-common==1.4.0
mock==1.3.0
MySQL-python==1.2.5
pep8==1.6.2
pylint==1.4.4
python-dateutil==2.4.2
pytz==2015.7
requests==2.8.1
pep8==1.7.0
pylint==1.7.1
python-dateutil==2.6.0
pytz==2017.2
requests==2.17.3
six==1.10.0
transifex-client
wsgiref==0.1.2
Expand Down