### Install bpnotify using pip Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/install.rst Installs the bpnotify package from a given URL using pip. This is the first step in setting up the application. ```bash pip install -e https://project.beproud.jp/hg/bpnotify/ ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/beproud/bpnotify/blob/master/release_checklist.rst Installs the 'wheel' and 'twine' packages required for building and uploading Python packages. ```shell pip install wheel twine ``` -------------------------------- ### Add bpnotify to INSTALLED_APPS Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/install.rst Configures the Django project's settings.py file to include bpnotify in the INSTALLED_APPS list, enabling its functionality. ```python INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', #... 'beproud.django.notify', #... ) ``` -------------------------------- ### Configure BPNOTIFY_MEDIA settings Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/install.rst Defines the routing for notifications by specifying media types, their verbose names, default notification types, and the backends to use for sending notifications. ```python BPNOTIFY_MEDIA = { "news": { "verbose_name": "News", "default_types": ("new_user", "follow", "private_msg"), "backends": ( "beproud.django.notify.backends.model.ModelBackend", ), }, "private_messages": { "verbose_name": "Private Message", "default_types": ("private_msg",), "backends": ( "beproud.django.notify.backends.model.ModelBackend", "beproud.django.notify.backends.mail.EmailBackend", ), }, } ``` -------------------------------- ### BPNOTIFY_MEDIA Configuration Example Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/settings.rst Demonstrates the structure and possible settings for the BPNOTIFY_MEDIA dictionary, which defines media names, verbose names, default notification types, and notification backends. ```python BPNOTIFY_MEDIA = { "news": { "verbose_name": "News", "default_types": ("new_user", "follow", "private_msg"), "backends": ( "beproud.django.notify.backends.model.ModelBackend", ), }, "private_messages": { "verbose_name": "Private Message", "default_types": ("private_msg",), "backends": ( "beproud.django.notify.backends.model.ModelBackend", "beproud.django.notify.backends.mail.EmailBackend", ), }, } ``` -------------------------------- ### Set BPNOTIFY_SETTINGS_STORAGE Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/install.rst Specifies the storage backend for notification settings. The default is CachedDBStorage, which stores settings in the database cache. ```python BPNOTIFY_SETTINGS_STORAGE="beproud.django.notify.storage.cached_db.CachedDBStorage" ``` -------------------------------- ### BPNOTIFY_SETTINGS_STORAGE Configuration Example Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/settings.rst Shows how to configure the BPNOTIFY_SETTINGS_STORAGE setting, specifying the backend class for storing notification settings. The default is CachedDBStorage. ```python BPNOTIFY_SETTINGS_STORAGE="beproud.django.notify.storage.cached_db.CachedDBStorage" ``` -------------------------------- ### bpnotify Project Setup and Requirements Source: https://github.com/beproud/bpnotify/blob/master/README.rst This section details the project requirements for bpnotify, including compatible versions of Python, Celery, and Django, as well as the 'six' library. It's essential for setting up the development environment. ```rst Requirements ============ * Python (3.9, 3.10, 3.11, 3.12) * Celery (5.3) * Django (4.2) * six ``` -------------------------------- ### Get Notification Setting Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/sending_notifications.rst Retrieves the current notification setting for a given target, notification type, and media. Returns a boolean indicating whether notifications will be sent. ```python get_notify_setting() ``` -------------------------------- ### Upload to Production PyPI Source: https://github.com/beproud/bpnotify/blob/master/release_checklist.rst Uploads the final distribution packages to the production PyPI repository. ```shell twine upload dist/* ``` -------------------------------- ### Upload to TestPyPI Source: https://github.com/beproud/bpnotify/blob/master/release_checklist.rst Uploads the built distribution packages to the TestPyPI repository for testing. ```shell twine upload --repository testpypi dist/* ``` -------------------------------- ### Build Python Packages Source: https://github.com/beproud/bpnotify/blob/master/release_checklist.rst Builds the source distribution (sdist) and wheel distribution (bdist_wheel) of the Python package. ```shell python setup.py sdist bdist_wheel ``` -------------------------------- ### bpnotify API Documentation Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/sending_notifications.rst Provides reference for the core functions within the bpnotify API, including `notify`, `notify_now`, `get_notifications`, and `get_notify_setting`. ```APIDOC notify(targets, notify_type, extra_data={}, include_media=None, exclude_media=[]) Sends a notification of the given type to a iterable of targets. If targets is not iterable, it is treated as a single target. Sends asynchronously via Celery if djcelery is installed, otherwise synchronously via notify_now(). notify_now(targets, notify_type, extra_data={}, include_media=None, exclude_media=[]) Sends a notification directly and synchronously, bypassing asynchronous queues. get_notifications(target, media, start=None, end=None) Retrieves notifications for a specific target and media type from backends that support retrieval. Returns notifications in reverse chronological order (newest first). Example return format: [ { 'target': User: monty, 'notify_type': "private_message", 'media': "private_messages", 'extra_data': { 'spam': 'eggs', } 'ctime': datetime.datetime(2011, 5, 8, 14, 06, 52, 882674) }, ... ] get_notify_setting(target, notify_type, media_name, default=None) Retrieves the notification setting for a specific target, notify type, and media type. Returns the default value if no setting is found, or None if no default is specified. ``` -------------------------------- ### bpnotify Core Functionality Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/index.rst Demonstrates the core `notify` function used for sending notifications in bpnotify. This function checks user settings before dispatching notifications. ```python from beproud.django.notify.api import notify # Example usage: # notify(user, "You have a new message", "message") ``` -------------------------------- ### Email Backend Templates Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/backends/mail_backend.rst Defines the template paths used for rendering email content (subject, HTML body, text body) for the EmailBackend. These templates are located within the 'notify///' directory. ```APIDOC Email Templates: Subject Template Path: notify///mail_subject.txt HTML Body Template Path: notify///mail_body.html Text Body Template Path: notify///mail_body.txt Notes: - Subject template is required. - Either HTML body or Text body template is required. - If only text template is found, email is sent as plain text. - If only HTML template is found, email is sent as multipart with text body generated by stripping HTML tags. - If both HTML and text templates are found, email is sent as multipart. - Email is not sent if no subject template or neither body template is found. ``` -------------------------------- ### CachedDBStorage Class Documentation Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/storage/cached_db_storage.rst Provides details on the CachedDBStorage class, its inheritance from DBStorage, and its caching mechanism using Django's cache framework. It highlights its role as the default settings storage. ```APIDOC class beproud.django.notify.storage.cached_db.CachedDBStorage: """The cached db storage storage is identical in functionality to the :class:`DBStorage ` backend, storing setting data in the database using the :class:`NotifySetting ` model. However, the cached db storage caches settings data using Django's cache framework. The cached db storage is the default settings storage backend and is recommended over the :class:`DBStorage ` backend unless the site does not use the Django's cache framework.""" ``` -------------------------------- ### NotifySetting Model Reference Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/storage/db_storage.rst Provides a detailed reference for the NotifySetting model used by DBStorage. It outlines the purpose and type of each attribute, including foreign keys and generic foreign key relationships. ```APIDOC NotifySetting: target: A GenericForeignKey for the target model object. The target is retrieved using a automatically using the ``target_content_type`` and ``target_object_id`` fields. target_content_type: A ForeignKey to the content type of the target object. target_object_id: The target object's id. notify_type: The notify type of the notification. media: The media type of the notification. send: A boolean attribute specifying whether notifications of the notify_type and media are sent to the target. ``` -------------------------------- ### Check Package Integrity Source: https://github.com/beproud/bpnotify/blob/master/release_checklist.rst Verifies the integrity and metadata of the built distribution packages using twine. ```shell twine check --strict dist/* ``` -------------------------------- ### Email Backend Template Context Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/backends/mail_backend.rst Lists the context variables available when rendering email templates for the EmailBackend. This includes notification-specific data and any additional context provided. ```APIDOC Template Context Variables: - target: The target object of the notification. - notify_type: The type of the notification. - media: The media type of the notification. - extra_context: Any additional data passed during notification. ``` -------------------------------- ### Sending a Simple Notification Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/sending_notifications.rst Demonstrates how to send a basic notification to the current Django user within a view. It utilizes the `notify` function and handles user authentication. ```python from django.http import HttpResponse from django.contrib.auth.decorators import login_required from beproud.django.notify import notify @login_required def hello_world(request): notify(request.user, "hello_world") return HttpResponse("Hello World!") ``` -------------------------------- ### bpnotify Django Notification Routing Source: https://github.com/beproud/bpnotify/blob/master/README.rst This snippet describes the core functionality of bpnotify, a notification routing system for Django. It outlines how notifications are defined with targets, types, media, and extra data, and then routed to different backends such as email. ```python Application notify function with targets, notify_type, media, extra_data, then bpnotify send notify with backend (example: mail). ``` -------------------------------- ### Notification Model Reference Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/backends/model_backend.rst Provides a reference to the Notification model used by the Model Backend. It details the attributes for storing notification data, including target information, notification type, media, extra data, and creation time. ```APIDOC class beproud.django.notify.models.Notification target: A GenericForeignKey for the target model object. The target is retrieved using a automatically using the ``target_content_type`` and ``target_object_id`` fields. target_content_type: A ForeignKey to the content type of the target object. target_object_id: The target object's id. notify_type: The notify type of the notification. media: The media type of the notification. extra_data: A JSONField of extra data sent along with the notification. The extra_data is a dictionary stored in the database as JSON. ctime: A datetime specifying the time that the notification was sent. ``` -------------------------------- ### Email Recipient Retrieval Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/backends/mail_backend.rst Explains how the email recipient is determined for the EmailBackend. It prioritizes properties on the target object and then checks the extra_data dictionary. ```APIDOC Recipient Retrieval: 1. Search target object for 'email' or 'mail' property. 2. If not found, search extra_data dictionary for 'email' or 'mail' key. Note: - If no recipient email is retrieved, the email is not sent. ``` -------------------------------- ### Excluding Media Types for Notifications Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/sending_notifications.rst Shows how to control notification delivery by specifying which media types to include or exclude. This allows for targeted notification sending. ```python # Send only to the "mail" media type. notify(request.user, "welcome", include_media=["mail"]) # Send to all media types except the "profile" and "notices" media types. notify(request.user, "welcome", exclude_media=["profile", "notices"]) ``` -------------------------------- ### Set Notification Setting Source: https://github.com/beproud/bpnotify/blob/master/docs/en/source/sending_notifications.rst Updates the notification setting for a given target, notification type, and media. The 'send' parameter determines if notifications are enabled (True) or disabled (False). ```APIDOC .. function:: set_notify_setting(target, notify_type, media_name, send) Updates notification settings. Parameters: - target: The target for the notification. - notify_type: The type of notification. - media_name: The name of the media to route notifications to. - send (bool): True to enable notifications, False to disable. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.