chat routines
This commit is contained in:
SDE
2023-08-08 16:09:16 +03:00
parent f62c603ad4
commit 014ccf8f45
3 changed files with 17 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ from django.template.loader import render_to_string
from django.urls import reverse
from .funcs import *
import json
from datetime import datetime, time
@login_required(login_url='/profile/login/')
@@ -53,6 +54,8 @@ def update_chat_ajax(request):
msg = None
Dict = {}
last_message_modifiedDT = None
try:
data = json.loads(request.body)
@@ -61,9 +64,12 @@ def update_chat_ajax(request):
tpl_name = 'blocks/profile/b_messages_container.html'
if 'ticket_id' in data and data['ticket_id']:
if 'ticket_id' in data and data['ticket_id'] and data['ticket_id'] != 'null':
ticket = MsgGroup.objects.get(id=data['ticket_id'])
if 'last_message_modifiedDT' in data:
last_message_modifiedDT = datetime.strptime(data['last_message_modifiedDT'], '%d.%m.%Y %H:%M:%S:%f')
sender = User.objects.get(id=data['sender'])
receiver = User.objects.get(id=data['receiver'])
@@ -77,6 +83,13 @@ def update_chat_ajax(request):
else:
msgs = get_msgs_for_chat_w_users(sender, receiver)
if last_message_modifiedDT:
if not msgs or msgs[0].modifiedDT <= last_message_modifiedDT:
Dict.update({
'msgs_count': len(msgs)
})
return JsonResponse(Dict, status=200)
res_Dict.update({
'messages': msgs,

View File

@@ -58,7 +58,7 @@ def create_airports_by_airportsList(airportsList, city=None):
kwargs.update({'iata_code': airport_Dict['iata']})
airport = Airport.objects.get(**kwargs)
except Airport.DoesNotExist:
print(f' - - {airport_Dict["int_name"]} не найден в БД > добавляем')
print(f' - - {airport_Dict["iata"]} не найден в БД > добавляем')
except Exception as e:
print(f'error = {str(e)}')

View File

@@ -7,8 +7,8 @@
{% else %}
{% for msg in messages %}
{% include "widgets/w_message.html" %}
{% if forloop.last %}
<span style="display: none" class="date_n_time_last_message" data-modifiedDT="{{ msg.modifiedDT }}"></span>
{% if forloop.first %}
<span style="display: none" class="date_n_time_last_message" data-modifiedDT="{{ msg.modifiedDT|date:"d.m.Y H:i:s:u" }}"></span>
{% endif %}
{% endfor %}
{% endif %}