2020-01-27 14:37:52 -06:00
|
|
|
from django.utils.translation import gettext as _
|
2020-03-15 20:23:14 -06:00
|
|
|
from django.views.generic import ListView
|
2020-01-27 14:37:52 -06:00
|
|
|
|
2020-03-15 20:23:14 -06:00
|
|
|
from .models import Message
|
2020-01-27 14:37:52 -06:00
|
|
|
|
2020-03-15 20:23:14 -06:00
|
|
|
|
2020-03-20 15:34:33 -06:00
|
|
|
def format_time(time):
|
|
|
|
return time.strftime('%H:%M %p %d-%m-%Y')
|
|
|
|
|
|
|
|
|
2020-03-15 20:23:14 -06:00
|
|
|
class ChatView(ListView):
|
|
|
|
model = Message
|
2020-03-19 16:51:56 -06:00
|
|
|
context_object_name = 'message'
|
2020-03-15 20:23:14 -06:00
|
|
|
template_name = 'chat/chat.html'
|
2020-03-18 23:13:55 -06:00
|
|
|
title = _('Chat Box')
|
2020-03-20 15:34:33 -06:00
|
|
|
paginate_by = 50
|
2020-03-18 23:13:55 -06:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2020-03-19 16:51:56 -06:00
|
|
|
context = super().get_context_data(**kwargs)
|
2020-03-18 23:13:55 -06:00
|
|
|
context['title'] = self.title
|
2020-03-20 15:34:33 -06:00
|
|
|
|
|
|
|
for msg in context['message']:
|
|
|
|
msg.time = format_time(msg.time)
|
|
|
|
|
2020-03-18 23:13:55 -06:00
|
|
|
return context
|