0.7.32
files in chat download
This commit is contained in:
@@ -13,4 +13,6 @@ urlpatterns = [
|
||||
# path('send_msg/', send_msg_ajax, name='send_msg_ajax'),
|
||||
# path('update_chat/', update_chat_ajax2, name='update_chat_ajax'),
|
||||
path('show_chat_w_user/', show_chat_w_user_ajax, name='show_chat_w_user_ajax'),
|
||||
|
||||
path('get_file_from_msg/', get_file_from_msg_ajax, name='get_file_from_msg_ajax'),
|
||||
]
|
||||
@@ -18,6 +18,31 @@ from channels.layers import get_channel_layer
|
||||
from asgiref.sync import async_to_sync
|
||||
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def get_file_from_msg_ajax(request):
|
||||
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
msg = Message.objects.get(id=data['message_id'])
|
||||
|
||||
res_Dict = {}
|
||||
for file in msg.files:
|
||||
if file['file_name'] == data['file_name']:
|
||||
res_Dict = file
|
||||
break
|
||||
|
||||
return JsonResponse(res_Dict, status=200)
|
||||
|
||||
except Exception as e:
|
||||
msg = f'get_file_from_msg_ajax Error = {str(e)}'
|
||||
return JsonResponse({'error': msg}, status=400)
|
||||
|
||||
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def show_chat_w_user_ajax(request):
|
||||
|
||||
|
||||
@@ -16,6 +16,27 @@ register = template.Library()
|
||||
def get_ws_address():
|
||||
return settings.WS_ADDRESS
|
||||
|
||||
@register.simple_tag
|
||||
def get_filesize(size):
|
||||
if size:
|
||||
unit = 'B'
|
||||
if size / 1024 > 1:
|
||||
unit = 'KB'
|
||||
size = size / 1024
|
||||
if size / 1024 > 1:
|
||||
unit = 'MB'
|
||||
size = size / 1024
|
||||
if size / 1024 > 1:
|
||||
unit = 'GB'
|
||||
size = size / 1024
|
||||
if size / 1024 > 1:
|
||||
unit = 'TB'
|
||||
size = size / 1024
|
||||
size = round(size, 2)
|
||||
return f'{str(size)}{unit}'
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def get_msg_side(cur_user, ticket, msg):
|
||||
|
||||
Reference in New Issue
Block a user