changeset 2033:e3f1bd9dd009

quick frontend (chat): added a getlocale method and changed self.day_change calculation for pyjamas compatibility
author Goffi <goffi@goffi.org>
date Tue, 09 Aug 2016 01:11:22 +0200 (2016-08-08)
parents d941fa9954f4
children 3f745370a39a
files frontends/src/quick_frontend/quick_chat.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py	Tue Aug 09 01:10:09 2016 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Tue Aug 09 01:11:22 2016 +0200
@@ -25,8 +25,13 @@
 from sat_frontends.quick_frontend.constants import Const as C
 from collections import OrderedDict
 from sat_frontends.tools import jid
-import locale
 import time
+try:
+    from locale import getlocale
+except ImportError:
+    # FIXME: pyjamas workaround
+    getlocale = lambda x: (None, 'utf-8')
+
 
 ROOM_USER_JOINED = 'ROOM_USER_JOINED'
 ROOM_USER_LEFT = 'ROOM_USER_LEFT'
@@ -107,7 +112,7 @@
         # if the message was sent before today, we print the full date
         timestamp = time.localtime(self.timestamp)
         time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
-        return time.strftime(time_format, timestamp).decode(locale.getlocale()[1])
+        return time.strftime(time_format, timestamp).decode(getlocale()[1])
 
     def getNick(self, entity):
         """Return nick of an entity when possible"""
@@ -201,7 +206,8 @@
         self.messages = OrderedDict()  # key: uid, value: Message instance
         self.games = {}  # key=game name (unicode), value=instance of quick_games.RoomGame
         self.subject = subject
-        self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00  %Y"))  # struct_time of day changing time
+        lt = time.localtime()
+        self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst)  # struct_time of day changing time
 
     def postInit(self):
         """Method to be called by frontend after widget is initialised