From d4c203c620d1a198a3e95a1526e3c003ad3edf91 Mon Sep 17 00:00:00 2001 From: thanhluong Date: Fri, 22 May 2020 17:16:42 +0000 Subject: [PATCH] Change time format --- chat_box/asgi.py | 12 ++++++++++++ chat_box/consumers.py | 1 + chat_box/migrations/0002_message_hidden.py | 18 ++++++++++++++++++ chat_box/migrations/0003_auto_20200505_2306.py | 18 ++++++++++++++++++ chat_box/migrations/0004_auto_20200505_2336.py | 18 ++++++++++++++++++ chat_box/views.py | 5 +++-- 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 chat_box/asgi.py create mode 100644 chat_box/migrations/0002_message_hidden.py create mode 100644 chat_box/migrations/0003_auto_20200505_2306.py create mode 100644 chat_box/migrations/0004_auto_20200505_2336.py diff --git a/chat_box/asgi.py b/chat_box/asgi.py new file mode 100644 index 0000000..6044bc8 --- /dev/null +++ b/chat_box/asgi.py @@ -0,0 +1,12 @@ +""" +ASGI entrypoint. Configures Django and then runs the application +defined in the ASGI_APPLICATION setting. +""" + +import os +import django +from channels.routing import get_default_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dmoj.settings") +django.setup() +application = get_default_application() diff --git a/chat_box/consumers.py b/chat_box/consumers.py index 1588053..de3db27 100644 --- a/chat_box/consumers.py +++ b/chat_box/consumers.py @@ -33,6 +33,7 @@ class ChatConsumer(AsyncWebsocketConsumer): async def receive(self, text_data): text_data_json = json.loads(text_data) message = text_data_json['message'] + time = save_data_and_get_time(message) message['time'] = format_time(time) diff --git a/chat_box/migrations/0002_message_hidden.py b/chat_box/migrations/0002_message_hidden.py new file mode 100644 index 0000000..23c02da --- /dev/null +++ b/chat_box/migrations/0002_message_hidden.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.12 on 2020-05-05 15:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_box', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='message', + name='hidden', + field=models.BooleanField(default=False, verbose_name='is hidden'), + ), + ] diff --git a/chat_box/migrations/0003_auto_20200505_2306.py b/chat_box/migrations/0003_auto_20200505_2306.py new file mode 100644 index 0000000..28efdb9 --- /dev/null +++ b/chat_box/migrations/0003_auto_20200505_2306.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.12 on 2020-05-05 16:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_box', '0002_message_hidden'), + ] + + operations = [ + migrations.AlterField( + model_name='message', + name='hidden', + field=models.BooleanField(default=True, verbose_name='is hidden'), + ), + ] diff --git a/chat_box/migrations/0004_auto_20200505_2336.py b/chat_box/migrations/0004_auto_20200505_2336.py new file mode 100644 index 0000000..3ecc44c --- /dev/null +++ b/chat_box/migrations/0004_auto_20200505_2336.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.12 on 2020-05-05 16:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_box', '0003_auto_20200505_2306'), + ] + + operations = [ + migrations.AlterField( + model_name='message', + name='hidden', + field=models.BooleanField(default=False, verbose_name='is hidden'), + ), + ] diff --git a/chat_box/views.py b/chat_box/views.py index 2ba3779..8640b09 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -11,7 +11,8 @@ import json def format_time(time): - return time.strftime('%H:%M %p %d-%m-%Y') + return time + #return time.strftime('%H:%M %p %d-%m-%Y') def format_messages(messages): @@ -74,4 +75,4 @@ def delete_message(request): return JsonResponse(ret) - return JsonResponse(ret) \ No newline at end of file + return JsonResponse(ret)