- About Pinax
- Overview
- Documentation
- Change Log
- History
- Contribute
- Code of Conduct
- Connect with Pinax
- License
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.
pinax-messages
is an app for providing private user-to-user threaded messaging.
Django \ Python | 2.7 | 3.4 | 3.5 | 3.6 |
---|---|---|---|---|
1.11 | * | * | * | * |
2.0 | * | * | * |
To install pinax-messages:
$ pip install pinax-messages
Add "pinax.messages"
to your INSTALLED_APPS
setting:
INSTALLED_APPS = [
# other apps
"pinax.messages",
]
Run Django migrations to create pinax-messages
database tables:
$ python manage.py migrate
Add pinax.messages.urls
to your project urlpatterns:
urlpatterns = [
# other urls
url(r"^messages/", include("pinax.messages.urls", namespace="pinax_messages")),
]
pinax-messages
handles 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:
<a href="{% url 'pinax_messages:inbox' %}"><i class="fa fa-envelope"></i> {% trans "Message Inbox" %}</a>
Place this snippet wherever you have need to view a specific message thread:
<a href="{% url 'pinax_messages:thread_detail' thread.pk %}"><i class="fa fa-envelope"></i> {% trans "View Message Thread" %}</a>
Add the following line to an object template in order to provide a button for messaging a user associated with object
:
<a href="{% url "pinax_messages:message_user_create" user_id=object.user.id %}" class="btn btn-default">Message this user</a>
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 Message
Message.new_message(from_user=self.request.user, to_users=[user], subject=subject, content=content)
pinax-messages
provides two context variables using a template context processor. In order to access these in your templates, add user_messages
to your TEMPLATES
settings:
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 userunread_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 _account_bar.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 %}
<li class="{% if user_unread %}unread{% endif %}">
<a href="{% url 'pinax_messages:inbox' %}"><i class="fa fa-envelope"></i> {% trans "Messages" %}
{% if user_unread %}<sup>{{ user_unread }}</sup>{% endif %}
</a>
</li>
{% endwith %}
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 |
These URL names are available when using pinax-messages urls.py:
pinax-messages:inbox
— Inbox view
pinax-messages:message_create
— Create new message
pinax-messages:message_user_create
— Create new message to specific user
pinax-messages:thread_detail
— View message thread, requires thread PK
pinax-messages:thread_delete
— Delete message thread, requires thread PK
InboxView
- Display all message threads
MessageCreateView
— Create a new message thread
ThreadView
— View specific message thread
ThreadDeleteView
— Delete specific message thread
NewMessageForm
— creates a new message thread to a single user
NewMessageFormMultiple
— creates a new message thread to multiple users
MessageReplyForm
- creates a reply to a message thread
Default templates are provided by the pinax-templates
app in the
messages
section of that project.
Reference pinax-templates installation instructions to include these templates in your project.
View live pinax-templates
examples and source at Pinax Templates!
Override the default pinax-templates
templates by copying them into your project
subdirectory pinax/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"
and class="icon icon-pencil"
as well as
bootstrap
from the {% load i18n bootstrap %}
statement.
Since bootstrap
template 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.
Displays inbox message threads.
Show message thread and allow response.
New message form.
message_sent
— providing_args = ["message", "thread", "reply"]
- Update CI config
- Update MANIFEST.in
- Add sorting guidance for 3rd-party app imports
- Improve documentation markup
- Remove pinax-theme-bootstrap from test requirements
- Update test config
- Update documentation
- Standardize documentation layout
- Drop Django v1.8, v1.10 support
- Add
unread_thread_count
template filter
- Add Django 2.0 compatibility testing
- Drop Django 1.9 and Python 3.3 support
- Move documentation into README
- Convert CI and coverage to CircleCi and CodeCov
- Add PyPi-compatible long description
- Fix thread delete view with correct template path and success URL
- add documentation
- convert to Django generic CBVs
- various fixes and cleanup
- initial release
This app was formerly named user-messages
but was renamed after being donated to Pinax from Eldarion.
For an overview on how contributing to Pinax works read this blog post and watch the included video, or read our How to Contribute section. For concrete contribution ideas, please see our Ways to Contribute/What We Need Help With section.
In case of any questions we recommend you join our Pinax Slack team and ping us there instead of creating an issue on GitHub. Creating issues on GitHub is of course also valid but we are usually able to help you faster if you ping us in Slack.
We also highly recommend reading our blog post on Open Source and Self-Care.
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-2019 James Tauber and contributors under the MIT license.