From 08e3a7b8369e940677823967de92c8e86a09b03a Mon Sep 17 00:00:00 2001 From: richardbarran Date: Sat, 1 Aug 2009 22:40:59 +0000 Subject: [PATCH] Allow datetime format in the messages to be customised. git-svn-id: http://django-jqchat.googlecode.com/svn/trunk@10 8369a704-5b4a-11de-992f-fdd7e25b9163 --- jqchat/templates/jqchat/chat_payload.json | 2 +- jqchat/tests.py | 7 ++++++- jqchat/views.py | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/jqchat/templates/jqchat/chat_payload.json b/jqchat/templates/jqchat/chat_payload.json index e7d4af5..13add89 100644 --- a/jqchat/templates/jqchat/chat_payload.json +++ b/jqchat/templates/jqchat/chat_payload.json @@ -5,7 +5,7 @@ {% if NewDescription %} "description": {{ NewDescription }},{% endif %} "messages": [ {% for row in NewMessages %}{# The localtime filter is part of Django timezone and adjusts a datetime to the given timezone #} - { "text": "{{ row.created|localtime:user_tz|time:"H:i:s" }} {{ row.text|safe }}"}{% if not forloop.last %},{% endif %} + { "text": "{{ row.created|localtime:user_tz|date:TimeDisplayFormat }} {{ row.text|safe }}"}{% if not forloop.last %},{% endif %} {% endfor %} ] {{ CustomPayload|default:""|safe }} diff --git a/jqchat/tests.py b/jqchat/tests.py index 0e5795d..11e081b 100644 --- a/jqchat/tests.py +++ b/jqchat/tests.py @@ -7,10 +7,15 @@ Unit tests for jqchat application. from django.test import TestCase from django.test.client import Client from django.contrib.auth.models import User +#from django.conf import settings import simplejson from models import Room, Message +# During testing we want to use default settings. +import views +views.DATE_FORMAT = "H:i:s" + class ChatPageTest(TestCase): """Test the chat test page.""" @@ -49,7 +54,7 @@ class AJAXGetTest(TestCase): def setUp(self): self.client = Client() self.client.login(username='mickey', password='test') - + def test_get_messages(self): """Get the latest messages.""" diff --git a/jqchat/views.py b/jqchat/views.py index 32f627a..167c9cb 100644 --- a/jqchat/views.py +++ b/jqchat/views.py @@ -8,6 +8,12 @@ from models import Room, Message import time +# The format of the date displayed in the chat window can be customised. +try: + DATE_FORMAT = settings.JQCHAT_DATE_FORMAT +except: + # Use default format. + DATE_FORMAT = "H:i:s" #------------------------------------------------------------------------------ @login_required @@ -114,6 +120,7 @@ class Ajax(object): 'NewDescription': NewDescription, 'user_tz': user_tz, 'CustomPayload': CustomPayload, + 'TimeDisplayFormat': DATE_FORMAT }, context_instance=RequestContext(self.request)) response['Content-Type'] = 'text/plain; charset=utf-8' -- 2.39.5