Skip to content
Snippets Groups Projects
Unverified Commit 7ec58fd7 authored by David Ormsbee's avatar David Ormsbee Committed by GitHub
Browse files

Merge pull request #19906 from...

Merge pull request #19906 from open-craft/opencraft/edx-platform/devan/editable-weekly-course-highlight-emails

Allow a configurable number of weekly course highlight emails
parents ce295216 b31ca38f
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ Base management command for sending emails
import datetime
import pytz
from six.moves import range
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
......@@ -14,7 +15,10 @@ from openedx.core.djangoapps.schedules.utils import PrefixedDebugLoggerMixin
class SendEmailBaseCommand(PrefixedDebugLoggerMixin, BaseCommand):
async_send_task = None # define in subclass
offsets = () # define in subclass
# An iterable of day offsets (e.g. -7, -14, -21, -28, ...) that defines the days for
# which emails are sent out, relative to the 'date' parameter
offsets = range(-7, -77, -7)
def add_arguments(self, parser):
parser.add_argument(
......@@ -27,10 +31,20 @@ class SendEmailBaseCommand(PrefixedDebugLoggerMixin, BaseCommand):
help='Send all emails to this address instead of the actual recipient'
)
parser.add_argument('site_domain_name')
parser.add_argument(
'--weeks',
type=int,
help='Number of weekly emails to be sent',
)
def handle(self, *args, **options):
self.log_debug('Args = %r', options)
if 'weeks' in options:
num_weeks = options['weeks']
num_days = (7 * num_weeks) + 1
self.offsets = range(-7, -num_days, -7)
current_date = datetime.datetime(
*[int(x) for x in options['date'].split('-')],
tzinfo=pytz.UTC
......
......@@ -5,7 +5,6 @@ Management command to send Schedule course updates
from textwrap import dedent
from six.moves import range
from openedx.core.djangoapps.schedules.management.commands import SendEmailBaseCommand
from openedx.core.djangoapps.schedules.tasks import ScheduleCourseUpdate
......@@ -18,4 +17,3 @@ class Command(SendEmailBaseCommand):
help = dedent(__doc__).strip()
async_send_task = ScheduleCourseUpdate
log_prefix = 'Course Update'
offsets = range(-7, -77, -7)
......@@ -36,6 +36,11 @@ class TestSendEmailBaseCommand(CacheIsolationTestCase):
None
)
def test_weeks_option(self):
with patch.object(self.command, 'enqueue') as enqueue:
self.command.handle(site_domain_name=self.site.domain, date='2017-09-29', weeks=12)
self.assertEqual(enqueue.call_count, 12)
def test_send_emails(self):
with patch.multiple(
self.command,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment