Skip to content

Commit

Permalink
feat: Better Emails (#269)
Browse files Browse the repository at this point in the history
* load local .env

* Implement nicer emails

* Update common.py

* plaintext style changes

* Add tests for composer

* fix namespace

* email testing and inline css for outlook support

* track static files

* add panel component, and put receipt info into booking email

* add test for payment info in booking

* 100coverage

* Give default created target user names, and make anonymous booking emails more tailored

* fix test
  • Loading branch information
atoff authored Sep 27, 2021
1 parent 134d49d commit e46b479
Show file tree
Hide file tree
Showing 30 changed files with 983 additions and 84 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ venv.bak/
# mkdocs documentation
/site

# django staticfiles
/static

# mypy
.mypy_cache/

Expand Down
73 changes: 48 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
exclude: ^.devcontainer/
- id: fix-encoding-pragma
args: ['--remove']
- id: forbid-new-submodules
- id: mixed-line-ending
args: ['--fix=lf']
description: Forces to replace line ending by the UNIX 'lf' character.
# - id: pretty-format-json
# args: ['--no-sort-keys']
- id: check-added-large-files
args: ['--maxkb=500']
- id: no-commit-to-branch
args: [--branch, main]
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: .txt$
- id: check-yaml
- id: check-json
exclude: ^.devcontainer/
- id: fix-encoding-pragma
args: ["--remove"]
- id: forbid-new-submodules
- id: mixed-line-ending
args: ["--fix=lf"]
description: Forces to replace line ending by the UNIX 'lf' character.
# - id: pretty-format-json
# args: ['--no-sort-keys']
- id: check-added-large-files
args: ["--maxkb=500"]
- id: no-commit-to-branch
args: [--branch, main]

- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- id: seed-isort-config

- repo: https://github.com/PyCQA/isort
rev: 5.8.0
hooks:
- id: isort
- id: isort
exclude: ^t2\.py$


- repo: https://github.com/psf/black
rev: 21.5b1
hooks:
- id: black
language_version: python3.9
- id: black
language_version: python3.9

# Flake8 checks what errors there are and gives code
# - repo: https://gitlab.com/pycqa/flake8
Expand All @@ -49,10 +49,15 @@ repos:
rev: v1.1
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
args:
[
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variable",
]

- repo: https://github.com/pre-commit/mirrors-pylint
rev: 'v3.0.0a3' # Use the sha / tag you want to point at
rev: "v3.0.0a3" # Use the sha / tag you want to point at
hooks:
- id: pylint
exclude: migrations/
Expand All @@ -61,4 +66,22 @@ repos:
rev: v0.812
hooks:
- id: mypy
additional_dependencies: [django-stubs,dj-database-url,django-filter,django-cors-headers,django-autoslug,graphene-django,psycopg2-binary,django-graphql-auth,gunicorn,shortuuid,squareup,django-environ,django-guardian,djangorestframework,django_tiptap]
additional_dependencies:
[
django-stubs,
dj-database-url,
django-filter,
django-cors-headers,
django-autoslug,
graphene-django,
psycopg2-binary,
django-graphql-auth,
gunicorn,
shortuuid,
squareup,
django-environ,
django-guardian,
djangorestframework,
django_tiptap,
django_inlinecss,
]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,5 @@ The API image will then need rebuilding to add this dependency. Run:
```
make build
```

If mypy gives an error about not being able to find the new package, add it to the list of "additional_dependencies" in `.pre-commit-config.yaml`.
13 changes: 12 additions & 1 deletion config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"guardian",
"django_tiptap",
"rest_framework",
"django_inlinecss",
# Your apps
"uobtheatre.users",
"uobtheatre.productions",
Expand All @@ -45,6 +46,7 @@
"uobtheatre.addresses",
"uobtheatre.payments",
"uobtheatre.images",
"uobtheatre.mail",
"uobtheatre",
)

Expand All @@ -70,6 +72,11 @@

# Email
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost")
EMAIL_PORT = os.getenv("EMAIL_PORT") or 1025
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
DEFAULT_FROM_EMAIL = "UOB Theatre <[email protected]>"

ADMINS = (("Author", "[email protected]"),)

Expand Down Expand Up @@ -253,8 +260,12 @@
"REGISTER_MUTATION_FIELDS": ["email", "first_name", "last_name"],
"REGISTER_MUTATION_FIELDS_OPTIONAL": [],
"ALLOW_LOGIN_NOT_VERIFIED": False,
"ACTIVATION_PATH_ON_EMAIL": "user/email-verify",
"ACTIVATION_PATH_ON_EMAIL": "login/activate",
"ACTIVATION_SECONDARY_EMAIL_PATH_ON_EMAIL": "user/email-verify",
"PASSWORD_RESET_PATH_ON_EMAIL": "login/forgot",
"EMAIL_TEMPLATE_ACTIVATION": "emails/activation_email.html",
"EMAIL_TEMPLATE_SECONDARY_EMAIL_ACTIVATION": "emails/activation_email.html",
"EMAIL_TEMPLATE_PASSWORD_RESET": "emails/password_reset_email.html",
}


Expand Down
7 changes: 3 additions & 4 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

DEBUG = True

# Mail
EMAIL_HOST = "localhost"
EMAIL_PORT = 1025
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
EMAIL_BACKEND = os.getenv(
"EMAIL_BACKEND", "django.core.mail.backends.console.EmailBackend"
)

# CORS
CORS_ORIGIN_ALLOW_ALL = True
1 change: 0 additions & 1 deletion config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@
}

EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend"
DEFAULT_FROM_EMAIL = "UOB Theatre <[email protected]>"
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def user(self, new_user):

def login(self, user=None):
self.user = user if user else UserFactory()
self.user.status.verified = True
return self.user

def logout(self):
Expand Down
3 changes: 2 additions & 1 deletion local.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

volumes:
uobtheatre_local_postgres_data: {}
Expand All @@ -17,6 +17,7 @@ services:
- .:/app/uobtheatre-api:z
env_file:
- ./.envs/.local/.django
- .env
- ./.envs/.local/.postgres
ports:
- "8000:8000"
Expand Down
3 changes: 2 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ squareup>=9.0.0.20210226
sentry-sdk==1.4.2
whitenoise==5.3.0 # https://github.com/evansd/whitenoise


#=== Email ===#
django-anymail[amazon_ses]==8.4 # https://github.com/anymail/django-anymail
django-inlinecss==0.3.0
Loading

0 comments on commit e46b479

Please sign in to comment.