]> git.parisson.com Git - django-postman.git/commitdiff
Resolve a PendingDeprecationWarning (in relation with Pull Request 8)
authorPatrick Samson <pk.samson@gmail.com>
Wed, 6 Feb 2013 21:51:17 +0000 (22:51 +0100)
committerPatrick Samson <pk.samson@gmail.com>
Wed, 6 Feb 2013 21:51:17 +0000 (22:51 +0100)
CHANGELOG
postman/future_1_4.py [new file with mode: 0644]
postman/models.py
postman/tests.py

index d5b4c27b908c66dd451eac57acd5c2da3657fdfb..53a2d70810494794b45797e6f61d9eba27d97a1c 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,10 @@
 Django Postman changelog
 ========================
 
+Version 2.1.1, December 2012
+----------------------------
+* Fix issue #21, a missing unicode/str encoding migration
+
 Version 2.1.0, December 2012
 ----------------------------
 * Make the app compatible with the new 'Custom Auth Model' feature of Django 1.5
diff --git a/postman/future_1_4.py b/postman/future_1_4.py
new file mode 100644 (file)
index 0000000..6b360ac
--- /dev/null
@@ -0,0 +1,23 @@
+"""
+A forwards compatibility module.
+
+Implements some features of Django 1.4 when the application is run with a lower version of Django:
+- text truncating
+"""
+
+from __future__ import unicode_literals
+
+from django.utils.functional import allow_lazy
+from django.utils.text import truncate_words
+
+class Truncator(object):
+    "A simplified version of django.utils.text.Truncator"
+    def __init__(self, text):
+        self.text = text
+
+    def words(self, num):
+        s = truncate_words(self.text, num)
+        if s.endswith(' ...'):
+            s = s.replace(' ...', '...')
+        return s
+    words = allow_lazy(words)
index e43036cdfb9e6496268278b4c3f354ad5b3a89d7..9da2e282c9033a5132f141c200249c508016ab6e 100644 (file)
@@ -8,7 +8,10 @@ except ImportError:
     from postman.future_1_5 import get_user_model
 from django.core.exceptions import ValidationError
 from django.db import models
-from django.utils.text import truncate_words
+try:
+    from django.utils.text import Truncator  # Django 1.4
+except ImportError:
+    from postman.future_1_4 import Truncator
 from django.utils.translation import ugettext, ugettext_lazy as _
 try:
     from django.utils.timezone import now  # Django 1.4 aware datetimes
@@ -262,7 +265,7 @@ class Message(models.Model):
         ordering = ['-sent_at', '-id']
 
     def __unicode__(self):
-        return "{0}>{1}:{2}".format(self.obfuscated_sender, self.obfuscated_recipient, truncate_words(self.subject,5))
+        return "{0}>{1}:{2}".format(self.obfuscated_sender, self.obfuscated_recipient, Truncator(self.subject).words(5))
 
     @models.permalink
     def get_absolute_url(self):
index 7d49de649c34edee42c9f4200e6a80d37cadb901..1251b24cc073763ad8715ce3c52dd5f48c703e05 100644 (file)
@@ -1094,6 +1094,14 @@ class MessageTest(BaseTest):
         self.check_parties(m, s=self.user1, email=self.email              )
         self.check_parties(m,               email=self.email, r=self.user2)
 
+    def test_representation(self):
+        "Test the message representation as text."
+        m = Message(sender=self.user1, recipient=self.user2)
+        m.subject = 'one two three four last'
+        self.assertEqual(str(m), 'foo>bar:one two three four last')
+        m.subject = 'one two three four last over'
+        self.assertEqual(str(m), 'foo>bar:one two three four last...')
+
     def test_status(self):
         "Test status."
         m = Message.objects.create(subject='s')