Skip to main content

A Django one to one chat application

Reason this release was yanked:

url reversal error

Project description

realchat

MIT License

Features

  • One to one chat
  • message encrypted before entering database
  • Less hassle

realchat is a Django app to conduct web-based chat.

Detailed documentation is in the "docs" directory.

Quick start

  1. Add to your settings.py

    INSTALLED_APPS

       ```
            INSTALLED_APPS = [
                 'realchat',
            ]
       ```
    

    To use the chat app, add it to your INSTALLED_APPS

    Auth_USER_MODEL

       ```
            AUTH_USER_MODEL = 'app.User' # it can be whatever user model you create
       ```
    

    The auth user model will communicate with the chat app and provide the user's name, email and auth status.

    LOGIN_URL

       ```
            LOGIN_URL = '/login/' # it can be whatever login url you create
       ```
    

    The login url provide url redirect from the chat view classes if the user is not logged in.

  2. Include the chat URLconf in your project urls.py like this

       ```
            path('chat/', include('realchat.urls')),
       ```
    
  3. Templating
    The chat app views return the following context variables:

MessageListView

context

 ```
 "inbox": # returns a dictionary of users you have chats with, 
           # and the latest message between you both
           # also including the time and unread message count
 ```

usage (django html)

 ```
      # use a for loop
      {% for key, item in inbox.items %}
           {{ key }} # to get the user you're chatting with 
           {{ item.message }} # to get the latest message between you two
           {{ item.date }} # the date the lastest message was sent
           {{ item.count }} # to get the unread messages count

           # to give access the inbox of the user, make each item template 
           # of the loop clickable and the url should be:
           {% url 'realchat:inbox' key %}
      {% endfor %}

 ```

InboxView

context

 ```
      "messages":     # returns all messages between you and the other user
      "other_person": # returns the user object of the person you're 
                     # chatting with
      "inbox":         # does the same as in the message list view, 
                     # it is passed to make sidepanel work like whatsapp web
      "you": #         # your user object is passed also 
 ```

usage (django html)

 ```
      # use a for loop
      {{ other_person.username }} # will get the username to display
      {% for message in messages%}
           # you can seperate user message and other user messages by
           # comparing the message sender and recipient objects
           # i.e
           {% if message.sender == other_person %}
           {{ message.message }}
           {{ message.date }}
           {% else %}
           # this will return messages that are not sent from the other_person
           {{ message.message }}
           {{ message.date }}
           {% endif %} 

      # finally, when sending messages to a user, create the following 
      # input tags in your from
           # hidden
           <input type="hidden" name="recipient" value="{{ other_person.pk }}">
           <input type="hidden" name="you" value="{{ you.pk }}">
      # get the message
      <input type=text name="message" placeholder="...">

      # the actionof the form should be:
      {% url 'realchat:inbox' other_person.username %}

      {% endfor %}

      # to use the inbox context,
      # extend the messaelist template
 ```

UserListView

context

 ```
      # usser list view has one context
      "users": # returns all users excluding the user logged in
 ```

usage

 ```
      # use a for loop and style your template however
 ```

4.Run python manage.py migrate to create the chat models.

5.Visit http://127.0.0.1:8000/chat/ to participate in the to see a messages.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

realchat-1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

realchat-1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file realchat-1.1.tar.gz.

File metadata

  • Download URL: realchat-1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for realchat-1.1.tar.gz
Algorithm Hash digest
SHA256 3d9465a54f32cb7a23c281ce2acc5132f2348b674e74aa6a4286c8b1b542dbea
MD5 89f900b85bf5dfd13dcb17c4d5d61140
BLAKE2b-256 08ecdcf07097defffe09cc213ba122d310f5ea4dec5ccc99f784e36e8a6a0751

See more details on using hashes here.

File details

Details for the file realchat-1.1-py3-none-any.whl.

File metadata

  • Download URL: realchat-1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for realchat-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19402fd296e82c74255f7c71e0e2bfe112db1250a2fd70a1029285e245c7f0e1
MD5 dc05d324312dc6014d1a527005c76651
BLAKE2b-256 e3473d57f750b649a9825256efd4e6f7f8adf389162a382de8786b7476ecbda8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page