diff --git a/notifier/digest.py b/notifier/digest.py index 31a7a09..30588f8 100644 --- a/notifier/digest.py +++ b/notifier/digest.py @@ -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 @@ -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, @@ -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) diff --git a/notifier/management/commands/forums_digest.py b/notifier/management/commands/forums_digest.py index 41350b1..3858cf4 100644 --- a/notifier/management/commands/forums_digest.py +++ b/notifier/management/commands/forums_digest.py @@ -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 @@ -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 - diff --git a/notifier/management/commands/scheduler.py b/notifier/management/commands/scheduler.py index 9ec996f..331ed48 100644 --- a/notifier/management/commands/scheduler.py +++ b/notifier/management/commands/scheduler.py @@ -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 diff --git a/notifier/settings.py b/notifier/settings.py index f54780f..cdb277c 100644 --- a/notifier/settings.py +++ b/notifier/settings.py @@ -3,6 +3,9 @@ import os import platform +# Change this +SECRET_KEY = "bI7S2DOOdOLHu3pry1hr2glKlBvBRIB9Uz9CjjI69nOdFyyhsLww06y95z3caIoC0H6RzwLQQe0B9gE43QUM4hjBy6OHhpv1Fwil" + DATABASES = { 'default': { # Database backend defaults to 'sqlite3', but 'mysql' is also supported. @@ -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') diff --git a/notifier/tests/test_digest.py b/notifier/tests/test_digest.py index d08cd7b..85e1afa 100644 --- a/notifier/tests/test_digest.py +++ b/notifier/tests/test_digest.py @@ -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): diff --git a/requirements.txt b/requirements.txt index fed8f2e..83383dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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