Django one-to-one Websocket-based Asyncio-handled chat, developed by Bearle team
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Fixed some documents & stuff Feb 9, 2017
django_private_chat bumpversion Dec 12, 2018
docs Update django version in docs Jan 10, 2019
example Update django version in example Jan 10, 2019
screenshots Removed dots from screen, split quickstart into example project and e… Feb 12, 2017
tests fixed test Jun 16, 2017
.coveragerc Initial commit from cookiecutter-djangopackage Feb 9, 2017
.editorconfig Initial commit from cookiecutter-djangopackage Feb 9, 2017
.gitignore python3.7 compatibility (#26) Dec 7, 2018
.travis.yml removed py27 from testing Jun 16, 2017
AUTHORS.rst Added models with ugettext translate Feb 9, 2017
CONTRIBUTING.rst Fixed some documents & stuff Feb 9, 2017
HISTORY.rst bumpversion Dec 12, 2018
LICENSE Fixed some documents & stuff Feb 9, 2017
MANIFEST.in Initial commit from cookiecutter-djangopackage Feb 9, 2017
Makefile Initial commit from cookiecutter-djangopackage Feb 9, 2017
README.rst Merge remote-tracking branch 'origin/dev' into dev Oct 21, 2018
example.service Create example.service May 10, 2017
manage.py Initial commit from cookiecutter-djangopackage Feb 9, 2017
requirements.txt Update Requirements.txt Mar 20, 2018
requirements_dev.txt Docs Oct 6, 2018
requirements_test.txt Added requirements Feb 10, 2017
runtests.py Initial commit from cookiecutter-djangopackage Feb 9, 2017
setup.cfg bumpversion Dec 12, 2018
setup.py Remove uvloop from requirements Feb 11, 2017
tox.ini removed py27 from testing Jun 16, 2017

README.rst

😎 django-private-chat 😎

https://travis-ci.org/Bearle/django-private-chat.svg?branch=master

Please also check out our another package https://github.com/Bearle/django_mail_admin

Django one-to-one Websocket-based Asyncio-handled chat, developed by Bearle team

https://github.com/Bearle/django-private-chat/blob/dev/screenshots/screen_1.jpg?raw=true

Important Notes

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 && CHAT_WS_SERVER_PROTOCOL settings!

Documentation

The full documentation is (finally) at https://django-private-chat.readthedocs.io . You can also check the docstrings & this readme.

Example project

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.

Customize the templates

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.

Exsiting project quickstart

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
CHAT_WS_SERVER_PROTOCOL = 'ws'

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

To create a WSS (TLS) server instead:

python manage.py run_chat_server "path/to/cert.pem"

(also works with uvloop). The "cert.pem" file should be a plaintext PEM file containing first a private key, then a certificate (may be a concatenation of a .key and a .crt file). Please note that wss will use TLSv1 by default for python 3.5 & 3.4 and will use ssl.PROTOCOL_TLS_SERVER for 3.6 and above. Features --------

- Uses current app model (get_user_model() and settings.AUTH_USER_MODEL)

- Translatable (uses ugettext and {% trans %} )

- One-to-one user chat

- Works using WebSockets

- Works (optionally) using WSS (TLS) connections (disclaimer - security not guaranteed)

- Displays online/offline status

- Display typing/not typing status

- Soft deletable message model - be sure to keep messages to comply with message-keeping laws

- Flash the dialog button when the user you are not currently talking to wrote you a message

-👉 TODO: add a dialog to the list when new one started

-👉 TODO: add user-not-found and other alerts

-👉 possible Redis backend intergration

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package: