Commits

Matthew Schinckel committed d05efa5

Convert SMS to non-unicode characters.
Also contains commented out code to allow for sending
of unicode messages, for later.

  • Participants
  • Parent commits b49897b

Comments (0)

Files changed (2)

File sms/models/gateway.py

 from django.utils.translation import ugettext as _
 import logging
 import re
+import unicodedata
 
 from django.conf import settings
 
             raw_data[self.recipient_keyword] = message.recipient_number
         else:
             raw_data[self.recipient_keyword] = message.recipient.mobile
-        raw_data[self.content_keyword] = message.content
+        # We need to see if this message needs to be sent as unicode.
+        # Could be smart and try to see if it is a short enough message.
+        # Or look for a preference that says if this person may send unicode
+        # messages?
+        # try:
+        #     str(message.content)
+        # except UnicodeEncodeError:
+        #     raw_data[self.content_keyword] = "".join(["%04x" % ord(x) for x in message.content])
+        #     raw_data["unicode"] = 1
+        # else:
+        raw_data[self.content_keyword] = unicodedata.normalize('NFKD', message.content).encode('ascii', 'ignore')
         if self.uuid_keyword:
             assert message.uuid, "Message must have a valid UUID. Has it been saved?"
             raw_data[self.uuid_keyword] = message.uuid

File sms/models/message.py

     
     @property
     def length(self):
+        """Unicode messages are limited to 70 chars/message segment."""
+        # try:
+        #     return len(str(self.content)) / 160 + 1
+        # except UnicodeEncodeError:
+        #     return len(self.content) / 70 + 1
         return len(self.content) / 160 + 1
     
     @property