Remove unused massemail commands.
This commit is contained in:
@@ -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)
|
||||
@@ -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()
|
||||
@@ -1 +0,0 @@
|
||||
Test body.
|
||||
@@ -1 +0,0 @@
|
||||
Test subject.
|
||||
@@ -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')
|
||||
@@ -1,2 +0,0 @@
|
||||
Fred
|
||||
Barney
|
||||
@@ -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)
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user