Patrick Samson committed 18a1717

Resolve a PendingDeprecationWarning (in relation with Pull Request 5)

Comments (0)

Files changed (4)

 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


+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)


     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
+    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 _
     from django.utils.timezone import now  # Django 1.4 aware datetimes
         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))
     def get_absolute_url(self):
         self.check_parties(m, s=self.user1,              )
         self.check_parties(m,     , 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')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.