Django one-to-one Websocket-based Asyncio-handled chat, developed by Bearle team
This app uses separate management command, run_chat_server for running Websockets in Django context. It is intended to be used with something like Supervisor or Systemd to run asyncio webserver as a separate one from Django. We didn't want our app to be limited to be used together with Django Channels - that's why we did it that way.
You can find an example Systemd config to run it as a service at https://github.com/Bearle/django-private-chat/blob/dev/example.service
P.S. Don't forget to change CHAT_WS_SERVER_HOST && CHAT_WS_SERVER_PORT settings!
The full documentation will be (soon) at https://django-private-chat.readthedocs.io , for now just check the docstrings =)
You can check out our example project by cloning the repo and heading into example/ directory. There is a README file for you to check, initial data to check out the chat included.
How to customize the template? Just copy:
venv/lib/pythonX.X/site-packages/django_private_chat/templates/django_private_chat/dialogs.html to yourapp/templates/django_private_chat/dialogs.html
And feel free to edit it as you like! We intentionally left the JS code inside for it to be editable easily.
Install django-private-chat:
pip install django-private-chat
Migrate:
python manage.py migrate django-private-chat
Note: you can use this package with or without uvloop, just run either
python manage.py run_chat_server
or run
python manage.py run_chat_server_uvloop
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'django_private_chat',
...
)
Add the server & port for your asyncio server to settings:
CHAT_WS_SERVER_HOST = 'localhost'
CHAT_WS_SERVER_PORT = 5002
It is possible to change messages datetime format using
DATETIME_FORMAT
Add django-private-chat's URL patterns:
from django_private_chat import urls as django_private_chat_urls
urlpatterns = [
...
url(r'^', include('django_private_chat.urls')),
...
]
Add
{% block extra_js %}{% endblock extra_js %}
to your base template
Now you can start a dialog using
/dialogs/some_existing_username
-:white_check_mark: Uses current app model (get_user_model() and settings.AUTH_USER_MODEL)
-:white_check_mark: Translatable (uses ugettext and {% trans %} )
-:white_check_mark: One-to-one user chat
-:white_check_mark: Works using WebSockets
-:white_check_mark: Displays online/offline status
-:white_check_mark: Display typing/not typing status
-:white_check_mark: Soft deletable message model - be sure to keep messages to comply with message-keeping laws
-:white_check_mark: Flash the dialog button when the user you are not currently talking to wrote you a message
-:point_right: TODO: add a dialog to the list when new one started
-:point_right: TODO: add user-not-found and other alerts
-:point_right: possible Redis backend intergration
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Tools used in rendering this package: