Metadata-Version: 2.4
Name: django-delayed-notifications
Version: 0.12.1
Summary: django-delayed-notifications provides tracking of notifications, and delayed sending.
Project-URL: Homepage, https://gitlab.com/frague59/django-delayed-notifications
Project-URL: Source, https://gitlab.com/frague59/django-delayed-notifications
Author-email: François GUÉRIN <frague59@gmail.com>
Maintainer-email: François GUÉRIN <frague59@gmail.com>
License: MIT
License-File: LICENSE
Keywords: delayed sending,django,notifications
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Natural Language :: French
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: beautifulsoup4~=4.11
Requires-Dist: django-ckeditor-5
Requires-Dist: django-currentuser<1.0,>=0.6.0
Requires-Dist: django-solo<3.0,>=2.0
Requires-Dist: django<6.0,>=3.2
Provides-Extra: docs
Requires-Dist: sphinx-rtd-theme; extra == 'docs'
Requires-Dist: sphinx>=1.5.5; extra == 'docs'
Description-Content-Type: text/markdown

# Notifications

This application sends notifications to the user and emails addresses.
It stores messages into a database, and sends can be delayed through a cron task.

## Installation

```shell
$ pip install django-delayed-notifications
```

Add `django_notifications` to your `INSTALLED_APPS`:

```python
INSTALLED_APPS = (
    ...
    "django_notifications",
    ...
)
```

Apply the migrations:

```shell
$ ./manage.py migrate
```

## Usage

Instead of sending a raw email, with the `send_mail` django function, you can create a Notification object and program
the sending.

### Notification creation

```python
from pathlib import Path
from django_notifications.models import Notification, Attachment
from django.core.files import File
from django.utils.timezone import now
from datetime import timedelta

# **Basic creation**
my_instance = "<A random object in the application>"
notification = Notification.objects.create(
    subject="My beautiful email",
    text_body="My text body",
    html_body="""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="x-apple-disable-message-reformatting">
    <title>My beautiful email</title>
</head>
<body>My HTML body</body>
</html>
    """,
    from_email="foo@example.org",  # Optional
    related_object=my_instance,  # Optional
)

# ** Related objects states management **
# When using FSM, you can provide the states from / to (Optional)
notification.state_from = "active"
notification.state_to = "processing"

# **Attachments management**
# Include file from a raw file
from django.core.files.base import ContentFile

_attachment = Attachment.objects.create(
    notification=notification,
    attachment_file=ContentFile(Path("<my_file>").open("r"), name="my_file.txt")
)

# Including an attachment from a FileField
from django.db.models.fields import FieldFile

assert isinstance(my_instance.file, FieldFile)

_attachment = Attachment.objects.create(
    notification=notification,
    attachment_file=ContentFile(my_instance.file.read(), name=my_instance.file.name)
)

# **Recipients management**
# You can provide users
notification.recipients.set("<User instance>", "<User instance>", ...)

# And / Or provides email address, `\n` separated
notification.email_recipients = "\n".join([
    "foo@example.org", "bar@example.org"
])
notification.save()

# You can set the delayed sending date
notification.delayed_sending_at = now() + timedelta(days=1)
notification.save()

# Or you can send the email immediately
notification.send()
```

### Management command

The application provides a management command to send the emails:

This command can be used in a `cron`, to provide delayed sending.

```sh
$ ./manage.py send_notifications
12 notifications sent.
```

### Templates

The application provides some basic templates for emails, and provides some basic blocks.

#### Provided blocks
```html
{% extends "django_notifications/base_email.html" %
{% block extrahead %}<!-- JS / CSS to add to header -->{% endblock extrahead %}
{% block header %}<!-- Email header (empty) -->{% endblock header %}
{% block page_title %}
  {% block title-content %}{{ subject }}{% endblock title-content %}
{% endblock page_title %}
{% block main-content %}<!-- Main content on the email -->{% endblock main-content %}
{% block buttons %}
    <div class="buttons">
      {% block buttons-content %}<!-- Link buttons -->{% endblock buttons-content %}
    </div>
{% endblock buttons %}
{% block signature %}
    <div class="signature">
      {% block signature-content %}<!-- Email signature content -->{% endblock signature-content %}
    </div>
{% endblock signature %}
```

### Config

This application provides an admin interface for notifications.

+ delay_notifications: Delay notification sending, using the cron job
+ delay: Delay to apply to notifications
+ receive_notifications_field: Name of the field to allow notification send
+ receive_messages_field: Name of the field to allow notification send -- **NOT USED**
+ enable_debug_notifications: Enable (re)sending emails
+ debug_notifications_email: Target recipient of the email debugging

## Notes

The application is available in English and translated to French.
