From e86aa7600288e55cb167a36470149cd9b26f4c5f Mon Sep 17 00:00:00 2001 From: SDE Date: Wed, 16 Aug 2023 15:33:46 +0300 Subject: [PATCH] 0.3.25 support chat v3 --- AuthApp/middleware.py | 20 +++++++++++--------- ChatServiceApp/templatetags/tt_chat.py | 7 +++++++ TWB/settings.py | 4 ++++ templates/tb_base.html | 4 +++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/AuthApp/middleware.py b/AuthApp/middleware.py index f2333d1..4454a1b 100644 --- a/AuthApp/middleware.py +++ b/AuthApp/middleware.py @@ -49,16 +49,18 @@ class ResponseInterceptionMiddleware: # def process_view(self, request, view_func, *view_args, **view_kwargs): # - # if request.user.is_authenticated and request.body: - # for_save_to_session = request.user.user_profile.pop_node_by_name('for_save_to_session') - # if for_save_to_session: - # data = json.loads(request.body) - # data.update(for_save_to_session) + # request.META.update({'ws_port': settings.WS_PORT}) # - # # request_data = getattr(request, '_body', request.body) - # # request_data = json.loads(request_data) - # # # here you can write the logic to append the payload to request data - # request._body = json.dumps(data) + # # if request.user.is_authenticated and request.body: + # # for_save_to_session = request.user.user_profile.pop_node_by_name('for_save_to_session') + # # if for_save_to_session: + # # data = json.loads(request.body) + # # data.update(for_save_to_session) + # # + # # # request_data = getattr(request, '_body', request.body) + # # # request_data = json.loads(request_data) + # # # # here you can write the logic to append the payload to request data + # # request._body = json.dumps(data) # return None # def __call__(self, request): diff --git a/ChatServiceApp/templatetags/tt_chat.py b/ChatServiceApp/templatetags/tt_chat.py index e65385a..39b644d 100644 --- a/ChatServiceApp/templatetags/tt_chat.py +++ b/ChatServiceApp/templatetags/tt_chat.py @@ -1,5 +1,6 @@ from django import template from django.template.defaultfilters import stringfilter +from django.conf import settings register = template.Library() @@ -10,6 +11,12 @@ register = template.Library() # from django.utils.html import mark_safe # @register.filter('get_msg_side') + +@register.simple_tag +def get_ws_port(): + return settings.WS_PORT + + @register.simple_tag def get_msg_side(cur_user, ticket, msg): if msg: diff --git a/TWB/settings.py b/TWB/settings.py index d32532e..3f1b6aa 100644 --- a/TWB/settings.py +++ b/TWB/settings.py @@ -91,10 +91,14 @@ TEMPLATES = [ # WSGI_APPLICATION = 'TWB.wsgi.application' ASGI_APPLICATION = 'TWB.asgi.application' +WS_PORT = 8000 + CHANNEL_LAYERS = { 'default': { # 'BACKEND': 'channels.layers.InMemoryChannelLayer', "BACKEND": "channels_redis.core.RedisChannelLayer", + # 'USER': 'spadredis-zxs-service', + # 'PASSWORD': '9zghygpri84f8vl', "CONFIG": { "hosts": [("127.0.0.1", 6379)], }, diff --git a/templates/tb_base.html b/templates/tb_base.html index fbfe660..136ec91 100644 --- a/templates/tb_base.html +++ b/templates/tb_base.html @@ -1,4 +1,6 @@ {% load static %} +{% load tt_chat %} + @@ -10,7 +12,7 @@