Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_chat.py @ 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 |
parents | 62a99c214b57 |
children | f607349a01a4 |
comparison
equal
deleted
inserted
replaced
2032:d941fa9954f4 | 2033:e3f1bd9dd009 |
---|---|
23 from sat.core import exceptions | 23 from sat.core import exceptions |
24 from sat_frontends.quick_frontend import quick_widgets | 24 from sat_frontends.quick_frontend import quick_widgets |
25 from sat_frontends.quick_frontend.constants import Const as C | 25 from sat_frontends.quick_frontend.constants import Const as C |
26 from collections import OrderedDict | 26 from collections import OrderedDict |
27 from sat_frontends.tools import jid | 27 from sat_frontends.tools import jid |
28 import locale | |
29 import time | 28 import time |
29 try: | |
30 from locale import getlocale | |
31 except ImportError: | |
32 # FIXME: pyjamas workaround | |
33 getlocale = lambda x: (None, 'utf-8') | |
34 | |
30 | 35 |
31 ROOM_USER_JOINED = 'ROOM_USER_JOINED' | 36 ROOM_USER_JOINED = 'ROOM_USER_JOINED' |
32 ROOM_USER_LEFT = 'ROOM_USER_LEFT' | 37 ROOM_USER_LEFT = 'ROOM_USER_LEFT' |
33 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT) | 38 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT) |
34 | 39 |
105 def time_text(self): | 110 def time_text(self): |
106 """Return timestamp in a nicely formatted way""" | 111 """Return timestamp in a nicely formatted way""" |
107 # if the message was sent before today, we print the full date | 112 # if the message was sent before today, we print the full date |
108 timestamp = time.localtime(self.timestamp) | 113 timestamp = time.localtime(self.timestamp) |
109 time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M" | 114 time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M" |
110 return time.strftime(time_format, timestamp).decode(locale.getlocale()[1]) | 115 return time.strftime(time_format, timestamp).decode(getlocale()[1]) |
111 | 116 |
112 def getNick(self, entity): | 117 def getNick(self, entity): |
113 """Return nick of an entity when possible""" | 118 """Return nick of an entity when possible""" |
114 contact_list = self.host.contact_lists[self.profile] | 119 contact_list = self.host.contact_lists[self.profile] |
115 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED: | 120 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED: |
199 if occupants is not None: | 204 if occupants is not None: |
200 raise exceptions.InternalError(u"only group chat can have occupants") | 205 raise exceptions.InternalError(u"only group chat can have occupants") |
201 self.messages = OrderedDict() # key: uid, value: Message instance | 206 self.messages = OrderedDict() # key: uid, value: Message instance |
202 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame | 207 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame |
203 self.subject = subject | 208 self.subject = subject |
204 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time | 209 lt = time.localtime() |
210 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 | |
205 | 211 |
206 def postInit(self): | 212 def postInit(self): |
207 """Method to be called by frontend after widget is initialised | 213 """Method to be called by frontend after widget is initialised |
208 | 214 |
209 handle the display of history and subject | 215 handle the display of history and subject |