django-chelseru 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_chelseru-1.0.0/LICENSE +21 -0
- django_chelseru-1.0.0/MANIFEST.in +1 -0
- django_chelseru-1.0.0/PKG-INFO +56 -0
- django_chelseru-1.0.0/README.md +19 -0
- django_chelseru-1.0.0/django_chelseru.egg-info/PKG-INFO +56 -0
- django_chelseru-1.0.0/django_chelseru.egg-info/SOURCES.txt +36 -0
- django_chelseru-1.0.0/django_chelseru.egg-info/dependency_links.txt +1 -0
- django_chelseru-1.0.0/django_chelseru.egg-info/requires.txt +6 -0
- django_chelseru-1.0.0/django_chelseru.egg-info/top_level.txt +3 -0
- django_chelseru-1.0.0/drf_chelseru_auth/__init__.py +0 -0
- django_chelseru-1.0.0/drf_chelseru_auth/admin.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_auth/apps.py +6 -0
- django_chelseru-1.0.0/drf_chelseru_auth/migrations/__init__.py +0 -0
- django_chelseru-1.0.0/drf_chelseru_auth/models.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_auth/tests.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_auth/views.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_chat/__init__.py +0 -0
- django_chelseru-1.0.0/drf_chelseru_chat/admin.py +5 -0
- django_chelseru-1.0.0/drf_chelseru_chat/apps.py +6 -0
- django_chelseru-1.0.0/drf_chelseru_chat/consumers.py +82 -0
- django_chelseru-1.0.0/drf_chelseru_chat/middleware.py +33 -0
- django_chelseru-1.0.0/drf_chelseru_chat/migrations/0001_initial.py +36 -0
- django_chelseru-1.0.0/drf_chelseru_chat/migrations/__init__.py +0 -0
- django_chelseru-1.0.0/drf_chelseru_chat/models.py +23 -0
- django_chelseru-1.0.0/drf_chelseru_chat/routing.py +6 -0
- django_chelseru-1.0.0/drf_chelseru_chat/serializers.py +26 -0
- django_chelseru-1.0.0/drf_chelseru_chat/urls.py +12 -0
- django_chelseru-1.0.0/drf_chelseru_chat/views.py +59 -0
- django_chelseru-1.0.0/drf_chelseru_sms/__init__.py +0 -0
- django_chelseru-1.0.0/drf_chelseru_sms/admin.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_sms/apps.py +6 -0
- django_chelseru-1.0.0/drf_chelseru_sms/migrations/__init__.py +0 -0
- django_chelseru-1.0.0/drf_chelseru_sms/models.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_sms/tests.py +3 -0
- django_chelseru-1.0.0/drf_chelseru_sms/views.py +3 -0
- django_chelseru-1.0.0/pyproject.toml +3 -0
- django_chelseru-1.0.0/setup.cfg +4 -0
- django_chelseru-1.0.0/setup.py +36 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chelseru (Sobahan Bahman Rashnu)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include README.md
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-chelseru
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Authentication system, online and real-time chat, SMS system for Iranian SMS services.
|
|
5
|
+
Home-page: https://pip-django.chelseru.com
|
|
6
|
+
Author: Sobhan Bahman | Rashnu
|
|
7
|
+
Author-email: bahmanrashnu@gmail.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/Chelseru/django-chelseru-lour/
|
|
9
|
+
Project-URL: Telegram Group, https://t.me/bahmanpy
|
|
10
|
+
Project-URL: Telegram Channel, https://t.me/ChelseruCom
|
|
11
|
+
Keywords: djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu lour sms djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: Django>=5.1.6
|
|
20
|
+
Requires-Dist: djangorestframework==3.15.2
|
|
21
|
+
Requires-Dist: djangorestframework_simplejwt==5.5.0
|
|
22
|
+
Requires-Dist: channels==4.2.2
|
|
23
|
+
Requires-Dist: channels_redis==4.2.1
|
|
24
|
+
Requires-Dist: daphne==4.1.2
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: author-email
|
|
27
|
+
Dynamic: classifier
|
|
28
|
+
Dynamic: description
|
|
29
|
+
Dynamic: description-content-type
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: keywords
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: project-url
|
|
34
|
+
Dynamic: requires-dist
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
Dynamic: summary
|
|
37
|
+
|
|
38
|
+
# Django Chelseru
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install django-chelseru
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
-
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT License
|
|
54
|
+
|
|
55
|
+
Sobhan Bahman | Rashnu
|
|
56
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-chelseru
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Authentication system, online and real-time chat, SMS system for Iranian SMS services.
|
|
5
|
+
Home-page: https://pip-django.chelseru.com
|
|
6
|
+
Author: Sobhan Bahman | Rashnu
|
|
7
|
+
Author-email: bahmanrashnu@gmail.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/Chelseru/django-chelseru-lour/
|
|
9
|
+
Project-URL: Telegram Group, https://t.me/bahmanpy
|
|
10
|
+
Project-URL: Telegram Channel, https://t.me/ChelseruCom
|
|
11
|
+
Keywords: djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu lour sms djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: Django>=5.1.6
|
|
20
|
+
Requires-Dist: djangorestframework==3.15.2
|
|
21
|
+
Requires-Dist: djangorestframework_simplejwt==5.5.0
|
|
22
|
+
Requires-Dist: channels==4.2.2
|
|
23
|
+
Requires-Dist: channels_redis==4.2.1
|
|
24
|
+
Requires-Dist: daphne==4.1.2
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: author-email
|
|
27
|
+
Dynamic: classifier
|
|
28
|
+
Dynamic: description
|
|
29
|
+
Dynamic: description-content-type
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: keywords
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: project-url
|
|
34
|
+
Dynamic: requires-dist
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
Dynamic: summary
|
|
37
|
+
|
|
38
|
+
# Django Chelseru
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install django-chelseru
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
-
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT License
|
|
54
|
+
|
|
55
|
+
Sobhan Bahman | Rashnu
|
|
56
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
django_chelseru.egg-info/PKG-INFO
|
|
7
|
+
django_chelseru.egg-info/SOURCES.txt
|
|
8
|
+
django_chelseru.egg-info/dependency_links.txt
|
|
9
|
+
django_chelseru.egg-info/requires.txt
|
|
10
|
+
django_chelseru.egg-info/top_level.txt
|
|
11
|
+
drf_chelseru_auth/__init__.py
|
|
12
|
+
drf_chelseru_auth/admin.py
|
|
13
|
+
drf_chelseru_auth/apps.py
|
|
14
|
+
drf_chelseru_auth/models.py
|
|
15
|
+
drf_chelseru_auth/tests.py
|
|
16
|
+
drf_chelseru_auth/views.py
|
|
17
|
+
drf_chelseru_auth/migrations/__init__.py
|
|
18
|
+
drf_chelseru_chat/__init__.py
|
|
19
|
+
drf_chelseru_chat/admin.py
|
|
20
|
+
drf_chelseru_chat/apps.py
|
|
21
|
+
drf_chelseru_chat/consumers.py
|
|
22
|
+
drf_chelseru_chat/middleware.py
|
|
23
|
+
drf_chelseru_chat/models.py
|
|
24
|
+
drf_chelseru_chat/routing.py
|
|
25
|
+
drf_chelseru_chat/serializers.py
|
|
26
|
+
drf_chelseru_chat/urls.py
|
|
27
|
+
drf_chelseru_chat/views.py
|
|
28
|
+
drf_chelseru_chat/migrations/0001_initial.py
|
|
29
|
+
drf_chelseru_chat/migrations/__init__.py
|
|
30
|
+
drf_chelseru_sms/__init__.py
|
|
31
|
+
drf_chelseru_sms/admin.py
|
|
32
|
+
drf_chelseru_sms/apps.py
|
|
33
|
+
drf_chelseru_sms/models.py
|
|
34
|
+
drf_chelseru_sms/tests.py
|
|
35
|
+
drf_chelseru_sms/views.py
|
|
36
|
+
drf_chelseru_sms/migrations/__init__.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from channels.generic.websocket import AsyncWebsocketConsumer
|
|
3
|
+
from .models import ChatRoom, Message
|
|
4
|
+
from django.contrib.auth import get_user_model
|
|
5
|
+
from asgiref.sync import sync_to_async
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
User = get_user_model()
|
|
9
|
+
|
|
10
|
+
class ChatConsumer(AsyncWebsocketConsumer):
|
|
11
|
+
@sync_to_async
|
|
12
|
+
def is_user_in_chat_room(self, user, chat_room):
|
|
13
|
+
return user == chat_room.user_1 or user == chat_room.user_2
|
|
14
|
+
|
|
15
|
+
async def connect(self):
|
|
16
|
+
user = self.scope["user"]
|
|
17
|
+
if user.is_authenticated:
|
|
18
|
+
self.user = user
|
|
19
|
+
self.chat_room_id = self.scope['url_route']['kwargs']['chat_room_id']
|
|
20
|
+
self.chat_room = await sync_to_async(ChatRoom.objects.get)(id=self.chat_room_id)
|
|
21
|
+
|
|
22
|
+
if not await self.is_user_in_chat_room(user, self.chat_room):
|
|
23
|
+
await self.close()
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
self.room_group_name = f"chat_{self.chat_room.id}"
|
|
27
|
+
|
|
28
|
+
# Join room group
|
|
29
|
+
await self.channel_layer.group_add(
|
|
30
|
+
self.room_group_name,
|
|
31
|
+
self.channel_name
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
await self.accept()
|
|
35
|
+
else:
|
|
36
|
+
await self.close()
|
|
37
|
+
|
|
38
|
+
async def disconnect(self, close_code):
|
|
39
|
+
# Leave room group
|
|
40
|
+
await self.channel_layer.group_discard(
|
|
41
|
+
self.room_group_name,
|
|
42
|
+
self.channel_name
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
async def receive(self, text_data):
|
|
46
|
+
user = self.scope["user"]
|
|
47
|
+
if not user.is_authenticated:
|
|
48
|
+
await self.close()
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
text_data_json = json.loads(text_data)
|
|
52
|
+
message = text_data_json['message']
|
|
53
|
+
sender_id = self.scope['user'].id
|
|
54
|
+
# sender_id = text_data_json['sender_id']
|
|
55
|
+
sender = await sync_to_async(User.objects.get)(id=sender_id)
|
|
56
|
+
|
|
57
|
+
# Save message to database
|
|
58
|
+
chat_message = await sync_to_async(Message.objects.create)(
|
|
59
|
+
chat_room=self.chat_room,
|
|
60
|
+
sender=sender,
|
|
61
|
+
text=message
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Send message to room group
|
|
65
|
+
await self.channel_layer.group_send(
|
|
66
|
+
self.room_group_name,
|
|
67
|
+
{
|
|
68
|
+
'type': 'chat_message',
|
|
69
|
+
'message': chat_message.text,
|
|
70
|
+
'sender': sender.username
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
async def chat_message(self, event):
|
|
75
|
+
message = event['message']
|
|
76
|
+
sender = event['sender']
|
|
77
|
+
|
|
78
|
+
# Send message to WebSocket
|
|
79
|
+
await self.send(text_data=json.dumps({
|
|
80
|
+
'message': message,
|
|
81
|
+
'sender': sender
|
|
82
|
+
}))
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from urllib.parse import parse_qs
|
|
2
|
+
from channels.middleware import BaseMiddleware
|
|
3
|
+
from django.contrib.auth.models import AnonymousUser
|
|
4
|
+
from rest_framework_simplejwt.tokens import AccessToken
|
|
5
|
+
from django.contrib.auth import get_user_model
|
|
6
|
+
from asgiref.sync import sync_to_async
|
|
7
|
+
|
|
8
|
+
User = get_user_model()
|
|
9
|
+
|
|
10
|
+
@sync_to_async
|
|
11
|
+
def get_user(validated_token):
|
|
12
|
+
try:
|
|
13
|
+
user_id = validated_token["user_id"]
|
|
14
|
+
return User.objects.get(id=user_id)
|
|
15
|
+
except User.DoesNotExist:
|
|
16
|
+
return AnonymousUser()
|
|
17
|
+
|
|
18
|
+
class JWTAuthMiddleware(BaseMiddleware):
|
|
19
|
+
async def __call__(self, scope, receive, send):
|
|
20
|
+
query_string = scope.get("query_string", b"").decode()
|
|
21
|
+
query_params = parse_qs(query_string)
|
|
22
|
+
token = query_params.get("token")
|
|
23
|
+
|
|
24
|
+
if token:
|
|
25
|
+
try:
|
|
26
|
+
access_token = AccessToken(token[0])
|
|
27
|
+
scope["user"] = await get_user(access_token)
|
|
28
|
+
except Exception as e:
|
|
29
|
+
scope["user"] = AnonymousUser()
|
|
30
|
+
else:
|
|
31
|
+
scope["user"] = AnonymousUser()
|
|
32
|
+
|
|
33
|
+
return await super().__call__(scope, receive, send)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Generated by Django 5.1.6 on 2025-08-10 16:17
|
|
2
|
+
|
|
3
|
+
import django.db.models.deletion
|
|
4
|
+
from django.conf import settings
|
|
5
|
+
from django.db import migrations, models
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Migration(migrations.Migration):
|
|
9
|
+
|
|
10
|
+
initial = True
|
|
11
|
+
|
|
12
|
+
dependencies = [
|
|
13
|
+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
operations = [
|
|
17
|
+
migrations.CreateModel(
|
|
18
|
+
name='ChatRoom',
|
|
19
|
+
fields=[
|
|
20
|
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
21
|
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
22
|
+
('user_1', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user1_chats', to=settings.AUTH_USER_MODEL)),
|
|
23
|
+
('user_2', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user2_chats', to=settings.AUTH_USER_MODEL)),
|
|
24
|
+
],
|
|
25
|
+
),
|
|
26
|
+
migrations.CreateModel(
|
|
27
|
+
name='Message',
|
|
28
|
+
fields=[
|
|
29
|
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
30
|
+
('text', models.TextField()),
|
|
31
|
+
('timestamp', models.DateTimeField(auto_now_add=True)),
|
|
32
|
+
('chat_room', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='drf_chelseru_chat.chatroom')),
|
|
33
|
+
('sender', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
|
34
|
+
],
|
|
35
|
+
),
|
|
36
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from django.contrib.auth import get_user_model
|
|
2
|
+
from django.db import models
|
|
3
|
+
|
|
4
|
+
User = get_user_model()
|
|
5
|
+
|
|
6
|
+
class ChatRoom(models.Model):
|
|
7
|
+
user_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user1_chats')
|
|
8
|
+
user_2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user2_chats')
|
|
9
|
+
|
|
10
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
11
|
+
|
|
12
|
+
def __str__(self):
|
|
13
|
+
return f"ID: {self.id} | Chat between {self.user_1.username} and {self.user_2.username}"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Message(models.Model):
|
|
17
|
+
chat_room = models.ForeignKey(ChatRoom, on_delete=models.CASCADE, related_name='messages')
|
|
18
|
+
sender = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
19
|
+
text = models.TextField()
|
|
20
|
+
timestamp = models.DateTimeField(auto_now_add=True)
|
|
21
|
+
|
|
22
|
+
def __str__(self):
|
|
23
|
+
return f"iD: {self.id} | Message from {self.sender.username} at {self.timestamp} | Chatroom ID: {self.chat_room.id}"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from rest_framework import serializers
|
|
2
|
+
from .models import ChatRoom, Message
|
|
3
|
+
from django.contrib.auth import get_user_model
|
|
4
|
+
|
|
5
|
+
User = get_user_model()
|
|
6
|
+
|
|
7
|
+
class UserSerializer(serializers.ModelSerializer):
|
|
8
|
+
class Meta:
|
|
9
|
+
model = User
|
|
10
|
+
fields = ['id', 'username', 'email']
|
|
11
|
+
|
|
12
|
+
class ChatRoomSerializer(serializers.ModelSerializer):
|
|
13
|
+
user_1, user_2 = UserSerializer(read_only=True), UserSerializer(read_only=True)
|
|
14
|
+
class Meta:
|
|
15
|
+
model = ChatRoom
|
|
16
|
+
fields = '__all__'
|
|
17
|
+
depth = 1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MessageSerializer(serializers.ModelSerializer):
|
|
21
|
+
sender = UserSerializer(read_only=True)
|
|
22
|
+
|
|
23
|
+
class Meta:
|
|
24
|
+
model = Message
|
|
25
|
+
fields = '__all__'
|
|
26
|
+
depth = 1
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# urls.py
|
|
2
|
+
from django.urls import path, include
|
|
3
|
+
from rest_framework.routers import DefaultRouter
|
|
4
|
+
from .views import ChatRoomViewSet, MessageViewSet
|
|
5
|
+
|
|
6
|
+
router = DefaultRouter()
|
|
7
|
+
router.register(r'chatrooms', ChatRoomViewSet, basename='chatroom')
|
|
8
|
+
router.register(r'messages', MessageViewSet, basename='messages')
|
|
9
|
+
|
|
10
|
+
urlpatterns = [
|
|
11
|
+
path('api/', include(router.urls)),
|
|
12
|
+
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from rest_framework import viewsets, permissions
|
|
2
|
+
from .models import ChatRoom, Message
|
|
3
|
+
from .serializers import ChatRoomSerializer, MessageSerializer
|
|
4
|
+
from django.db.models import Q
|
|
5
|
+
from rest_framework.decorators import action
|
|
6
|
+
from rest_framework.response import Response
|
|
7
|
+
from rest_framework import status as drf_status
|
|
8
|
+
from rest_framework.exceptions import PermissionDenied, NotFound, ValidationError
|
|
9
|
+
# from django_filters.rest_framework import DjangoFilterBackend
|
|
10
|
+
from django.contrib.auth.models import User
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# views.py
|
|
14
|
+
class ChatRoomViewSet(viewsets.ModelViewSet):
|
|
15
|
+
serializer_class = ChatRoomSerializer
|
|
16
|
+
permission_classes = [permissions.IsAuthenticated]
|
|
17
|
+
model = serializer_class.Meta.model
|
|
18
|
+
|
|
19
|
+
def get_queryset(self):
|
|
20
|
+
return self.model.objects.filter(user_1=self.request.user) | self.model.objects.filter(user_2=self.request.user)
|
|
21
|
+
|
|
22
|
+
def perform_create(self, serializer):
|
|
23
|
+
user = self.request.user
|
|
24
|
+
|
|
25
|
+
user_id = self.request.data.get('user', None)
|
|
26
|
+
user_2 = User.objects.filter(id=user_id).first()
|
|
27
|
+
if not user_2:
|
|
28
|
+
raise NotFound("کاربر مورد نظر با آی دی فرستاده شده یافت نشد.")
|
|
29
|
+
|
|
30
|
+
chat_room = serializer.save(user_1=user, user_2=user_2)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class MessageViewSet(viewsets.ModelViewSet):
|
|
34
|
+
serializer_class = MessageSerializer
|
|
35
|
+
permission_classes = [permissions.IsAuthenticated]
|
|
36
|
+
|
|
37
|
+
def get_queryset(self):
|
|
38
|
+
user = self.request.user
|
|
39
|
+
|
|
40
|
+
queryset = self.serializer_class.Meta.model.objects.filter(user=profile.organization)
|
|
41
|
+
chat_room_id = self.request.query_params.get('chat_room')
|
|
42
|
+
if chat_room_id:
|
|
43
|
+
queryset = queryset.filter(chat_room_id=chat_room_id)
|
|
44
|
+
return queryset
|
|
45
|
+
|
|
46
|
+
def perform_create(self, serializer):
|
|
47
|
+
chat_room_id = self.request.data.get('chat_room')
|
|
48
|
+
if not chat_room_id:
|
|
49
|
+
raise ValidationError("فیلد chat_room اجباریه.")
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
chat = ChatRoom.objects.get(id=chat_room_id)
|
|
53
|
+
except ChatRoom.DoesNotExist:
|
|
54
|
+
raise NotFound("چتروم پیدا نشد.")
|
|
55
|
+
|
|
56
|
+
message = serializer.save(sender=self.request.user, chat_room=chat)
|
|
57
|
+
chat = message.chat_room
|
|
58
|
+
chat.save()
|
|
59
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name='django-chelseru',
|
|
6
|
+
version='1.0.0',
|
|
7
|
+
packages=find_packages(),
|
|
8
|
+
include_package_data=True,
|
|
9
|
+
install_requires=[
|
|
10
|
+
'Django>=5.1.6',
|
|
11
|
+
'djangorestframework==3.15.2',
|
|
12
|
+
'djangorestframework_simplejwt==5.5.0',
|
|
13
|
+
'channels==4.2.2',
|
|
14
|
+
'channels_redis==4.2.1',
|
|
15
|
+
'daphne==4.1.2'
|
|
16
|
+
],
|
|
17
|
+
author='Sobhan Bahman | Rashnu',
|
|
18
|
+
author_email='bahmanrashnu@gmail.com',
|
|
19
|
+
description='Authentication system, online and real-time chat, SMS system for Iranian SMS services.',
|
|
20
|
+
long_description=open('README.md').read(),
|
|
21
|
+
long_description_content_type='text/markdown',
|
|
22
|
+
url='https://pip-django.chelseru.com',
|
|
23
|
+
project_urls={
|
|
24
|
+
"Documentation": "https://github.com/Chelseru/django-chelseru-lour/",
|
|
25
|
+
"Telegram Group": "https://t.me/bahmanpy",
|
|
26
|
+
"Telegram Channel": "https://t.me/ChelseruCom",
|
|
27
|
+
},
|
|
28
|
+
classifiers=[
|
|
29
|
+
'Programming Language :: Python :: 3',
|
|
30
|
+
'Framework :: Django',
|
|
31
|
+
'License :: OSI Approved :: MIT License',
|
|
32
|
+
'Operating System :: OS Independent',
|
|
33
|
+
],
|
|
34
|
+
python_requires='>=3.11',
|
|
35
|
+
keywords="djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu lour sms djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم",
|
|
36
|
+
)
|