From 8c2043198f0c5781b727ea7d6b3f774cbab291d0 Mon Sep 17 00:00:00 2001 From: SDE Date: Sun, 6 Aug 2023 15:22:52 +0300 Subject: [PATCH] 0.1.34 chat routines --- AuthApp/views.py | 2 +- ChatServiceApp/js_urls.py | 1 + ChatServiceApp/js_views.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/AuthApp/views.py b/AuthApp/views.py index c47eb2f..1762574 100644 --- a/AuthApp/views.py +++ b/AuthApp/views.py @@ -44,7 +44,7 @@ def chat_w_user_View(request, user_id=None): 'page': 'chat', 'cur_receiver': cur_receiver, 'receivers': receivers, - 'cur_chat_msgs':cur_chat_msgs + 'messages':cur_chat_msgs } t = loader.get_template('pages/profile/p_user_profile.html') diff --git a/ChatServiceApp/js_urls.py b/ChatServiceApp/js_urls.py index 5b6c852..774c4a0 100644 --- a/ChatServiceApp/js_urls.py +++ b/ChatServiceApp/js_urls.py @@ -11,4 +11,5 @@ urlpatterns = [ path('create_ticket/', create_ticket_ajax, name='create_ticket_ajax'), path('support_show_chat_by_ticket/', support_show_chat_by_ticket_ajax, name='support_show_chat_by_ticket_ajax'), path('send_msg/', send_msg_ajax, name='send_msg_ajax'), + path('show_chat_w_user/', show_chat_w_user_ajax, name='show_chat_w_user_ajax'), ] \ No newline at end of file diff --git a/ChatServiceApp/js_views.py b/ChatServiceApp/js_views.py index e823aca..45708a6 100644 --- a/ChatServiceApp/js_views.py +++ b/ChatServiceApp/js_views.py @@ -15,6 +15,34 @@ from .funcs import * import json +@login_required(login_url='/profile/login/') +def show_chat_w_user_ajax(request): + + if request.method != 'POST': + raise Http404 + + try: + + data = json.loads(request.body) + + from AuthApp.models import User + cur_receiver = User.objects.get(id=data['user_id']) + + Dict = { + 'cur_receiver': cur_receiver, + 'messages': get_msgs_for_chat_w_users(request.user, cur_receiver), + } + + tpl_name = 'blocks/profile/b_chats.html' + + html = render_to_string(tpl_name, Dict, request=request) + return JsonResponse({'html': html}, status=200) + + except Exception as e: + msg = f'show_chat_w_user_ajax Error = {str(e)}' + return JsonResponse({'error': msg}, status=400) + + @login_required(login_url='/profile/login/') def send_msg_ajax(request): from AuthApp.models import User