wagtail-birdsong/README.md

93 lines
2.1 KiB
Markdown
Raw Normal View History

2020-04-16 07:47:18 +00:00
# Basic usage
2020-03-04 23:11:39 +00:00
Add the following to your installed apps:
```
'mjml',
'wagtailbirdsong',
2020-04-16 07:47:18 +00:00
'wagtail.contrib.modeladmin',
2020-03-04 23:11:39 +00:00
```
Make a new app eg `email` and create a file called `models.py` with the following:
```
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtailbirdsong.blocks import DefaultBlocks
from wagtailbirdsong.models import BaseEmail
class SaleEmail(BaseEmail):
body = StreamField(DefaultBlocks())
2020-04-16 07:47:18 +00:00
panels = BaseEmail.panels + [
2020-03-04 23:11:39 +00:00
StreamFieldPanel('body'),
]
```
In your `wagtail_hooks.py` add something like:
```
from wagtail.contrib.modeladmin.options import modeladmin_register
2020-04-16 07:47:18 +00:00
from wagtailbirdsong.options import EmailAdmin
2020-03-04 23:11:39 +00:00
from .models import SaleEmail
@modeladmin_register
2020-04-16 07:47:18 +00:00
class SaleEmailAdmin(EmailAdmin):
2020-03-04 23:11:39 +00:00
model = SaleEmail
menu_label = 'SaleEmail'
menu_icon = 'pilcrow'
menu_order = 200
```
Create your email template in `{app_folder}/templates/{app_name}/mail/{model_name}.html` eg `email/templates/email/mail/sale_email.html`:
```
{% extends "wagtailbirdsong/mail/base_email.html" %}
{% block email_body %}
<mj-section>
<mj-column>
<mj-text>Hello world! {{ self.subject }}</mj-text>
{% for b in self.body %}
2020-04-16 07:47:18 +00:00
{{ b }}
2020-03-04 23:11:39 +00:00
{% endfor %}
</mj-column>
</mj-section>
{% endblock email_body %}
```
2020-04-16 07:47:18 +00:00
# Custom backend
Do mostly as you would in the above example, but override the `get_backend` method of the `BaseEmail` class. Your custom backend should follow what you see in `wagtailbirdsong.backends.BaseEmailBackend`.
For example:
```
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtailbirdsong.blocks import DefaultBlocks
from wagtailbirdsong.models import BaseEmail
from .backends import CustomBackend
class SaleEmail(BaseEmail):
body = StreamField(DefaultBlocks())
panels = BaseEmail.panels + [
StreamFieldPanel('body'),
]
def get_backend(self):
return CustomBackend
```