websocket & change broker decimal to int
This commit is contained in:
@@ -7,10 +7,27 @@ For more information on this file, see
|
|||||||
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# import os
|
||||||
|
#
|
||||||
|
# from django.core.asgi import get_asgi_application
|
||||||
|
#
|
||||||
|
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Rasaddam_Backend.settings')
|
||||||
|
#
|
||||||
|
# application = get_asgi_application()
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
from channels.auth import AuthMiddlewareStack
|
||||||
|
from apps.authentication.websocket import routing
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Rasaddam_Backend.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project_name.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = ProtocolTypeRouter({
|
||||||
|
"http": get_asgi_application(),
|
||||||
|
"websocket": AuthMiddlewareStack(
|
||||||
|
URLRouter(
|
||||||
|
routing.websocket_urlpatterns
|
||||||
|
)
|
||||||
|
),
|
||||||
|
})
|
||||||
@@ -44,6 +44,8 @@ sentry_sdk.init(
|
|||||||
profile_lifecycle="trace",
|
profile_lifecycle="trace",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ASGI_APPLICATION = "Rasaddam_Backend.asgi.application" # noqa
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
'localhost',
|
'localhost',
|
||||||
'127.0.0.1',
|
'127.0.0.1',
|
||||||
|
|||||||
@@ -4,9 +4,5 @@ from apps.product.models import SaleUnit
|
|||||||
|
|
||||||
@shared_task(bind=True)
|
@shared_task(bind=True)
|
||||||
def task_func(self):
|
def task_func(self):
|
||||||
print("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss")
|
print("Task Is Running.....")
|
||||||
sale_unit = SaleUnit.objects.get(id=1)
|
|
||||||
print(sale_unit.unit)
|
|
||||||
sale_unit.trash = True
|
|
||||||
sale_unit.save()
|
|
||||||
return 'Done'
|
return 'Done'
|
||||||
|
|||||||
0
apps/authentication/websocket/__init__.py
Normal file
0
apps/authentication/websocket/__init__.py
Normal file
30
apps/authentication/websocket/consumer.py
Normal file
30
apps/authentication/websocket/consumer.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
from channels.generic.websocket import AsyncWebsocketConsumer
|
||||||
|
from apps.product.models import SaleUnit
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
@sync_to_async
|
||||||
|
def get_unit(unit_id=None):
|
||||||
|
unit = SaleUnit.objects.get(id=int(unit_id))
|
||||||
|
return unit
|
||||||
|
|
||||||
|
|
||||||
|
class MyConsumer(AsyncWebsocketConsumer):
|
||||||
|
async def connect(self):
|
||||||
|
await self.accept()
|
||||||
|
await self.send(text_data=json.dumps({"message": "Connected!"}))
|
||||||
|
|
||||||
|
async def disconnect(self, close_code):
|
||||||
|
print("WebSocket disconnected!")
|
||||||
|
|
||||||
|
async def receive(self, text_data):
|
||||||
|
data = json.loads(text_data)
|
||||||
|
message = data.get("message")
|
||||||
|
unit = await get_unit(int(message))
|
||||||
|
print("Received:", message)
|
||||||
|
|
||||||
|
# پاسخ به کلاینت
|
||||||
|
await self.send(text_data=json.dumps({
|
||||||
|
"message": unit
|
||||||
|
}))
|
||||||
6
apps/authentication/websocket/routing.py
Normal file
6
apps/authentication/websocket/routing.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.urls import re_path
|
||||||
|
from apps.authentication.websocket import consumer
|
||||||
|
|
||||||
|
websocket_urlpatterns = [
|
||||||
|
re_path(r"ws/somepath/$", consumer.MyConsumer.as_asgi()),
|
||||||
|
]
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-07-19 10:59
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0049_alter_quota_limit_by_organizations'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='quotabrokervalue',
|
||||||
|
name='value',
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/product/migrations/0051_quotabrokervalue_value.py
Normal file
18
apps/product/migrations/0051_quotabrokervalue_value.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-07-19 10:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0050_remove_quotabrokervalue_value'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quotabrokervalue',
|
||||||
|
name='value',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -450,7 +450,7 @@ class QuotaBrokerValue(BaseModel):
|
|||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='values'
|
related_name='values'
|
||||||
)
|
)
|
||||||
value = models.DecimalField(max_digits=12, decimal_places=2)
|
value = models.PositiveBigIntegerField(default=0)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Quota ({self.quota.id}) for Broker({self.broker.organization.name})"
|
return f"Quota ({self.quota.id}) for Broker({self.broker.organization.name})"
|
||||||
|
|||||||
@@ -78,4 +78,7 @@ tinydb
|
|||||||
django-simple-history
|
django-simple-history
|
||||||
sentry_sdk
|
sentry_sdk
|
||||||
django-celery-beat
|
django-celery-beat
|
||||||
django-celery-results
|
django-celery-results
|
||||||
|
channels
|
||||||
|
channels_redis
|
||||||
|
daphne
|
||||||
Reference in New Issue
Block a user