django-delayed-notifications


Namedjango-delayed-notifications JSON
Version 0.7.3 PyPI version JSON
download
home_page
Summarydjango-delayed-notifications provides tracking of notifications, and delayed sending.
upload_time2023-08-31 12:55:06
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords django notifications delayed sending
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 objects management **
# It is possible to attach an object to the email (Optional)
notification.related_object = my_instance

# ** 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**
_attachment = Attachment.objects.create(
    notification=notification,
    attachment_file=File(Path("<my_file>").open("r"), name="my_file.txt")
)

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

# 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:

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

### Templates

The application provides some basic templates for emails.

### Admin

This application provides an admin interface for notifications.

## Notes

The application is available in English and translated to French.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "django-delayed-notifications",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "django,notifications,delayed sending",
    "author": "",
    "author_email": "Fran\u00e7ois GU\u00c9RIN <frague59@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d2/9a/503120dc41079193f247fd557a2aadd7b04a3884fa56c2efafee58ee5ee1/django-delayed-notifications-0.7.3.tar.gz",
    "platform": null,
    "description": "# Notifications\n\nThis application sends notifications to the user and emails addresses.\nIt stores messages into a database, and sends can be delayed through a cron task.\n\n## Installation\n\n```shell\n$ pip install django-delayed-notifications\n```\n\nAdd `django_notifications` to your `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = (\n    ...\n    \"django_notifications\",\n    ...\n)\n```\n\nApply the migrations:\n\n```shell\n$ ./manage.py migrate\n```\n\n## Usage\n\nInstead of sending a raw email, with the `send_mail` django function, you can create a Notification object and program\nthe sending.\n\n### Notification creation\n\n```python\nfrom pathlib import Path\nfrom django_notifications.models import Notification, Attachment\nfrom django.core.files import File\nfrom django.utils.timezone import now\nfrom datetime import timedelta\n\n# **Basic creation**\nmy_instance = \"<A random object in the application>\"\nnotification = Notification.objects.create(\n    subject=\"My beautiful email\",\n    text_body=\"My text body\",\n    html_body=\"\"\"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"x-apple-disable-message-reformatting\">\n    <title>My beautiful email</title>\n</head>\n<body>My HTML body</body>\n</html>\n    \"\"\",\n    from_email=\"foo@example.org\",  # Optional\n\n)\n\n# ** Related objects management **\n# It is possible to attach an object to the email (Optional)\nnotification.related_object = my_instance\n\n# ** Related objects states management **\n# When using FSM, you can provide the states from / to (Optional)\nnotification.state_from = \"active\"\nnotification.state_to = \"processing\"\n\n# **Attachments management**\n_attachment = Attachment.objects.create(\n    notification=notification,\n    attachment_file=File(Path(\"<my_file>\").open(\"r\"), name=\"my_file.txt\")\n)\n\n# **Recipients management**\n# You can provide users\nnotification.recipients.set(\"<User instance>\", \"<User instance>\", ...)\nnotification.save()\n\n# And / Or provides email address, `\\n` separated\nnotification.email_recipients = \"\\n\".join([\n    \"foo@example.org\", \"bar@example.org\"\n])\nnotification.save()\n\n# You can set the delayed sending date\nnotification.delayed_sending_at = now() + timedelta(days=1)\nnotification.save()\n\n# Or you can send the email immediately\nnotification.send()\n```\n\n### Management command\n\nThe application provides a management command to send the emails:\n\n```sh\n$ ./manage.py send_notifications\n12 notifications sent.\n```\n\n### Templates\n\nThe application provides some basic templates for emails.\n\n### Admin\n\nThis application provides an admin interface for notifications.\n\n## Notes\n\nThe application is available in English and translated to French.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "django-delayed-notifications provides tracking of notifications, and delayed sending.",
    "version": "0.7.3",
    "project_urls": {
        "Homepage": "https://gitlab.com/frague59/django-delayed-notifications",
        "Source": "https://gitlab.com/frague59/django-delayed-notifications"
    },
    "split_keywords": [
        "django",
        "notifications",
        "delayed sending"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcc121b8d44619e7a5889868429f14cf05d9ec1ba3e0871227a7b611c8a44c89",
                "md5": "7cd04784c336308e00c6bc09facae860",
                "sha256": "d853b2241816c35929cb39d32ef8715c01ca6a1a45f875f3a72fbf8acb9eefb5"
            },
            "downloads": -1,
            "filename": "django_delayed_notifications-0.7.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7cd04784c336308e00c6bc09facae860",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 31695,
            "upload_time": "2023-08-31T12:55:03",
            "upload_time_iso_8601": "2023-08-31T12:55:03.981557Z",
            "url": "https://files.pythonhosted.org/packages/bc/c1/21b8d44619e7a5889868429f14cf05d9ec1ba3e0871227a7b611c8a44c89/django_delayed_notifications-0.7.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d29a503120dc41079193f247fd557a2aadd7b04a3884fa56c2efafee58ee5ee1",
                "md5": "0b0b150c60b33437e681a5721d9fb55b",
                "sha256": "5e87a5cf89a5aeefbd7ad2f5ef5e82b1aef048de0e6b35a7718e9805c2c08d8a"
            },
            "downloads": -1,
            "filename": "django-delayed-notifications-0.7.3.tar.gz",
            "has_sig": false,
            "md5_digest": "0b0b150c60b33437e681a5721d9fb55b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21256,
            "upload_time": "2023-08-31T12:55:06",
            "upload_time_iso_8601": "2023-08-31T12:55:06.040477Z",
            "url": "https://files.pythonhosted.org/packages/d2/9a/503120dc41079193f247fd557a2aadd7b04a3884fa56c2efafee58ee5ee1/django-delayed-notifications-0.7.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-31 12:55:06",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "frague59",
    "gitlab_project": "django-delayed-notifications",
    "lcname": "django-delayed-notifications"
}
        
Elapsed time: 0.10988s