a Django app for allowing users of your site to send messages to each other
Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter project templates. This collection can be found at http://pinaxproject.com.
Where you can find what you need: * Releases: published to PyPI or tagged in app repos in the Pinax GitHub organization * Global documentation: Pinax documentation website * App specific documentation: app repos in the Pinax GitHub organization * Support information: SUPPORT.md file in the Pinax default community health file repo * Contributing information: CONTRIBUTING.md file in the Pinax default community health file repo * Current and historical release docs: Pinax Wiki
pinax-messagesis an app for providing private user-to-user threaded messaging.
Django / Python |
3.6 | 3.7 | 3.8 |
---|---|---|---|
2.2 | * | * | * |
3.0 | * | * | * |
To install pinax-messages:
$ pip install pinax-messages
Add
pinax.messagesto your
INSTALLED_APPSsetting:
INSTALLED_APPS = [ # other apps "pinax.messages", ]
Run Django migrations to create
pinax-messagesdatabase tables:
$ python manage.py migrate
Add
pinax.messages.urlsto your project urlpatterns:
urlpatterns = [ # other urls url(r"^messages/", include("pinax.messages.urls", namespace="pinax_messages")), ]
pinax-messageshandles user-to-user private threaded messaging primarily by the inclusion of template snippets. These snippets fall into three categories: view message inbox (all threads), view message thread, and create (or respond to) a message.
Place this snippet wherever a "Message Inbox" link is needed for viewing user message inbox:
{% trans "Message Inbox" %}
Place this snippet wherever you have need to view a specific message thread:
{% trans "View Message Thread" %}
Add the following line to an object template in order to provide a button for messaging a user associated with
object:
Message this user
Use the following code to create a new message programmatically. Note that
to_users(message recipients) is a list, allowing messages sent to multiple users.
from pinax.messages.models import MessageMessage.new_message(from_user=self.request.user, to_users=[user], subject=subject, content=content)
pinax-messagesprovides two context variables using a template context processor. In order to access these in your templates, add
user_messagesto your
TEMPLATESsettings:
TEMPLATES = [ { # ... "OPTIONS": { # other options "context_processors": [ # other processors "pinax.messages.context_processors.user_messages" ], }, }, ]
The following context variables are available, and work with the current authenticated user:
inbox_threads— all message threads for current user
unread_threads— unread message threads for current user
Determines if a message thread has unread messages for a user.
Argument:
user
For instance if there are unread messages in a thread, change the CSS class accordingly:
{% load pinax_messages_tags %}<div class="thread {% if thread|unread:user %}unread{% endif %}"> ... </div>
Returns the number of unread threads for the user. Use for notifying a user of new messages, for example in accountbar.html_
Argument:
user
For instance if there are unread messages in a thread, change the CSS class accordingly:
{% load pinax_messages_tags %}{% with user|unread_thread_count as user_unread %} </pre><li class="{% if user_unread %}unread{% endif %}"> <a href="%7B%%20url%20'pinax_messages:inbox'%20%%7D"><i class="fa fa-envelope"></i> {% trans "Messages" %} {% if user_unread %}<sup>{{ user_unread }}</sup>{% endif %} </a> </li> {% endwith %}
Reference Guide
URL–View–Template Matrix
| URL Name | View | Template | | ------------------------------------ | --------------------- | --------------------- | |
pinax-messages:inbox|InboxView()|inbox.html| |pinax-messages:message_create|MessageCreateView()|message_create.html| |pinax-messages:message_user_create|MessageCreateView()|message_create.html| |pinax-messages:thread_detail|ThreadView()|thread_detail.html| |pinax-messages:thread_delete|ThreadDeleteView()| N/A |URL Names
These URL names are available when using pinax-messages urls.py:
pinax-messages:inbox— Inbox viewpinax-messages:message_create— Create new messagepinax-messages:message_user_create— Create new message to specific userpinax-messages:thread_detail— View message thread, requires thread PKpinax-messages:thread_delete— Delete message thread, requires thread PKViews
InboxView- Display all message threadsMessageCreateView— Create a new message threadThreadView— View specific message threadThreadDeleteView— Delete specific message threadForms
NewMessageForm— creates a new message thread to a single userNewMessageFormMultiple— creates a new message thread to multiple usersMessageReplyForm- creates a reply to a message threadTemplates
Default templates are provided by the
pinax-templatesapp in the messages section of that project.Reference pinax-templates installation instructions to include these templates in your project.
View live
pinax-templatesexamples and source at Pinax Templates!Customizing Templates
Override the default
pinax-templatestemplates by copying them into your project subdirectorypinax/messages/on the template path and modifying as needed.For example if your project doesn't use Bootstrap, copy the desired templates then remove Bootstrap and Font Awesome class names from your copies. Remove class references like
class="btn btn-success"andclass="icon icon-pencil"as well asbootstrapfrom the{% load i18n bootstrap %}statement. Sincebootstraptemplate tags and filters are no longer loaded, you'll also need to update{{ form|bootstrap }}to{{ form }}since the "bootstrap" filter is no longer available.
inbox.htmlDisplays inbox message threads.
thread_detail.htmlShow message thread and allow response.
message_create.htmlNew message form.
Signals
message_sent—providing_args = ["message", "thread", "reply"]Change Log
3.0.0
unread_thread_counttemplate filter
This app was formerly named
user-messagesbut was renamed after being donated to Pinax from Eldarion.
Contributing information can be found in the Pinax community health file repo.
In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a Code of Conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.
For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.
Copyright (c) 2012-present James Tauber and contributors under the MIT license.