0.7.33
files in chat download
This commit is contained in:
@@ -107,6 +107,9 @@ def get_update_chat_Dict(data):
|
||||
|
||||
def send_msg(data):
|
||||
from AuthApp.models import User
|
||||
import base64
|
||||
import os
|
||||
|
||||
res_Dict = {}
|
||||
msg = None
|
||||
required_update_tickets_list_wo_managers = False
|
||||
@@ -178,13 +181,27 @@ def send_msg(data):
|
||||
if 'text' in data:
|
||||
msg_create_kwargs.update({'text': data['text']})
|
||||
|
||||
msg = Message.objects.create(**msg_create_kwargs)
|
||||
|
||||
if 'files' in data:
|
||||
files_list = []
|
||||
for file in data['files']:
|
||||
files_list.append(json.loads(file))
|
||||
msg_create_kwargs.update({'files': files_list})
|
||||
file_data =json.loads(file)
|
||||
|
||||
if not os.path.exists(f'chat_file_storage/{msg.id}'):
|
||||
os.makedirs(f'chat_file_storage/{msg.id}')
|
||||
f = open(f'chat_file_storage/{msg.id}/{file_data["file_name"]}', 'wb+')
|
||||
head, content = file_data['file'].split(',')
|
||||
content = base64.b64decode(content)
|
||||
f.write(content)
|
||||
f.close()
|
||||
|
||||
del file_data['file']
|
||||
files_list.append(file_data)
|
||||
msg.files = files_list
|
||||
msg.save(update_fields=['files'])
|
||||
|
||||
|
||||
msg = Message.objects.create(**msg_create_kwargs)
|
||||
|
||||
# if ticket:
|
||||
# msgs = get_messages_for_ticket(ticket)
|
||||
|
||||
Reference in New Issue
Block a user