Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.0.0 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions des/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '2.4.1'
default_app_config = 'des.apps.DjangoDesConfig'
__version__ = "3.0.0"
default_app_config = "des.apps.DjangoDesConfig"
13 changes: 7 additions & 6 deletions des/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
## -*- coding: utf-8 -*-
from des.models import DynamicEmailConfiguration
from django.contrib import admin
from solo.admin import SingletonModelAdmin

from des.forms import DynamicEmailConfigurationForm
from des.models import DynamicEmailConfiguration


class DynamicEmailConfigurationAdmin(SingletonModelAdmin):
form = DynamicEmailConfigurationForm
change_form_template = 'des/change_form.html'
change_form_template = "des/change_form.html"

class Media:
js = ('js/des.js'),
css = {
'all': ('css/des.css',)
}
js = (("js/des.js"),)
css = {"all": ("css/des.css",)}


admin.site.register(DynamicEmailConfiguration, DynamicEmailConfigurationAdmin)
4 changes: 2 additions & 2 deletions des/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@


class DjangoDesConfig(AppConfig):
name = 'des'
verbose_name = 'Dynamic Email Settings'
name = "des"
verbose_name = "Dynamic Email Settings"
verbose_name_plural = verbose_name
46 changes: 30 additions & 16 deletions des/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,40 @@


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

from des.models import DynamicEmailConfiguration

configuration = DynamicEmailConfiguration.get_solo()

super(ConfiguredEmailBackend, self).__init__(
host = configuration.host if host is None else host,
port = configuration.port if port is None else port,
username = configuration.username if username is None else username,
password = configuration.password if password is None else password,
use_tls = configuration.use_tls if use_tls is None else use_tls,
fail_silently = configuration.fail_silently if fail_silently is None else fail_silently,
use_ssl = configuration.use_ssl if use_ssl is None else use_ssl,
timeout = configuration.timeout if timeout is None else timeout,
ssl_keyfile = ssl_keyfile, # TODO: configuration.ssl_keyfile if ssl_keyfile is not None else ssl_keyfile,
ssl_certfile = ssl_certfile, # TODO: configuration.ssl_certfile if ssl_certfile is not None else ssl_certfile,
**kwargs)
host=configuration.host if host is None else host,
port=configuration.port if port is None else port,
username=configuration.username if username is None else username,
password=configuration.password if password is None else password,
use_tls=configuration.use_tls if use_tls is None else use_tls,
fail_silently=(
configuration.fail_silently if fail_silently is None else fail_silently
),
use_ssl=configuration.use_ssl if use_ssl is None else use_ssl,
timeout=configuration.timeout if timeout is None else timeout,
ssl_keyfile=ssl_keyfile, # TODO: configuration.ssl_keyfile if ssl_keyfile is not None else ssl_keyfile,
ssl_certfile=ssl_certfile, # TODO: configuration.ssl_certfile if ssl_certfile is not None else ssl_certfile,
**kwargs
)


__all__ = ['ConfiguredEmailBackend']
__all__ = ["ConfiguredEmailBackend"]
1 change: 1 addition & 0 deletions des/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.forms import ModelForm, PasswordInput

from des.models import DynamicEmailConfiguration


Expand Down
8 changes: 4 additions & 4 deletions des/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from des.models import DynamicEmailConfiguration

try:
from django.urls import reverse
except ImportError:
Expand All @@ -7,8 +8,7 @@

def get_configuration_admin_url():
meta = DynamicEmailConfiguration._meta
return reverse('admin:{}_{}_change'.format(
meta.app_label, meta.model_name
))
return reverse("admin:{}_{}_change".format(meta.app_label, meta.model_name))


__all__ = ['get_configuration_admin_url']
__all__ = ["get_configuration_admin_url"]
79 changes: 65 additions & 14 deletions des/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,77 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='DynamicEmailConfiguration',
name="DynamicEmailConfiguration",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('host', models.CharField(blank=True, max_length=256, null=True, verbose_name='Email Host')),
('port', models.SmallIntegerField(blank=True, null=True, verbose_name='Email Port')),
('from_email', models.CharField(blank=True, max_length=256, null=True, verbose_name='Default From Email')),
('username', models.CharField(blank=True, max_length=256, null=True, verbose_name='Email Authentication Username')),
('password', models.CharField(blank=True, max_length=256, null=True, verbose_name='Email Authentication Password')),
('use_tls', models.BooleanField(default=False, verbose_name='Use TLS')),
('use_ssl', models.BooleanField(default=False, verbose_name='Use SSL')),
('fail_silently', models.BooleanField(default=False, verbose_name='Fail Silently')),
('timeout', models.SmallIntegerField(blank=True, null=True, verbose_name='Email Send Timeout (seconds)')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"host",
models.CharField(
blank=True, max_length=256, null=True, verbose_name="Email Host"
),
),
(
"port",
models.SmallIntegerField(
blank=True, null=True, verbose_name="Email Port"
),
),
(
"from_email",
models.CharField(
blank=True,
max_length=256,
null=True,
verbose_name="Default From Email",
),
),
(
"username",
models.CharField(
blank=True,
max_length=256,
null=True,
verbose_name="Email Authentication Username",
),
),
(
"password",
models.CharField(
blank=True,
max_length=256,
null=True,
verbose_name="Email Authentication Password",
),
),
("use_tls", models.BooleanField(default=False, verbose_name="Use TLS")),
("use_ssl", models.BooleanField(default=False, verbose_name="Use SSL")),
(
"fail_silently",
models.BooleanField(default=False, verbose_name="Fail Silently"),
),
(
"timeout",
models.SmallIntegerField(
blank=True,
null=True,
verbose_name="Email Send Timeout (seconds)",
),
),
],
options={
'verbose_name': 'Email Configuration',
"verbose_name": "Email Configuration",
},
),
]
55 changes: 30 additions & 25 deletions des/models.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,60 @@
# -*- coding: utf-8 -*-
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as ugettext
from django.utils.translation import gettext_lazy as _
from solo.models import SingletonModel
from django.core.exceptions import ValidationError


class DynamicEmailConfiguration(SingletonModel):
host = models.CharField(
blank = True, null = True,
max_length = 256, verbose_name = _("Email Host"))
blank=True, null=True, max_length=256, verbose_name=_("Email Host")
)

port = models.SmallIntegerField(
blank = True, null = True,
verbose_name = _("Email Port"))
port = models.SmallIntegerField(blank=True, null=True, verbose_name=_("Email Port"))

from_email = models.CharField(
blank = True, null = True,
max_length = 256, verbose_name = _("Default From Email"))
blank=True, null=True, max_length=256, verbose_name=_("Default From Email")
)

username = models.CharField(
blank = True, null = True,
max_length = 256, verbose_name = _("Email Authentication Username"))
blank=True,
null=True,
max_length=256,
verbose_name=_("Email Authentication Username"),
)

password = models.CharField(
blank = True, null = True,
max_length = 256, verbose_name = _("Email Authentication Password"))
blank=True,
null=True,
max_length=256,
verbose_name=_("Email Authentication Password"),
)

use_tls = models.BooleanField(
default = False, verbose_name = _("Use TLS"))
use_tls = models.BooleanField(default=False, verbose_name=_("Use TLS"))

use_ssl = models.BooleanField(
default = False, verbose_name = _("Use SSL"))
use_ssl = models.BooleanField(default=False, verbose_name=_("Use SSL"))

fail_silently = models.BooleanField(
default = False, verbose_name = _("Fail Silently"))
fail_silently = models.BooleanField(default=False, verbose_name=_("Fail Silently"))

timeout = models.SmallIntegerField(
blank = True, null = True,
verbose_name = _("Email Send Timeout (seconds)"))
blank=True, null=True, verbose_name=_("Email Send Timeout (seconds)")
)

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

def __str__(self):
return _("Email Configuration")
return ugettext("Email Configuration")

class Meta:
verbose_name = _("Email Configuration")


__all__ = ['DynamicEmailConfiguration']
__all__ = ["DynamicEmailConfiguration"]
8 changes: 4 additions & 4 deletions des/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from django.conf.urls import url
from des import views
from django.urls import path

from des import views

urlpatterns = [
url(r'^send-test-email', views.send_test_email, name = 'des-test-email'),
path("send-test-email", views.send_test_email, name="des-test-email"),
]

__all__ = ['urlpatterns']
__all__ = ["urlpatterns"]
40 changes: 21 additions & 19 deletions des/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from django.http import HttpResponseRedirect, HttpResponseNotFound
from django.views.decorators.http import require_http_methods
from django.contrib import messages
from django.template import loader
from django.conf import settings
from django.contrib import messages
from django.core.mail import send_mail
from django.utils.translation import ugettext as _
from des.models import DynamicEmailConfiguration
from django.http import HttpResponseNotFound, HttpResponseRedirect
from django.template import loader
from django.utils.translation import gettext_lazy as _
from django.views.decorators.http import require_http_methods

from des.helpers import get_configuration_admin_url
from des.models import DynamicEmailConfiguration

subject = getattr(settings, 'DES_TEST_SUBJECT', _("Test Email"))
text_template = getattr(settings, 'DES_TEST_TEXT_TEMPLATE', "des/test_email.txt")
html_template = getattr(settings, 'DES_TEST_HTML_TEMPLATE', None)
subject = getattr(settings, "DES_TEST_SUBJECT", _("Test Email"))
text_template = getattr(settings, "DES_TEST_TEXT_TEMPLATE", "des/test_email.txt")
html_template = getattr(settings, "DES_TEST_HTML_TEMPLATE", None)

message_text = loader.render_to_string(text_template)
message_html = loader.render_to_string(html_template) if html_template else None
Expand All @@ -22,7 +23,7 @@ def send_test_email(request):
if request.user is None or not request.user.is_staff:
return HttpResponseNotFound()

email = request.POST.get('email', None)
email = request.POST.get("email", None)
config = DynamicEmailConfiguration.get_solo()

if email:
Expand All @@ -32,14 +33,15 @@ def send_test_email(request):
message_text,
config.from_email or None,
[email],
html_message = message_html)

messages.success(request,
_("Test email sent. Please check \"{}\" for a "
"message with the subject \"{}\"").format(
email,
subject
)
html_message=message_html,
)

messages.success(
request,
_(
'Test email sent. Please check "{}" for a '
'message with the subject "{}"'
).format(email, subject),
)
except Exception as e:
messages.error(request, _("Could not send email. {}").format(e))
Expand All @@ -49,4 +51,4 @@ def send_test_email(request):
return HttpResponseRedirect(get_configuration_admin_url())


__all__ = ['send_test_email']
__all__ = ["send_test_email"]
Loading