Skip to main content

No project description provided

Project description

Garpix Notify

Quickstart

Install with pip:

pip install garpix_notify

Add the garpix_notify and dependencies to your INSTALLED_APPS:

# settings.py

INSTALLED_APPS = [
    # ...
    'fcm_django',
    'garpix_notify',
]

FCM_DJANGO_SETTINGS = {
        "APP_VERBOSE_NAME": "Firebase Cloud Messaging",
        "FCM_SERVER_KEY": "[your api key]",
        "ONE_DEVICE_PER_USER": False,
        "DELETE_INACTIVE_DEVICES": False,
}

NOTIFY_SMS_URL = "http://sms.ru/sms/send"
NOTIFY_SMS_API_ID = "[your api key from sms.ru]"

Package not included migrations, set path to migration directory. Don’t forget create this directory (app/migrations/garpix_notify/) and place empty __init__.py:

app/migrations/
app/migrations/__init__.py  # empty file
app/migrations/garpix_notify/__init__.py  # empty file

Add path to settings:

# settings.py

MIGRATION_MODULES = {
    'garpix_notify': 'app.migrations.garpix_notify',
}

Create your custom user model and add AUTH_USER_MODEL to app/settings.py:

AUTH_USER_MODEL = 'user.User'

Run make migrations:

python manage.py makemigrations

Migrate:

python manage.py migrate

Example

Step 1. Set notify types in app/settings.py, for example:

REGISTRATION_EVENT = 1
FEEDBACK_EVENT = 2
EXAMPLE_EVENT_1 = 3
EXAMPLE_EVENT_2 = 4


NOTIFY_EVENTS = {
    REGISTRATION_EVENT: {
        'title': 'Register',
    },
    FEEDBACK_EVENT: {
        'title': 'Feeback',
    },
    EXAMPLE_EVENT_1: {
        'title': 'Example 1',
    },
    EXAMPLE_EVENT_2: {
        'title': 'Example 2',
    },
}

CHOICES_NOTIFY_EVENT = [(k, v['title']) for k, v in NOTIFY_EVENTS.items()]

Step 2. Go to the admin panel and go to the “Notifications” section - “SMTP accounts”

Add an SMTP account to send Email notifications. These will be the senders of Email notifications.

Step 3. Also go to “Notifications” - “Categories”

Create a category that will be used to send emails. Usually one category is enough. The ability to enter several categories is necessary to divide them into informational and marketing notifications.

Step 4. Go to “Notifications” - “Templates”

Create a template for a specific event (when you added them to settings.py).

Step 5. Call Notify.send()

In the code where it is necessary to work out sending a notification, we perform the following actions:

from django.conf import settings
from garpix_notify.models import Notify

# Syntax
# Notify.send(<event>, <context>[, <user=None>, <email=None>, <phone=None>, <files=None>, <data_json=None>])
# That is, we specify the event ID as the first parameter,
# create variables for the template,
# third - the user to send it to (it is not necessary to specify his email, phone number, etc.,
# because this will be determined automatically depending on the type of template)

# Пример
user = request.user  # this will be the recipient of the notification.

Notify(settings.REGISTRATION_EVENT, {
    'confirmation_code': 'abcdef12345',
}, user=user)

# If we do not have a user in the system, but we need to send an email, we can do the following

Notify(settings.EXAMPLE_EVENT_1, {
    'confirmation_code': 'abcdef12345',
}, email='example@mail.ru')

Do not forget run celery:

celery -A app worker --loglevel=info -B

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

garpix_notify-4.0.2.tar.gz (40.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

garpix_notify-4.0.2-py3-none-any.whl (65.4 kB view details)

Uploaded Python 3

File details

Details for the file garpix_notify-4.0.2.tar.gz.

File metadata

  • Download URL: garpix_notify-4.0.2.tar.gz
  • Upload date:
  • Size: 40.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for garpix_notify-4.0.2.tar.gz
Algorithm Hash digest
SHA256 3c7811131adabc1856abf6ed2b4b8099e940ef1f82f6cb1e3b687b291e096e62
MD5 80efc5f8e9d2dae72bb5fd5d92117051
BLAKE2b-256 f90831a57cceace9e694e9741d680e24ad34c553433b59c35030dee1f9bb942d

See more details on using hashes here.

File details

Details for the file garpix_notify-4.0.2-py3-none-any.whl.

File metadata

  • Download URL: garpix_notify-4.0.2-py3-none-any.whl
  • Upload date:
  • Size: 65.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for garpix_notify-4.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 484ecec3a7d1fe806795438e384459c05d903601483913598b6c38dcdd368dbf
MD5 e8c7c9243b207e23161edad1de75db2f
BLAKE2b-256 2ad3621160fbf5cfe2ea87f66e3dcdbde33ca772aab26681ab95e1dfacd3998a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page