# HG changeset patch # User Goffi # Date 1470697882 -7200 # Node ID e3f1bd9dd00953168951fe64647ebee62493514c # Parent d941fa9954f453a8d98aba608c82ce6c22827cb8 quick frontend (chat): added a getlocale method and changed self.day_change calculation for pyjamas compatibility diff -r d941fa9954f4 -r e3f1bd9dd009 frontends/src/quick_frontend/quick_chat.py --- 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