Fix bad names

This commit is contained in:
Andros Fenollosa 2021-03-08 21:25:34 +01:00
parent 91a01428fe
commit e3e1a0144c
11 changed files with 25 additions and 33 deletions

View File

@ -1,4 +1,4 @@
http://guitarlions.localhost http://my-demo.localhost
root * /usr/src/app/ root * /usr/src/app/

View File

@ -1,8 +1,7 @@
import json import json
from channels.generic.websocket import AsyncWebsocketConsumer from channels.generic.websocket import AsyncWebsocketConsumer
from asgiref.sync import sync_to_async
class BackConsumer(AsyncWebsocketConsumer): class BlogConsumer(AsyncWebsocketConsumer):
def connect(self): def connect(self):
''' Cliente se conecta ''' ''' Cliente se conecta '''
@ -12,15 +11,15 @@ class BackConsumer(AsyncWebsocketConsumer):
self.room_group_name = "blog_%s" % self.room_name self.room_group_name = "blog_%s" % self.room_name
# Se une a la sala # Se une a la sala
await self.channel_layer.group_add(self.room_group_name, self.channel_name) self.channel_layer.group_add(self.room_group_name, self.channel_name)
# Informa al cliente del éxito # Informa al cliente del éxito
await self.accept() self.accept()
def disconnect(self, close_code): def disconnect(self, close_code):
''' Cliente se desconecta ''' ''' Cliente se desconecta '''
# Leave room group # Leave room group
await self.channel_layer.group_discard(self.room_group_name, self.channel_name) self.channel_layer.group_discard(self.room_group_name, self.channel_name)
def receive(self, text_data): def receive(self, text_data):
''' Cliente envía información y nosotros la recibimos ''' ''' Cliente envía información y nosotros la recibimos '''
@ -29,7 +28,7 @@ class BackConsumer(AsyncWebsocketConsumer):
text = text_data_json["text"] text = text_data_json["text"]
# Enviamos el mensaje a la sala # Enviamos el mensaje a la sala
await self.channel_layer.group_send( self.channel_layer.group_send(
self.room_group_name, self.room_group_name,
{ {
"type": "chat_message", "type": "chat_message",
@ -44,7 +43,7 @@ class BackConsumer(AsyncWebsocketConsumer):
text = event["text"] text = event["text"]
# Send message to WebSocket # Send message to WebSocket
await self.send( self.send(
text_data=json.dumps( text_data=json.dumps(
{ {
"type": "chat_message", "type": "chat_message",

11
asgi.py
View File

@ -1,11 +0,0 @@
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
import django
django.setup()
from channels.routing import ProtocolTypeRouter
application = ProtocolTypeRouter({})

View File

@ -11,4 +11,4 @@ python3 manage.py migrate
# Start server # Start server
echo "Starting server" echo "Starting server"
uvicorn --host 0.0.0.0 --port 8000 --reload chapps.asgi:application uvicorn --host 0.0.0.0 --port 8000 --reload my_demo.asgi:application

View File

@ -11,4 +11,4 @@ python3 manage.py migrate
# Start server # Start server
echo "Starting server" echo "Starting server"
uvicorn --host 0.0.0.0 --port 8000 chapps.asgi:application uvicorn --host 0.0.0.0 --port 8000 my_demo.asgi:application

View File

@ -6,7 +6,7 @@ import sys
def main(): def main():
"""Run administrative tasks.""" """Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mi_web.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_demo.settings')
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:

View File

@ -1,6 +1,6 @@
import os import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mi_web.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_demo.settings")
import django import django
django.setup() django.setup()
@ -8,7 +8,7 @@ django.setup()
from channels.auth import AuthMiddlewareStack from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
from apps.chat.routing import websocket_urlpatterns from apps.back.routing import websocket_urlpatterns
application = ProtocolTypeRouter( application = ProtocolTypeRouter(

View File

@ -1,5 +1,5 @@
""" """
Django settings for mi_web project. Django settings for my_demo project.
Generated by 'django-admin startproject' using Django 3.1.3. Generated by 'django-admin startproject' using Django 3.1.3.
@ -38,7 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'channels', 'channels',
'apps.chat', 'apps.back',
'apps.front', 'apps.front',
] ]
@ -52,7 +52,7 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ]
ROOT_URLCONF = 'mi_web.urls' ROOT_URLCONF = 'my_demo.urls'
TEMPLATES = [ TEMPLATES = [
{ {
@ -77,8 +77,12 @@ TEMPLATES = [
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase', 'NAME': 'demo',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': '127.0.0.1',
'PORT': '5432',
} }
} }

View File

@ -1,10 +1,10 @@
# Django # Django
django django
# Servidor para Django # ASGI server
daphne==2.4.1 uvicorn
# Conector para PostgreSQL # Connect PostgreSQL
psycopg2-binary psycopg2-binary
# Channels # Channels
channels==2.4.0 channels==2.4.0
# Conector de Redis para Channels # Connect Redis for Channels
channels_redis channels_redis