Coder Social home page Coder Social logo

django-email-editor's Introduction

Django Email Editor

Fast and easy way to edit and manage email templates.

email_editor

Install

Add email_editor to your INSTALLED_APPS in django's settings.py:

INSTALLED_APPS = (
    # ...
    "email_editor",
    # ...
)

And add the frontend path to url.py:

# for example like this
from django.conf.urls import url
from django.contrib import admin

from django.urls import include

urlpatterns = [
    url(r'^admin/preview/', include('email_editor.urls')),
    
    url(r'^admin/', admin.site.urls),
]

Quickstart

Define a preview class:

from django.contrib.auth import get_user_model
from email_editor.preview import register, EmailPreview


@register
class WelcomeEmailPreview(EmailPreview):
    template_name = 'path/to/template/welcome_mail.html'
    
    # change this to true if you choose a post office email template in "template_name"
    is_post_office = False
    # change language to edit multilang templates
    language = 'de' 

    def get_template_context(self, **kwargs):
        return {
            'user': get_user_model().objects.first(),
            'test': {
                'Test': 'test'
            }
        }
# apps.py
from django.apps import AppConfig


class YourAppConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'your_app'

    def ready(self):
        super().ready()
        # noinspection PyUnresolvedReferences
        from . import email_previews

This will make the Template visible to the view.

Adding a subject to email template

Simply add following code to the beginning of the file:

<!-- Subject: Your awesome Subject! -->

<div>
  <h1>Welcome Email</h1>
  <div>Lorem Ispum dolor sit amet</div>
</div>

Settings

These are the default settings for the module.

EMAIL_EDITOR = {
    # show only template previews without editor 
    'PREVIEW_ONLY': False,

    # tinymce default init parameters
    'TINY_MCE_INIT': {
        # e.g. keys: plugins, toolbar ... 
    },

    # change editor ('ckeditor' | 'tinymce')
    'WYSIWYG_EDITOR': 'ckeditor',
    
    # preview show context: set max depth
    'CONTEXT_TREE_MAX_DEPTH': 3
}

Editors

Available Editors:

  • ACE
  • CKEditor
  • TinyMCE

Additional

If you want to extract subjects from the html email template the django-email-editor way, you can use the extract_subject function.

from django.template import loader

# import the function
from email_editor.preview import extract_subject

template = loader.get_template('your_app/your_template_name.html')

"""
Dont forget to put the subject into the html file like that: 
'<!-- Subject: Your Subject --> ...' 
at the beginning of your template file
"""


mail.send(
    subject=extract_subject(template),
    recipients=['test@localhost'],
    # ...
)

django-email-editor's People

Contributors

domlysi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.