Skip to content

Commit

Permalink
Add new app for emails
Browse files Browse the repository at this point in the history
While this is at the moment tied to the gym module, it is possible to use
this in the future e.g. in groups.
  • Loading branch information
rolandgeider committed Oct 5, 2015
1 parent f03b971 commit 0003ff3
Show file tree
Hide file tree
Showing 19 changed files with 588 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -7,7 +7,7 @@ django-browserid==1.0
django-recaptcha
reportlab
django_mobile
django-formtools
django-formtools==1.0
bleach
python-mimeparse
pillow
Expand Down
21 changes: 21 additions & 0 deletions wger/email/__init__.py
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.

from wger import get_version

VERSION = get_version()
default_app_config = 'wger.email.apps.Config'
25 changes: 25 additions & 0 deletions wger/email/apps.py
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-

# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

from django.apps import AppConfig


class Config(AppConfig):
name = 'wger.email'
verbose_name = "Email"

def ready(self):
pass
35 changes: 35 additions & 0 deletions wger/email/forms.py
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License


from django.utils.translation import (
pgettext,
ugettext_lazy as _
)
from django.forms import (
Form,
CharField,
Textarea
)


class EmailListForm(Form):
'''
Small form to send emails
'''

subject = CharField(label=pgettext('Subject', 'As in "email subject"'))
body = CharField(widget=Textarea, label=pgettext('Content', 'As in "content of an email"'))
Empty file.
Empty file.
40 changes: 40 additions & 0 deletions wger/email/management/commands/send-mass-emails.py
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-

# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

from django.core import mail
from django.conf import settings

from django.core.management.base import BaseCommand
from wger.email.models import CronEntry


class Command(BaseCommand):
'''
Sends the prepared mass emails
'''

def handle(self, *args, **options):
'''
Send some mails and remove them from the list
'''
if CronEntry.objects.count():
for email in CronEntry.objects.all()[:100]:
mail.send_mail(email.log.subject,
email.log.body,
settings.DEFAULT_FROM_EMAIL,
[email.email],
fail_silently=True)
email.delete()
39 changes: 39 additions & 0 deletions wger/email/migrations/0001_initial.py
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
('gym', '0004_auto_20151003_2357'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='CronEntry',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('email', models.EmailField(max_length=254)),
],
),
migrations.CreateModel(
name='Log',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('date', models.DateField(auto_now=True)),
('subject', models.CharField(max_length=100)),
('body', models.TextField()),
('gym', models.ForeignKey(editable=False, to='gym.Gym')),
('user', models.ForeignKey(editable=False, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='cronentry',
name='log',
field=models.ForeignKey(editable=False, to='email.Log'),
),
]
Empty file.
84 changes: 84 additions & 0 deletions wger/email/models.py
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

from django.contrib.auth.models import User
from django.db import models

from wger.gym.models import Gym


class Log(models.Model):
'''
A log of a sent email
'''

date = models.DateField(auto_now=True)
'''
Date when the log was created
'''

user = models.ForeignKey(User,
editable=False)
'''
The user that created the email
'''

gym = models.ForeignKey(Gym,
editable=False,
related_name='email_log'
)
'''
Gym this log belongs to
'''

subject = models.CharField(max_length=100)
'''
The email subject
'''

body = models.TextField()
'''
The email body
'''

def __unicode__(self):
'''
Return a more human-readable representation
'''
return self.subject


class CronEntry(models.Model):
'''
Simple list of emails to be sent by a cron job
'''

log = models.ForeignKey(Log,
editable=False)
'''
Foreign key to email log with subject and body
'''

email = models.EmailField()
'''
The email address
'''

def __unicode__(self):
'''
Return a more human-readable representation
'''
return self.email
39 changes: 39 additions & 0 deletions wger/email/templates/email/form.html
@@ -0,0 +1,39 @@
{% extends "base.html" %}
{% load wger_extras %}
{% load i18n %}

{% block title %}
Emailverteiler -
{% if email_type == 'starter' %}
Starter
{% else %}
Studio
{% endif %}
{% endblock %}

{% block content %}
<form action="{{ form_action }}"
method="post"
class="form-horizontal">
{% render_form_fields form "Vorschau erzeugen" %}
</form>
{% endblock %}

{% block sidebar %}
<div class="well">
<h4>Benutzung</h4>
<ol>
<li>Geben Sie die nötigen Daten in das Formular ein.</li>
<li>Die Manager bekommen eine Vorschau-Email, zur Kontrolle.</li>
<li>
Sie können beliebig oft den Inhalt korrigieren und über die
Vorschau-Emails kontrollieren.
</li>
<li>
Wenn Sie mit dem Inhalt zufrieden sind, können Sie die Emails
freigeben, sie weden in den nächsten Studen automatisch
verschickt
</li>
</ol>
</div>
{% endblock %}
29 changes: 29 additions & 0 deletions wger/email/templates/email/overview.html
@@ -0,0 +1,29 @@
{% extends "base.html" %}
{% load wger_extras i18n %}

{% block title %}{% Email %}{% endblock %}

{% block content %}

<p>Bitte wählen Sie die Empfänger</p>

<h4>Log</h4>
<table class="table">
<tr>
<th>{% trans "Date" %}</th>
<th>Typ</th>
<th>Betreff</th>
</tr>
{% for email in email_list %}
<tr>
<td>{{ email.date }}</td>
<td>{{ email.get_type_display }}</td>
<td>{{ email.subject }}</td>
</tr>
{% endfor %}
</table>

{% endblock %}

{% block sidebar %}
{% endblock %}

0 comments on commit 0003ff3

Please sign in to comment.