2020-03-19 05:13:55 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2020-01-27 20:37:52 +00:00
|
|
|
from django.utils.translation import gettext as _
|
2020-03-16 02:23:14 +00:00
|
|
|
from django.views.generic import ListView
|
2020-03-19 05:13:55 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils import timezone
|
|
|
|
|
2020-01-27 20:37:52 +00:00
|
|
|
|
2020-03-16 02:23:14 +00:00
|
|
|
from .models import Message
|
2020-01-27 20:37:52 +00:00
|
|
|
|
2020-03-16 02:23:14 +00:00
|
|
|
|
|
|
|
class ChatView(ListView):
|
|
|
|
model = Message
|
2020-03-19 05:13:55 +00:00
|
|
|
context_object_name = 'messages'
|
2020-03-16 02:23:14 +00:00
|
|
|
template_name = 'chat/chat.html'
|
2020-03-19 05:13:55 +00:00
|
|
|
title = _('Chat Box')
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(ChatView, self).get_context_data(**kwargs)
|
|
|
|
context['title'] = self.title
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def send(request):
|
|
|
|
new_message = Message(body=request.POST['message'],
|
|
|
|
author=request.profile,
|
|
|
|
time=timezone.now())
|
|
|
|
new_message.save()
|
|
|
|
return HttpResponseRedirect(reverse('chat'))
|