Commits

Tim Savage  committed 75f10d9 Draft Merge

Merge upstream changes

  • Participants
  • Parent commits 6082a18, 3b0ddb7

Comments (0)

Files changed (7)

 a4e391e1d1f80610b5a37bf4f6a3cc9930abd065 release-0.2.3b2
 fc357f5fec42d18d5d1b7a54ff110923ad52c8a7 release-0.2.4.beta1
 3f3fe00a9c1906f15b68ab15afbe1886f1d7f87e release-django-extras-0.2.5b1
+5f1e05191c1ed3cd87f80296992888781dffa020 django-extras-0.2.6b2

File django_extras/__init__.py

-VERSION = (0, 2, 5, 'beta', 1)
+VERSION = (0, 2, 6, 'beta', 2)
 
 def get_version():
     # Don't litter django_extras/__init__.py with all the get_version stuff.

File django_extras/db/models/fields/__init__.py

+#from django.conf import settings
 from django.core import exceptions
 from django.core.validators import MinValueValidator, MaxValueValidator
 from django.db import models
         ])
         super(LongitudeField, self).__init__(*args, **kwargs)
 
+
 # Register special admin widgets if admin is in use.
 #if 'django.contrib.admin' in settings.INSTALLED_APPS:
 #    from django.contrib.admin import options
-#    options.FORMFIELD_FOR_DBFIELD_DEFAULTS[ColorField] = { 'widget':  }
+#    from django_extras.forms.widgets import JQueryColorPicker
+#    options.FORMFIELD_FOR_DBFIELD_DEFAULTS[ColorField] = { 'widget': JQueryColorPicker }
 
 # Register fields with south.
 try:

File django_extras/templatetags/humanize_extras.py

+from django import template
+from django_extras.utils import humanize
+
+
+register = template.Library()
+
+
+@register.filter(is_safe=True)
+def describe_seconds(value):
+    """
+    Convert a seconds value into a human readable (ie week, day, hour) value.
+    :param value: integer value of the number of seconds.
+    :return: a string with the humanized value.
+    """
+    return humanize.describe_seconds(value)

File django_extras/tests/__init__.py

 from django_extras.tests.http.responses import *
 from django_extras.tests.middleware.timing import *
 from django_extras.tests.utils.cache import *
+from django_extras.tests.utils.humanize import *

File django_extras/tests/utils/humanize.py

+from django import test
+from django_extras.utils import humanize
+
+
+class HumanizeDescribeSecondsTestCase(test.TestCase):
+    def test_seconds(self):
+        self.assertEqual('12s', humanize.describe_seconds(12))
+
+    def test_minutes(self):
+        self.assertEqual('12m', humanize.describe_seconds(720))
+
+    def test_hours(self):
+        self.assertEqual('12h', humanize.describe_seconds(43200))
+
+    def test_days(self):
+        self.assertEqual('5d', humanize.describe_seconds(432000))
+
+    def test_weeks(self):
+        self.assertEqual('12w', humanize.describe_seconds(7257600))
+
+    def test_all_one(self):
+        self.assertEqual('1w 1d 1h 1m 1s', humanize.describe_seconds(694861))
+
+    def test_mix_it_up(self):
+        self.assertEqual('2w 3d 14h 42s', humanize.describe_seconds(1519242))

File django_extras/utils/humanize.py

+TIME_MAP = (
+    ('w', 604800),
+    ('d', 86400),
+    ('h', 3600),
+    ('m', 60),
+    ('s', 1)
+    )
+
+def describe_seconds(value):
+    """
+    Convert a seconds value into a human readable (ie week, day, hour) value.
+    :param value: integer value of the number of seconds.
+    :return: a string with the humanized value.
+    """
+    value_vector = []
+    for unit, factor in iter(TIME_MAP):
+        component, value = value / factor, value % factor
+        if component:
+            value_vector.append('%s%s' % (component, unit))
+    return ' '.join(value_vector)