Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
just need to create the POST for test emails
- Loading branch information
Jamie Counsell
committed
Dec 7, 2017
1 parent
937379d
commit c409fc5
Showing
25 changed files
with
324 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,9 @@ output/*/index.html | |
|
||
# Sphinx | ||
docs/_build | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# Other | ||
db.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__version__ = '0.1.0' | ||
default_app_config = 'django_des.apps.DjangoDesConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
), | ||
] |
20 changes: 20 additions & 0 deletions
20
django_des/migrations/0002_dynamicemailconfiguration_email_use_ssl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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?'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> › | ||
<a href="../">{{ opts.app_config.verbose_name|capfirst|escape }}</a> › | ||
{{ 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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> › | ||
<a href="../../">{{ opts.app_label|capfirst|escape }}</a> › | ||
<a href="../">{{ object|truncatewords:"18" }}</a> › | ||
{% trans 'History' %} | ||
|
||
</div> | ||
{% endblock %} |
Oops, something went wrong.