GithubHelp home page GithubHelp logo

django-events's Introduction

Events for django

Django events provides a simple mechanism for defining and responding to events in django.

The mechanism is similar to signals and in some cases should replace them.

Features

  • Declarative definition of the events and their listeners in the settings. The developer defines all events and their listeners in the settings file and the app is responsible to expose them in the other apps.

  • Base classes for actions that deal with the most common cases. Specifically:

    • Responding to events with a plain function.
    • Responding to events in a celery task.
    • Responding to events, only if a condition is met.
    • Responding to events, only when the event signals a status change.
  • Easier testing; the developer can remove all listeners for the events, when running the tests.

Status-change listeners

There are cases where certain things in an application have status, e.g. tests passing or not. In such cases you might want to notify the users, only when the status changes, i.e. going from "tests passing" to "tests failing" and the other way round.

The EdgeTriggeredAction class provides this feature.

Usage

First, add the app in the INSTALLED_APPS and define the events and their listeners in the settings file:

INSTALLED_APPS += ['events']

EVENTS = {
    'tests_pass': [
        'myapp.actions.Action1',
        'myapp.actions.Action2',
    ]
}

Then, in the place you want to emit the event, do:

from events.models import tests_pass

tests_pass.emit(args)

In the myapp.actions module define the two actions:

from events.actions import Action

class Action1(Action):
    pass


class Action2(Action):
    pass

django-events's People

Contributors

kbairak avatar kouk 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.