Skip to content

Commit

Permalink
Merge pull request #73 from capaci/email-template-variables
Browse files Browse the repository at this point in the history
Add custom variables to email template settings
  • Loading branch information
PedroBern committed Oct 12, 2020
2 parents 429041a + f959828 commit 411ca24
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/overriding-email-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Both subject and email templates receive the following variables:
- path --> defined in [settings](settings.md) <small>(some frontend path)</small>
- request
- timestamp
- custom variables defined using EMAIL_TEMPLATE_VARIABLES setting --> defined in [settings](settings.md)


## Writing the templates
Expand Down
25 changes: 25 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,28 @@ default: `#!python "email/activation_email.html"`
### EMAIL_TEMPLATE_PASSWORD_RESET

default: `#!python "email/password_reset_email.html"`

### EMAIL_TEMPLATE_VARIABLES

default: `#!python {}`

Dictionary of key value pairs of template variables that will be injected into the templates.

Example:

```python
GRAPHQL_AUTH = {
"EMAIL_TEMPLATE_VARIABLES": {
"frontend_domain": "the-frontend.com"
}
}
```

Now, in the templates:
{% raw %}

```html
<p>{{ protocol }}://{{ frontend_domain }}/{{ path }}/{{ token }}</p>
```

{% endraw %}
1 change: 1 addition & 0 deletions graphql_auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def get_email_context(self, info, path, action, **kwargs):
"protocol": "https" if info.context.is_secure() else "http",
"path": path,
"timestamp": time.time(),
**app_settings.EMAIL_TEMPLATE_VARIABLES,
}

def send_activation_email(self, info, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions graphql_auth/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"EMAIL_TEMPLATE_ACTIVATION_RESEND": "email/activation_email.html",
"EMAIL_TEMPLATE_SECONDARY_EMAIL_ACTIVATION": "email/activation_email.html",
"EMAIL_TEMPLATE_PASSWORD_RESET": "email/password_reset_email.html",
"EMAIL_TEMPLATE_VARIABLES": {},
# query stuff
"USER_NODE_EXCLUDE_FIELDS": ["password", "is_superuser"],
"USER_NODE_FILTER_FIELDS": {
Expand Down

0 comments on commit 411ca24

Please sign in to comment.