From ddf377cfb90148cff2ba2d729692a634bdf92bc6 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 1 Feb 2014 06:50:15 -0500 Subject: [PATCH] Remove unused massemail commands. --- .../student/management/commands/massemail.py | 22 ------- .../management/commands/massemailtxt.py | 60 ------------------- .../student/tests/emails/test_body.txt | 1 - .../student/tests/emails/test_subject.txt | 1 - .../student/tests/test_massemail.py | 50 ---------------- .../student/tests/test_massemail_users.txt | 2 - lms/templates/emails/welcome_body.txt | 32 ---------- lms/templates/emails/welcome_subject.txt | 7 --- 8 files changed, 175 deletions(-) delete mode 100644 common/djangoapps/student/management/commands/massemail.py delete mode 100644 common/djangoapps/student/management/commands/massemailtxt.py delete mode 100644 common/djangoapps/student/tests/emails/test_body.txt delete mode 100644 common/djangoapps/student/tests/emails/test_subject.txt delete mode 100644 common/djangoapps/student/tests/test_massemail.py delete mode 100644 common/djangoapps/student/tests/test_massemail_users.txt delete mode 100644 lms/templates/emails/welcome_body.txt delete mode 100644 lms/templates/emails/welcome_subject.txt diff --git a/common/djangoapps/student/management/commands/massemail.py b/common/djangoapps/student/management/commands/massemail.py deleted file mode 100644 index 8e9e2ba69f..0000000000 --- a/common/djangoapps/student/management/commands/massemail.py +++ /dev/null @@ -1,22 +0,0 @@ -from django.core.management.base import BaseCommand -from django.contrib.auth.models import User - -from edxmako import lookup_template - - -class Command(BaseCommand): - help = \ -'''Sends an e-mail to all users. Takes a single -parameter -- name of e-mail template -- located -in templates/email. Adds a .txt for the message -body, and an _subject.txt for the subject. ''' - - def handle(self, *args, **options): - #text = open(args[0]).read() - #subject = open(args[1]).read() - users = User.objects.all() - text = lookup_template('main', 'email/' + args[0] + ".txt").render() - subject = lookup_template('main', 'email/' + args[0] + "_subject.txt").render().strip() - for user in users: - if user.is_active: - user.email_user(subject, text) diff --git a/common/djangoapps/student/management/commands/massemailtxt.py b/common/djangoapps/student/management/commands/massemailtxt.py deleted file mode 100644 index e3ec851745..0000000000 --- a/common/djangoapps/student/management/commands/massemailtxt.py +++ /dev/null @@ -1,60 +0,0 @@ -import os.path -import time - -from django.core.management.base import BaseCommand -from django.conf import settings - -from edxmako import lookup_template - -from django.core.mail import send_mass_mail -import sys - -import datetime - - -def chunks(l, n): - """ Yield successive n-sized chunks from l. - """ - for i in xrange(0, len(l), n): - yield l[i:i + n] - - -class Command(BaseCommand): - help = \ -'''Sends an e-mail to all users in a text file. -E.g. -manage.py userlist.txt message logfile.txt rate -userlist.txt -- list of all users -message -- prefix for template with message -logfile.txt -- where to log progress -rate -- messages per second - ''' - log_file = None - - def hard_log(self, text): - self.log_file.write(datetime.datetime.utcnow().isoformat() + ' -- ' + text + '\n') - - def handle(self, *args, **options): - (user_file, message_base, logfilename, ratestr) = args - - users = [u.strip() for u in open(user_file).readlines()] - - message = lookup_template('main', 'emails/' + message_base + "_body.txt").render() - subject = lookup_template('main', 'emails/' + message_base + "_subject.txt").render().strip() - rate = int(ratestr) - - self.log_file = open(logfilename, "a+", buffering=0) - - i = 0 - for users in chunks(users, rate): - emails = [(subject, message, settings.DEFAULT_FROM_EMAIL, [u]) for u in users] - self.hard_log(" ".join(users)) - send_mass_mail(emails, fail_silently=False) - time.sleep(1) - print datetime.datetime.utcnow().isoformat(), i - i = i + len(users) - # Emergency interruptor - if os.path.exists("/tmp/stopemails.txt"): - self.log_file.close() - sys.exit(-1) - self.log_file.close() diff --git a/common/djangoapps/student/tests/emails/test_body.txt b/common/djangoapps/student/tests/emails/test_body.txt deleted file mode 100644 index 11115a5a72..0000000000 --- a/common/djangoapps/student/tests/emails/test_body.txt +++ /dev/null @@ -1 +0,0 @@ -Test body. diff --git a/common/djangoapps/student/tests/emails/test_subject.txt b/common/djangoapps/student/tests/emails/test_subject.txt deleted file mode 100644 index 6f4d1f63dc..0000000000 --- a/common/djangoapps/student/tests/emails/test_subject.txt +++ /dev/null @@ -1 +0,0 @@ -Test subject. diff --git a/common/djangoapps/student/tests/test_massemail.py b/common/djangoapps/student/tests/test_massemail.py deleted file mode 100644 index 39311a528b..0000000000 --- a/common/djangoapps/student/tests/test_massemail.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -Test `massemail` and `massemailtxt` commands. -""" -import mock -import pkg_resources - -from django.core import mail -from django.test import TestCase - -from edxmako import add_lookup -from ..management.commands import massemail -from ..management.commands import massemailtxt - - -class TestMassEmailCommands(TestCase): - """ - Test `massemail` and `massemailtxt` commands. - """ - - @mock.patch('edxmako.LOOKUP', {}) - def test_massemailtxt(self): - """ - Test the `massemailtext` command. - """ - add_lookup('main', '', package=__name__) - userfile = pkg_resources.resource_filename(__name__, 'test_massemail_users.txt') - command = massemailtxt.Command() - command.handle(userfile, 'test', '/dev/null', 10) - self.assertEqual(len(mail.outbox), 2) - self.assertEqual(mail.outbox[0].to, ["Fred"]) - self.assertEqual(mail.outbox[0].subject, "Test subject.") - self.assertEqual(mail.outbox[0].body.strip(), "Test body.") - self.assertEqual(mail.outbox[1].to, ["Barney"]) - self.assertEqual(mail.outbox[1].subject, "Test subject.") - self.assertEqual(mail.outbox[1].body.strip(), "Test body.") - - @mock.patch('edxmako.LOOKUP', {}) - @mock.patch('student.management.commands.massemail.User') - def test_massemail(self, usercls): - """ - Test the `massemail` command. - """ - add_lookup('main', '', package=__name__) - fred = mock.Mock() - barney = mock.Mock() - usercls.objects.all.return_value = [fred, barney] - command = massemail.Command() - command.handle('test') - fred.email_user.assert_called_once_with('Test subject.', 'Test body.\n') - barney.email_user.assert_called_once_with('Test subject.', 'Test body.\n') diff --git a/common/djangoapps/student/tests/test_massemail_users.txt b/common/djangoapps/student/tests/test_massemail_users.txt deleted file mode 100644 index 98afe6a240..0000000000 --- a/common/djangoapps/student/tests/test_massemail_users.txt +++ /dev/null @@ -1,2 +0,0 @@ -Fred -Barney diff --git a/lms/templates/emails/welcome_body.txt b/lms/templates/emails/welcome_body.txt deleted file mode 100644 index f7ffe45546..0000000000 --- a/lms/templates/emails/welcome_body.txt +++ /dev/null @@ -1,32 +0,0 @@ -<%namespace file="../main.html" import="stanford_theme_enabled" /> -## TODO: fix ugly hack -% if stanford_theme_enabled(): - ${settings.PLATFORM_NAME} Courses has launched! To log in, visit: -% else: - ${settings.PLATFORM_NAME} has launched! To log in, visit: -% endif - -% if is_secure: - https://${settings.SITE_NAME} -% else: - http://${settings.SITE_NAME} -% endif - -A login button will be at the top right-hand corner of the window. - -Please make sure you're using the latest version of Google Chrome or -Firefox. If you've forgotten your password, the log-in form has a -place to reset it. - -Thanks for joining us for the ride! - -## TODO: fix ugly hack -% if stanford_theme_enabled(): - The ${settings.PLATFORM_NAME} Courses team -% else: - The ${settings.PLATFORM_NAME} team -% endif - -(Please note that this e-mail address does not receive e-mails -- -if you need assistance, please use the help section of the web -site) diff --git a/lms/templates/emails/welcome_subject.txt b/lms/templates/emails/welcome_subject.txt deleted file mode 100644 index 0b0f831f7e..0000000000 --- a/lms/templates/emails/welcome_subject.txt +++ /dev/null @@ -1,7 +0,0 @@ -<%namespace file="../main.html" import="stanford_theme_enabled" /> -## TODO: fix ugly hack -% if stanford_theme_enabled(): - Welcome to ${settings.PLATFORM_NAME} Courses! -% else: - Welcome to ${settings.PLATFORM_NAME}! -% endif