Skip to content

Commit 0700f5b

Browse files
committed
Add examples app
1 parent 711648e commit 0700f5b

14 files changed

+206
-0
lines changed

examples/__init__.py

Whitespace-only changes.

examples/config/__init__.py

Whitespace-only changes.

examples/config/settings.py

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import os
2+
3+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
4+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5+
6+
7+
# Quick-start development settings - unsuitable for production
8+
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
9+
10+
# SECURITY WARNING: keep the secret key used in production secret!
11+
SECRET_KEY = '()!xq2ufm%j@n^!v^p08&w87vvg)rk^=aoj8u1(4xho5iuh-)l'
12+
13+
# SECURITY WARNING: don't run with debug turned on in production!
14+
DEBUG = True
15+
16+
ALLOWED_HOSTS = []
17+
18+
19+
# Application definition
20+
21+
INSTALLED_APPS = [
22+
'django.contrib.admin',
23+
'django.contrib.auth',
24+
'django.contrib.contenttypes',
25+
'django.contrib.sessions',
26+
'django.contrib.messages',
27+
'django.contrib.staticfiles',
28+
29+
'templated_mail',
30+
31+
'simple',
32+
]
33+
34+
MIDDLEWARE = [
35+
'django.middleware.security.SecurityMiddleware',
36+
'django.contrib.sessions.middleware.SessionMiddleware',
37+
'django.middleware.common.CommonMiddleware',
38+
'django.middleware.csrf.CsrfViewMiddleware',
39+
'django.contrib.auth.middleware.AuthenticationMiddleware',
40+
'django.contrib.messages.middleware.MessageMiddleware',
41+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
42+
]
43+
44+
ROOT_URLCONF = 'config.urls'
45+
46+
TEMPLATES = [
47+
{
48+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
49+
'DIRS': ['templates'],
50+
'APP_DIRS': True,
51+
'OPTIONS': {
52+
'context_processors': [
53+
'django.template.context_processors.debug',
54+
'django.template.context_processors.request',
55+
'django.contrib.auth.context_processors.auth',
56+
'django.contrib.messages.context_processors.messages',
57+
],
58+
},
59+
},
60+
]
61+
62+
WSGI_APPLICATION = 'config.wsgi.application'
63+
64+
65+
# Database
66+
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
67+
68+
DATABASES = {
69+
'default': {
70+
'ENGINE': 'django.db.backends.sqlite3',
71+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
72+
}
73+
}
74+
75+
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
76+
77+
# Password validation
78+
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
79+
80+
AUTH_PASSWORD_VALIDATORS = [
81+
{
82+
'NAME': 'django.contrib.auth.password_validation.'
83+
'UserAttributeSimilarityValidator',
84+
},
85+
{
86+
'NAME': 'django.contrib.auth.password_validation.'
87+
'MinimumLengthValidator',
88+
},
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.'
91+
'CommonPasswordValidator',
92+
},
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.'
95+
'NumericPasswordValidator',
96+
},
97+
]
98+
99+
100+
# Internationalization
101+
# https://docs.djangoproject.com/en/1.11/topics/i18n/
102+
103+
LANGUAGE_CODE = 'en-us'
104+
105+
TIME_ZONE = 'UTC'
106+
107+
USE_I18N = True
108+
109+
USE_L10N = True
110+
111+
USE_TZ = True
112+
113+
114+
# Static files (CSS, JavaScript, Images)
115+
# https://docs.djangoproject.com/en/1.11/howto/static-files/
116+
117+
STATIC_URL = '/static/'

examples/config/urls.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.conf.urls import include, url
2+
from django.contrib import admin
3+
4+
urlpatterns = [
5+
url(r'^admin/', admin.site.urls),
6+
url(r'^simple/', include('simple.urls', namespace='simple')),
7+
]

examples/config/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for config project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
15+
16+
application = get_wsgi_application()

examples/manage.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
7+
from django.core.management import execute_from_command_line
8+
execute_from_command_line(sys.argv)

examples/simple/__init__.py

Whitespace-only changes.

examples/simple/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class SimpleConfig(AppConfig):
5+
name = 'simple'

examples/simple/migrations/__init__.py

Whitespace-only changes.

examples/simple/urls.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf.urls import url
2+
3+
from simple import views
4+
5+
6+
urlpatterns = [
7+
url(r'^mail/txt_and_html', views.text_and_html_mail_view),
8+
url(r'^mail/txt', views.text_mail_view),
9+
url(r'^mail/html', views.html_mail_view),
10+
]

examples/simple/views.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from django.http import HttpResponse
2+
3+
from templated_mail.mail import BaseEmailMessage
4+
5+
6+
class TextEmailMessage(BaseEmailMessage):
7+
template_name = 'text_mail.html'
8+
9+
10+
class HTMLEmailMessage(BaseEmailMessage):
11+
template_name = 'html_mail.html'
12+
13+
14+
class TextAndHTMLEmailMessage(BaseEmailMessage):
15+
template_name = 'text_and_html_mail.html'
16+
17+
18+
def text_mail_view(request):
19+
recipients = ['foo@bar.tld']
20+
TextEmailMessage(request).send(to=recipients)
21+
return HttpResponse('Text mail has been sent.')
22+
23+
24+
def html_mail_view(request):
25+
recipients = ['foo@bar.tld']
26+
HTMLEmailMessage(request).send(to=recipients)
27+
return HttpResponse('HTML mail has been sent.')
28+
29+
30+
def text_and_html_mail_view(request):
31+
recipients = ['foo@bar.tld']
32+
TextAndHTMLEmailMessage(request).send(to=recipients)
33+
return HttpResponse('Text and HTML mail has been sent.')

examples/templates/html_mail.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% block subject %}HTML mail subject{% endblock %}
2+
3+
{% block html_body %}<p>Foobar email content</p>{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% block subject %}Text and HTML mail subject{% endblock %}
2+
3+
{% block text_body %}Foobar email content{% endblock %}
4+
{% block html_body %}<p>Foobar email content</p>{% endblock %}

examples/templates/text_mail.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% block subject %}Text mail subject{% endblock %}
2+
3+
{% block text_body %}Foobar email content{% endblock %}

0 commit comments

Comments
 (0)