Coder Social home page Coder Social logo

techscientist / django-herald Goto Github PK

View Code? Open in Web Editor NEW

This project forked from worthwhile/django-herald

0.0 1.0 0.0 51 KB

Django messaging library for separating content from transmission method

License: MIT License

Python 99.17% HTML 0.83%

django-herald's Introduction

django-herald

Latest PyPI version Build Status Coverage Status

Logo

Django library for separating the message content from transmission method

Installation

  1. pip install django-herald

  2. Add herald to INSTALLED_APPS.

  3. Add herald's URLS:

     if settings.DEBUG:
         urlpatterns = [
             url(r'^herald/', include('herald.urls')),
         ] + urlpatterns
    

Usage

  1. Create a notifications.py file in any django app. This is where your notification classes will live. Add a class like this:

     from herald import registry
     from herald.base import EmailNotification
    
    
     class WelcomeEmail(EmailNotification):  # extend from EmailNotification for emails
        template_name = 'welcome_email'  # name of template, without extension
        subject = 'Welcome'  # subject of email
    
        def __init__(self, user):  # optionally customize the initialization
            self.context = {'user': user}  # set context for the template rendering
            self.to_emails = [user.email]  # set list of emails to send to
    
        @staticmethod
        def get_demo_args():  # define a static method to return list of args needed to initialize class for testing
            from users.models import User
            return [User.objects.order_by('?')[0]]
    
     registry.register(WelcomeEmail)  # finally, register your notification class
    
  2. Create templates for rendering the email using this file structure:

     templates/
         herald/
             text/
                 welcome_email.txt
             html/
                 welcome_email.html
    
  3. Test how your email looks by navigating to /herald/.

  4. Send your email wherever you need in your code:

     WelcomeEmail(user).send()
    
  5. View the sent emails in django admin and even be able to resend it.

django-herald's People

Contributors

raiderrobert avatar

Watchers

Subhash Ramesh 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.