Skip to content

Commit

Permalink
Merge branch 'develop' into feature/exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Nov 30, 2024
2 parents 37ae965 + a651a5d commit 6f70bcf
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 5 deletions.
7 changes: 5 additions & 2 deletions django/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
asgiref==3.8.1
Django==5.1
Django==5.1.1
django-cors-headers==4.4.0
djangorestframework==3.15.1
djangorestframework==3.15.2
pytz==2021.3
sqlparse==0.5.1
psycopg2==2.9.9
Expand All @@ -11,3 +11,6 @@ python-dotenv==1.0.1
requests==2.31.0
pyjwt==2.8.0
mozilla-django-oidc==4.0.1
channels==4.1.0
daphne==4.1.2
python-socketio==5.11.4
8 changes: 6 additions & 2 deletions django/tts_be/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
"""

import os

from django.core.asgi import get_asgi_application

import socketio
from university.socket.views import sio

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tts_be.settings')

application = get_asgi_application()
django_app = get_asgi_application()

application = socketio.ASGIApp(sio, django_app)
11 changes: 11 additions & 0 deletions django/tts_be/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

JWT_KEY= CONFIG['JWT_KEY']

DEBUG = os.getenv('DEBUG')
DEBUG = int(DEBUG) != 0 if DEBUG else False

DOMAIN = os.getenv('DOMAIN')
DEBUG = False if int(CONFIG['DEBUG']) == 0 else True

Expand All @@ -43,14 +46,20 @@
# 'django_extensions',
'university',
'corsheaders',
'daphne',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions', # legacy
'django.contrib.messages',
'rest_framework',
'django.contrib.staticfiles',
<<<<<<< HEAD
'mozilla_django_oidc'
=======
'university',
'channels',
>>>>>>> develop
]

MIDDLEWARE = [
Expand Down Expand Up @@ -125,6 +134,8 @@

OIDC_RENEW_ID_TOKEN_EXPIRY_SECONDS = 3600 * 60

ASGI_APPLICATION = 'tts_be.asgi.application'

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

Expand Down
11 changes: 11 additions & 0 deletions django/university/socket/sessionsserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import uuid

class SessionsServer:
def __init__(self, sio):
self.sio = sio

def valid_token(self, token):
return True

def event(self, event):
return self.sio.event(event)
33 changes: 33 additions & 0 deletions django/university/socket/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import socketio

from university.socket.sessionsserver import SessionsServer

async_mode = None

basedir = os.path.dirname(os.path.realpath(__file__))
sio = socketio.AsyncServer(
async_mode='asgi',
cors_allowed_origins="*",
)

session_server = SessionsServer(sio)

@session_server.event
async def connect(sid, environ, auth):
if auth is None or 'token' not in auth:
raise ConnectionRefusedError('Authentication failed: No token provided')
elif not session_server.valid_token(auth['token']):
raise ConnectionRefusedError('Authentication failed: Invalid token')
else:
print('Client connected')
await sio.emit('my_response', {'data': 'Connected', 'count': 0}, room=sid)


@session_server.event
def disconnect(sid):
print('Client disconnected')

@session_server.event
async def test(sid, environ):
await sio.emit('response', 'ya')
2 changes: 1 addition & 1 deletion fetcher/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.28.1
requests==2.32.2
Binary file added postgres/sql/report-41.pdf
Binary file not shown.

0 comments on commit 6f70bcf

Please sign in to comment.