Skip to content
A simple Chat App for Django based on channels and websockets
Python JavaScript HTML CSS Shell
Branch: master
Clone or download
dibs-devs Merge pull request #37 from dibs-devs/ahmed
V 1.0.6 and 1.0.7 release
Latest commit 41c077e Jun 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
chatter Minor features, UI improvements May 24, 2019
django_chatter Bugfix: fixing queryset slicing Jun 2, 2019
docs Added 1.0.7 version changes Jun 2, 2019
functional_tests Multiple changes: May 27, 2019
tenants Added tests for consumers May 22, 2019
.gitignore Added registration template back for version control and removed it f… May 22, 2019
.travis.yml fix travis: chromedriver74 should work May 22, 2019
LICENSE Added MIT License Feb 20, 2019
MANIFEST.in Added docs in distributable package May 23, 2019
README.rst Minor updates to ReadMe May 27, 2019
clear-database.sh Fixed the text input interrupt bug. Changed Room model to have UUID v… May 4, 2019
clear-postgres.sh Added model tests, migrating to django-tenants to enable testing of m… May 20, 2019
dev-requirements.txt
manage.py started django project Jul 18, 2018
package_upload.sh Bugfix: fixing queryset slicing Jun 2, 2019
pytest.ini Added tests for consumers May 22, 2019
setup.py Added 1.0.7 version changes Jun 2, 2019

README.rst

Django Chatter

https://coveralls.io/repos/github/dibs-devs/chatter/badge.svg?branch=master https://travis-ci.org/dibs-devs/chatter.svg?branch=master https://pepy.tech/badge/django-chatter/month

Re-usable Django chat application for Django developers.

Full docs here: Django Chatter Docs

Chat is a crucial aspect of many web apps at present. However, Django's package repository does not have well-maintained reusable chat packages that Django developers can integrate into their platforms.

Django Chatter is an attempt to change that. This is an open-source fully reusable chat application that has mechanisms to support group chats in place.

The HTML front-end for this app is built with Flexbox, making it responsive to numerous viewports.

[More work to be done] Added to that, it can also possibly be used as a REST API, since all the views generate standard JSON responses that need to be parsed by the websockets present in the front-end of the app using this package.

This app makes use of Django Channels 2 and uses Redis as the message broker.

To run Django Chatter properly, you'll require python>=3.5 and Redis. Note: For development, we are currently using redis-5.0.3, built from source on Ubuntu machines.

The core mechanisms of Chatter follow the instructions provided in the Django Channels tutorial section, with some added modifications and theming.

Installation

  • Chatter is on PyPi now! To install it, run

    pip install django-chatter

    This should install all the required dependencies for Chatter.

  • Once you're done with that, add it to your settings.INSTALLED_APPS:

    INSTALLED_APPS = [
      ...
      'django_chatter',
      ...
      ]
  • Since we use Redis as our message broker, you need to enable channel layers for Chatter's ChatConsumer (see Channels' Consumers for more details). To enable that, you need to add the following lines to your project's settings.py file:

    CHANNEL_LAYERS = {
      'default': {
          'BACKEND': 'channels_redis.core.RedisChannelLayer',
          'CONFIG': {
              "hosts": [('127.0.0.1', 6379)],
          },
      },
    }
  • If you haven't already, create a file named routing.py in your project's configuration folder. This is because Django Channels uses a specification called ASGI for its websocket protocol. To enable Channels on your app, you have to add a file that routes all websocket requests to a Channels app (in this case, Chatter). This should be the same as the folder where your settings.py file is located.

    In routing.py, add the following lines:

    from channels.auth import AuthMiddlewareStack
    from channels.routing import ProtocolTypeRouter, URLRouter
    import django_chatter.routing
    
    application = ProtocolTypeRouter({
      'websocket': AuthMiddlewareStack(
        URLRouter(
        django_chatter.routing.websocket_urlpatterns # send websocket requests to chatter's urls
        )
      )
    })

    This routes all websocket requests to Chatter, with the logged in User object. If you are using different django-channels applications other than Chatter, you may already have this file, and can add the appropriate URL for chatter to handle. More details can be found on Django Channels' Routing page.

    If you know how the middleware wrapping in Channels works, then feel free to replace AuthMiddlewareStack with what you use as your auth middleware for User object processing (if you're curious to know about this, get in touch! We'd be happy to talk to you about it).

  • Now that you're done setting up routing.py, add the following line in your settings.py file to link to the routing.py (again, you may have already done this if you're already using channels)

    ASGI_APPLICATION = '<project name>.routing.application'
  • Chatter uses a context processor to generate a list of all rooms that a user is a member of. To use this context processor, add it to your TEMPLATES list in your settings.py file:

    TEMPLATES = [
      {
        ...
        'OPTIONS': {
          'context_processors': [
            ...,
            'django_chatter.context_processors.get_chatroom_list',
            ...,
          ],
        },
      },
    ]
  • Link django_chatter.urls to the URL you want in your URLConf (<project>/urls.py).

    Example:

    from django.urls import path, include
    
    ...
    urlpatterns = [
      ...,
      path('chat/', include('django_chatter.urls')),
      ...
    ]
  • Run migrations:

    $ python manage.py makeimigrations chat
    $ python manage.py migrate
  • Start your app's development server and go to your '/chat/' URL, and you will see Chatter's homepage.

Tests haven't been setup for this package yet. I built this app before I knew what good test practices were like. So, tests welcome!

Usage Notes

  • Chatter, as of right now, provides a very minimal interface for users to chat with other users.For starters, while group chatting is supported on the model layer, the corresponding templates and front-end logic have not yet been setup.
  • If you're using chatter as a package in your own app, you have to make sure that you handle user authentication in your app. Chatter, by default, provides views that require user authentication. If you're developing Chatter on the other hand, the usage will vary a bit. The notes for that can be found in the Get Involved section.

Running list of features to add

  • Add a "Create Group" option for users on the templates
  • Add 'Seen by user x' functionality
You can’t perform that action at this time.