Skip to content

Commit c041991

Browse files
authored
Merge pull request larymak#255 from RitiKSIBJr/new-django
django projects
2 parents f542650 + 0ec4bc7 commit c041991

38 files changed

+769
-0
lines changed

DJANGO PROJECTS/Chat/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Django Chat Application
2+
3+
## Overview
4+
5+
This is a simple django chat applications for real time chatting. One needs to create an account to be able to chat with others. User can create their own room for chatting.
6+
7+
## Libraries and Frameworks:
8+
9+
These are the libraries and frameworks used to build this chat application.
10+
1.Django == 3.0.2
11+
2.django-environ == 4.1.4
12+
3.channels == 3.0.4
13+
14+
[![Screenshot-70.png](https://i.postimg.cc/jqWhGBq1/Screenshot-70.png)](https://postimg.cc/fkNXd297)
15+
16+
17+
## Getting started with project
18+
First clone the repository from Github and cd into the Djagno Projects/Chat
19+
20+
Activate the virtualenv for the project
21+
22+
Install project dependencies
23+
```bash
24+
$ pip install -r requirements.txt
25+
```
26+
27+
Then aplly the migrations
28+
```bash
29+
$ python manage.py runserver
30+
```
31+
32+
Now you can run the server
33+
```bash
34+
$ python manage.py runserver
35+
```

DJANGO PROJECTS/Chat/chat/__init__.py

Whitespace-only changes.

DJANGO PROJECTS/Chat/chat/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

DJANGO PROJECTS/Chat/chat/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ChatConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'chat'

DJANGO PROJECTS/Chat/chat/forms.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django import forms
2+
from django.contrib.auth.forms import UserCreationForm
3+
from django.contrib.auth.models import User
4+
5+
class NewUserForm(UserCreationForm):
6+
email = forms.EmailField(required=True)
7+
8+
class Meta:
9+
model = User
10+
fields = ('username', 'email', 'password1', 'password2')
11+
12+
def save(self, commit=True):
13+
user = super(NewUserForm,self).save(commit=False)
14+
user.email = self.cleaned_data['email']
15+
if commit:
16+
user.save()
17+
return user
18+
19+
def __init__(self, *args, **kwargs):
20+
super(UserCreationForm, self).__init__(*args, **kwargs)
21+
self.fields['username'].help_text = None
22+
self.fields['password2'].help_text = None
23+
self.fields['password1'].help_text = None

DJANGO PROJECTS/Chat/chat/migrations/__init__.py

Whitespace-only changes.

DJANGO PROJECTS/Chat/chat/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% extends 'base.html' %}
2+
{% block title %}Home{% endblock %}
3+
4+
{% block content %}
5+
6+
<div class="container">
7+
{% if user.is_authenticated %}
8+
<div class="container fixed-card card">
9+
<h1>User is authenticated</h1>
10+
<p>This is a <strong>chat system app</strong> build in <strong>Python-Django</strong>.<br>
11+
12+
<ul style="text-align: left;">
13+
Featues:
14+
<li>Sign up to chat.</li>
15+
<li>Log in and log out from the app.</li>
16+
<li>Send messages and read messages.</li>
17+
<li>Create new rooms.</li>
18+
</ul></p>
19+
</div>
20+
{% else %}
21+
<div class="container fixed-card card">
22+
<h1>User is not authenticated</h1>
23+
<p>Make sure or <strong>logged in</strong> else you can <strong>sign up</strong>.</p>
24+
<a href="{% url 'login' %}" style="text-decoration: underline;">Follow this link to login or check the top right corner.</a>
25+
<a href="{% url 'register' %}" style="text-decoration: underline;">Follow this link to sign up or check the top right corner.</a>
26+
</div>
27+
{% endif %}
28+
</div>
29+
30+
{% endblock %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends 'base.html' %}
2+
{% block title %}LogIn{% endblock %}
3+
4+
{% block content %}
5+
6+
<div class="container card">
7+
<h1 class="head">Log In</h1>
8+
9+
<form method="post">
10+
{% csrf_token %}
11+
{{ form.as_p }}
12+
<input type="submit" value="LogIn" class="btn btn-dark in">
13+
</form>
14+
</div>
15+
16+
{% endblock %}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends 'base.html' %}
2+
3+
{% block title %}Sign In{% endblock %}
4+
5+
{% block content %}
6+
<div class="container card register-card">
7+
<h1>Register</h1>
8+
<form method="post">
9+
{% csrf_token %}
10+
{{ form.as_p }}
11+
<input type="submit" value="Sign In" class="btn btn-dark in">
12+
</form>
13+
</div>
14+
{% endblock %}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends 'base.html' %}
2+
3+
{% block title %}User Detail{% endblock %}
4+
5+
{% block content %}
6+
<div class="container user-card card">
7+
<h1>User Detail</h1>
8+
<h5>Username : {{ user.username }}</h5>
9+
<h5>Email : {{ user.email }}</h5>
10+
<a href="{% url 'logout' %}"><input type="submit" value="Log Out" class="btn btn-dark in new-btn"></a>
11+
</div>
12+
13+
{% endblock %}

DJANGO PROJECTS/Chat/chat/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

DJANGO PROJECTS/Chat/chat/urls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.urls import path
2+
from . import views
3+
from django.contrib.auth.views import LoginView, LogoutView
4+
5+
urlpatterns = [
6+
path('',views.index, name="index"),
7+
path('accounts/login/',LoginView.as_view(), name="login"),
8+
path('accounts/logout/',LogoutView.as_view(), name='logout'),
9+
path('accounts/register/',views.register, name='register'),
10+
path('user/',views.user, name="user")
11+
]

DJANGO PROJECTS/Chat/chat/views.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from django.shortcuts import render, redirect
2+
from .forms import NewUserForm
3+
from django.contrib.auth import login
4+
from django.contrib import messages
5+
6+
# Create your views here.
7+
def index(request):
8+
return render(request, 'index.html')
9+
10+
def register(request):
11+
if request.method == "POST":
12+
form = NewUserForm(request.POST)
13+
if form.is_valid():
14+
user = form.save()
15+
login(request, user)
16+
messages.success(request, 'Sign In successfull!')
17+
return redirect('index')
18+
messages.error(request, 'Invalid Information, Please try again!')
19+
form = NewUserForm
20+
return render(request, 'signin.html', context={'form':form})
21+
22+
def user(request):
23+
user = request.user
24+
context = {
25+
'user' : user
26+
}
27+
28+
return render(request, 'user.html', context)

DJANGO PROJECTS/Chat/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

DJANGO PROJECTS/Chat/project/__init__.py

Whitespace-only changes.

DJANGO PROJECTS/Chat/project/asgi.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
ASGI config for project project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
from channels.routing import ProtocolTypeRouter, URLRouter
14+
from channels.security.websocket import AllowedHostsOriginValidator
15+
from channels.auth import AuthMiddlewareStack
16+
17+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
18+
19+
import room.routing
20+
21+
application = ProtocolTypeRouter(
22+
{
23+
"http":get_asgi_application(),
24+
"websocket": AllowedHostsOriginValidator(
25+
AuthMiddlewareStack(URLRouter(room.routing.websocket_urlpatterns))
26+
)
27+
}
28+
)
29+
30+

0 commit comments

Comments
 (0)