Skip to content

Commit

Permalink
just need to create the POST for test emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Counsell committed Dec 7, 2017
1 parent 937379d commit c409fc5
Show file tree
Hide file tree
Showing 25 changed files with 324 additions and 54 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -45,3 +45,9 @@ output/*/index.html

# Sphinx
docs/_build

# pyenv
.python-version

# Other
db.sqlite3
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -16,6 +16,13 @@ env:
- TOX_ENV=py35-django-110
- TOX_ENV=py34-django-110
- TOX_ENV=py27-django-110
- TOX_ENV=py36-django-111
- TOX_ENV=py35-django-111
- TOX_ENV=py34-django-111
- TOX_ENV=py27-django-111
- TOX_ENV=py36-django-20
- TOX_ENV=py35-django-20
- TOX_ENV=py34-django-20

matrix:
fast_finish: true
Expand Down
18 changes: 3 additions & 15 deletions README.rst
Expand Up @@ -31,23 +31,10 @@ Add it to your `INSTALLED_APPS`:
INSTALLED_APPS = (
...
'django_des.apps.DjangoDesConfig',
'django_des',
...
)
Add Django Dynamic Email Settings's URL patterns:

.. code-block:: python
from django_des import urls as django_des_urls
urlpatterns = [
...
url(r'^', include(django_des_urls)),
...
]
Features
--------

Expand All @@ -61,7 +48,8 @@ Does the code actually work?
::

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ pip install -r requirements_dev.txt
(myenv) $ pip install -r requirements_test.txt
(myenv) $ tox

Credits
Expand Down
1 change: 1 addition & 0 deletions django_des/__init__.py
@@ -1 +1,2 @@
__version__ = '0.1.0'
default_app_config = 'django_des.apps.DjangoDesConfig'
14 changes: 14 additions & 0 deletions django_des/admin.py
@@ -0,0 +1,14 @@
## -*- coding: utf-8 -*-
from django_des.models import DynamicEmailConfiguration
from django.contrib import admin
from solo.admin import SingletonModelAdmin


class DynamicEmailConfigurationAdmin(SingletonModelAdmin):
class Media:
js = ('js/django_des.js'),
css = {
'all': ('css/django_des.css',)
}

admin.site.register(DynamicEmailConfiguration, DynamicEmailConfigurationAdmin)
2 changes: 2 additions & 0 deletions django_des/apps.py
Expand Up @@ -4,3 +4,5 @@

class DjangoDesConfig(AppConfig):
name = 'django_des'
verbose_name = 'Dynamic Email Settings'
verbose_name_plural = verbose_name
34 changes: 34 additions & 0 deletions django_des/backends.py
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import threading

from django.core.exceptions import AppRegistryNotReady
from django.core.mail.backends.smtp import EmailBackend


class ConfiguredEmailBackend(EmailBackend):
def __init__(self, host = None, port = None, username = None, password = None,
use_tls = None, fail_silently = False, use_ssl = None, timeout = None,
ssl_keyfile = None, ssl_certfile = None,
**kwargs):

from django_des.models import DynamicEmailConfiguration
configuration = DynamicEmailConfiguration.get_solo()

super(ConfiguredEmailBackend, self).__init__(
fail_silently = configuration.email_fail_silently)

self.host = host or configuration.email_host
self.port = port or configuration.email_port
self.username = username or configuration.email_host_user
self.password = password or configuration.email_host_password
self.use_tls = use_tls or configuration.email_use_tls
self.use_ssl = use_ssl or configuration.email_use_ssl
self.timeout = timeout or configuration.email_timeout
self.ssl_keyfile = ssl_keyfile # TODO: support this in admin
self.ssl_certfile = ssl_certfile # TODO: support this in admin
if self.use_ssl and self.use_tls:
raise ValueError(
"EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, "
"so only set one of those settings to True.")
self.connection = None
self._lock = threading.RLock()
33 changes: 33 additions & 0 deletions django_des/migrations/0001_initial.py
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-12-07 18:38
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='DynamicEmailConfiguration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email_host', models.CharField(max_length=100, verbose_name=b'Email Host')),
('email_port', models.SmallIntegerField(default=25, verbose_name=b'Email Port')),
('email_from_email', models.CharField(max_length=50, verbose_name=b'Default From Email')),
('email_host_user', models.CharField(max_length=50, verbose_name=b'Email User')),
('email_host_password', models.CharField(max_length=50, verbose_name=b'Email User Password')),
('email_use_tls', models.BooleanField(default=False, verbose_name=b'Use TLS?')),
('email_fail_silently', models.BooleanField(default=False, verbose_name=b'Fail Silently?')),
('email_timeout', models.SmallIntegerField(default=60, verbose_name=b'Email Send Timeout')),
],
options={
'verbose_name': 'Email Configuration',
},
),
]
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-12-07 19:30
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_des', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='dynamicemailconfiguration',
name='email_use_ssl',
field=models.BooleanField(default=False, verbose_name=b'Use SSL?'),
),
]
20 changes: 20 additions & 0 deletions django_des/migrations/0003_auto_20171207_1935.py
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-12-07 19:35
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_des', '0002_dynamicemailconfiguration_email_use_ssl'),
]

operations = [
migrations.AlterField(
model_name='dynamicemailconfiguration',
name='email_use_ssl',
field=models.BooleanField(default=False, verbose_name=b'Use SSL? (Requires EMAIL_SSL_CERTFILE and EMAIL_SSL_KEYFILE to be defined in settings.py)'),
),
]
File renamed without changes.
47 changes: 47 additions & 0 deletions django_des/models.py
@@ -1,2 +1,49 @@
# -*- coding: utf-8 -*-
from django.db import models
from solo.models import SingletonModel
from django.core.exceptions import ValidationError


class DynamicEmailConfiguration(SingletonModel):
email_host = models.CharField(
max_length = 100, verbose_name = "Email Host")

email_port = models.SmallIntegerField(
blank = False, null = False, default = 25,
verbose_name = "Email Port")

email_from_email = models.CharField(
max_length = 50, verbose_name = "Default From Email")

email_host_user = models.CharField(
max_length = 50, verbose_name = "Email User")

email_host_password = models.CharField(
max_length = 50, verbose_name = "Email User Password")

email_use_tls = models.BooleanField(
default = False, verbose_name = "Use TLS?")

email_use_ssl = models.BooleanField(
default = False, verbose_name = "Use SSL? (Requires "
"EMAIL_SSL_CERTFILE and EMAIL_SSL_KEYFILE to be defined "
"in settings.py)")

email_fail_silently = models.BooleanField(
default = False, verbose_name = "Fail Silently?")

email_timeout = models.SmallIntegerField(
blank = False, null = False, default = 60,
verbose_name = "Email Send Timeout")

def clean(self):
if self.email_use_ssl and self.email_use_tls:
raise ValidationError(
"\"Use TLS\" and \"Use SSL\" are mutually exclusive, "
"so only set one of those settings to True.")

def __str__(self):
return u"Email Configuration"

class Meta:
verbose_name = "Email Configuration"
57 changes: 57 additions & 0 deletions django_des/static/css/django_des.css
@@ -0,0 +1,57 @@
#django_des--test-input {
color: white;
background: none;
border: 0;
border-bottom: 1px solid white;
height: 1.15em;
margin: -2px 0 0 0;
}

input#django_des--test-input::-webkit-input-placeholder {
color: white;
font-weight: lighter;
opacity: 0.4;
}

input#django_des--test-input:-moz-placeholder { /* Firefox 18- */
color: white;
font-weight: lighter;
opacity: 0.4;
}

input#django_des--test-input::-moz-placeholder { /* Firefox 19+ */
color: white;
font-weight: lighter;
opacity: 0.4;
}

input#django_des--test-input:-ms-input-placeholder {
color: white;
font-weight: lighter;
opacity: 0.4;
}

#django_des--test-button.error {
border-width: 1px;
border-color: #ba2121;
}

#django_des--test-button {
display: block;
float: left;
padding: 3px 12px;
background: #999;
border: 1px solid white;
list-style-type: square;
font-size: 13px;
line-height: 20px;
font-weight: 400;
font-size: 11px;
cursor: pointer;
text-transform: uppercase;
letter-spacing: 0.5px;
color: #fff;
border-radius: 15px;
text-decoration: none;
margin-top: -1px;
}
25 changes: 25 additions & 0 deletions django_des/static/js/django_des.js
@@ -0,0 +1,25 @@
function stop_event(e) {
e.stopPropagation();
e.preventDefault();
}

document.addEventListener("DOMContentLoaded", function(event) {
var input = document.getElementById('django_des--test-input');
var form = document.getElementById('django_des--test-form');
var button = document.getElementById('django_des--test-button');

input.addEventListener('click', function(e){
stop_event(e);
button.classList.remove("error");
});

form.addEventListener('submit', function(e){
stop_event(e);
var email = e.target.elements.email.value;
if (email) {
e.target.submit();
} else {
button.classList.add("error");
}
});
})
29 changes: 29 additions & 0 deletions django_des/templates/admin/solo/change_form.html
@@ -0,0 +1,29 @@
<!--
Template courtesy of django-solo project:
https://github.com/lazybird/django-solo
-->
{% extends "admin/change_form.html" %}
{% load i18n %}
{% load admin_urls %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> &rsaquo;
<a href="../">{{ opts.app_config.verbose_name|capfirst|escape }}</a> &rsaquo;
{{ opts.verbose_name|capfirst }}
</div>
{% endblock %}

{% block object-tools-items %}
<li><a href="{% url opts|admin_urlname:'history' %}" class="historylink">{% trans "History" %}</a></li>
<li>
<form id="django_des--test-form" action="{% url opts|admin_urlname:'history' %}" method="POST">
<button type="submit" id="django_des--test-button">
{% csrf_token %}
{% trans "Send Test Email" %}
<input name="email" id="django_des--test-input" placeholder="example@website.com">
</button>
</form>
</li>
{% if has_absolute_url %}<li><a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
{% endblock %}
16 changes: 16 additions & 0 deletions django_des/templates/admin/solo/object_history.html
@@ -0,0 +1,16 @@
<!--
Template courtesy of django-solo project:
https://github.com/lazybird/django-solo
-->
{% extends "admin/object_history.html" %}
{% load i18n %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> &rsaquo;
<a href="../../">{{ opts.app_label|capfirst|escape }}</a> &rsaquo;
<a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo;
{% trans 'History' %}

</div>
{% endblock %}

0 comments on commit c409fc5

Please sign in to comment.