Skip to main content
PyPI https://codecov.io/gh/marcosgabarda/django-snitch/branch/main/graph/badge.svg?token=YKC608Q1HX https://img.shields.io/badge/code_style-black-000000.svg Documentation Status

Django app made to integrate generic events that create notifications that can be sent to users using several backends.

By default, it integrates push notifications and email to send the notifications.

Made with Python 3 and Django with :heart:.

Quick start

1 Install using pip:

pip install django-snitch

2 Add “snitch” to your INSTALLED_APPS settings like this:

INSTALLED_APPS += ('snitch',)

3 Create an events.py file in your app to register the events:

import snitch
from snitch.backends import PushNotificationBackend, EmailNotificationBackend

ACTIVATED_EVENT = "activated"
CONFIRMED_EVENT = "confirmed"


@snitch.register(ACTIVATED_EVENT)
class ActivatedHandler(snitch.EventHandler):
    title = "Activated!"


@snitch.register(CONFIRMED_EVENT)
class ConfirmedHandler(snitch.EventHandler):
    title = "Confirmed!"
    notification_backends = [PushNotificationBackend, EmailNotificationBackend]

    # Custom configuration for email backend
    template_email_kwargs = {"template_name": "email.html"}
    template_email_async = False

    def audience(self):
        return get_user_model().objects.all()

4 Use dispatch decorator to dispatch the event when a function is called:

from django.db import models
from django.utils import timezone

import snitch
from snitch.models import AbstractNotification
from tests.app.events import ACTIVATED_EVENT, CONFIRMED_EVENT


class Stuff(models.Model):
    """Simple stuff model with status."""

    IDLE, ACTIVE, CONFIRMED = 0, 1, 2
    status = models.PositiveIntegerField(default=IDLE)
    activated_at = models.DateTimeField(null=True, blank=True)
    confirmed_at = models.DateTimeField(null=True, blank=True)

    @snitch.dispatch(ACTIVATED_EVENT)
    def activate(self):
        self.activated_at = timezone.now()

    @snitch.dispatch(CONFIRMED_EVENT)
    def confirm(self):
        self.confirmed_at = timezone.now()

Custom Notification model

You can, in the same way that django.contrib.auth.model.User works, swap the Notification model, to customize it.

In order to do that, you should create a model that inherits from AbstractNotification:

from django.db import models

from snitch.models import AbstractNotification


class Notification(AbstractNotification):
    """Custom notification."""

    extra_field = models.BooleanField(default=False)

And after that, specify it in the settings:

SNITCH_NOTIFICATION_MODEL = "app.Notification"

Metadata

Release files for django-snitch 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-snitch 3.2.0
File Size Uploaded Provenance
django_snitch-3.2.0.tar.gz 23.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-snitch 3.2.0
File Interpreter ABI Platform
django_snitch-3.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.1 kB

Release files / django_snitch-3.2.0.tar.gz

Download URL django_snitch-3.2.0.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
deed8eb31f3ac34b9bea5a666638f9bc881be9bb2fa6cd990c02c4f6ac4ec3c6
BLAKE2b-256 checksum
How to use checksums
d36d13aca0acef30d7eec703f99246fdf689d2c5407138129d884281a286d909
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-1041-azure

Release files / django_snitch-3.2.0-py3-none-any.whl

Download URL django_snitch-3.2.0-py3-none-any.whl
Size 33.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfe2c8018fe59855e9f7bbda412564e9b671200a96635f0625bf75c9c269932a
BLAKE2b-256 checksum
How to use checksums
ba1911dbd00a6e921369776edba1297d407ee45f1cd1b561642b4782744d2416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-1041-azure

Security for django-snitch 3.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page