diff sat_frontends/quick_frontend/quick_chat.py @ 2847:c055a3a4ecb0

quick frontend(chat): display a useful message with __unicode__ and __str__
author Goffi <goffi@goffi.org>
date Sun, 10 Mar 2019 18:02:54 +0100
parents 76f714b12d21
children c2858e63cd82
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_chat.py	Sun Mar 10 18:02:42 2019 +0100
+++ b/sat_frontends/quick_frontend/quick_chat.py	Sun Mar 10 18:02:54 2019 +0100
@@ -85,6 +85,16 @@
         self.handleMe()
         self.widgets = set()  # widgets linked to this message
 
+    def __unicode__(self):
+        return u"Message<{mess_type}>  [{time}]{nick}> {message}".format(
+            mess_type=self.type,
+            time=self.time_text,
+            nick=self.nick,
+            message=self.main_message)
+
+    def __str__(self):
+        return self.__unicode__().encode('utf-8', 'ignore')
+
     @property
     def host(self):
         return self.parent.host
@@ -328,7 +338,7 @@
 
     ## Widget management ##
 
-    def __str__(self):
+    def __unicode__(self):
         return u"Chat Widget [target: {}, type: {}, profile: {}]".format(
             self.target, self.type, self.profile
         )