From ca89510799d21ca417db60aca047d2717f5d8cfe Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 23 May 2020 18:13:42 -0500 Subject: [PATCH] Fix page unable to scroll up --- chat_box/consumers.py | 2 -- chat_box/views.py | 13 +++---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/chat_box/consumers.py b/chat_box/consumers.py index 2ed85ae..60893c9 100644 --- a/chat_box/consumers.py +++ b/chat_box/consumers.py @@ -1,7 +1,6 @@ import json from channels.generic.websocket import AsyncWebsocketConsumer from .models import Message -from .views import format_time from django.urls import reverse from django.http import HttpResponse, HttpResponseRedirect from django.core import serializers @@ -35,7 +34,6 @@ class ChatConsumer(AsyncWebsocketConsumer): message = text_data_json['message'] message_saved = save_data_and_return(message) - message['time'] = message_saved[0]['fields']['time'] message['id'] = message_saved[0]['pk'] diff --git a/chat_box/views.py b/chat_box/views.py index 8640b09..d5bc8a0 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -10,20 +10,16 @@ from .models import Message import json -def format_time(time): - return time - #return time.strftime('%H:%M %p %d-%m-%Y') - def format_messages(messages): msg_list = [{ - 'time': format_time(msg.time), + 'time': msg.time, 'author': str(msg.author), 'body': msg.body, 'image': gravatar(msg.author, 32), 'id': msg.id } for msg in messages] - return json.dumps(msg_list) + return json.dumps(msg_list, default=str) class ChatView(ListView): @@ -50,9 +46,6 @@ class ChatView(ListView): context = super().get_context_data(**kwargs) context['title'] = self.title - for msg in context['message']: - msg.time = format_time(msg.time) - return context def delete_message(request): @@ -69,7 +62,7 @@ def delete_message(request): if mess.id == messid: mess.hidden = True mess.save() - new_elt = {'time': format_time(mess.time), 'content': mess.body} + new_elt = {'time': mess.time, 'content': mess.body} ret = new_elt break