Commits

Matthew Schinckel  committed 9a6a403 Merge

Merged in fcurella/django-timedelta-field/py3k (pull request #9)

added py3k support.

  • Participants
  • Parent commits 7b75f00, 329d2cc

Comments (0)

Files changed (4)

         "timedelta",
         "timedelta.templatetags",
     ],
+    install_requires = [
+        "six",
+    ],
     package_data = {'timedelta': ['VERSION']},
     classifiers = [
         'Programming Language :: Python',

File timedelta/fields.py

 
 from collections import defaultdict
 import datetime
+import six
 
 from .helpers import parse
 from .forms import TimedeltaFormField
     def get_prep_value(self, value):
         if self.null and value == "":
             return None
-        if (value is None) or isinstance(value, (str, unicode)):
+        if (value is None) or isinstance(value, six.string_types):
             return value
         return str(value).replace(',', '')
         

File timedelta/helpers.py

 import datetime
 from decimal import Decimal
 
+import six
+
 def nice_repr(timedelta, display="long", sep=", "):
     """
     Turns a datetime.timedelta object into a nice string repr.
     # and from serialization
     d = re.match(r'^((?P<days>\d+) days?,? )?(?P<hours>\d+):'
                  r'(?P<minutes>\d+)(:(?P<seconds>\d+(\.\d+)?))?$',
-                 unicode(string))
+                 six.text_type(string))
     if d: 
         d = d.groupdict(0)
     else:
                      r'((?P<hours>((\d*\.\d+)|\d+))\W*h(ou)?(r(s)?)?(,)?\W*)?'
                      r'((?P<minutes>((\d*\.\d+)|\d+))\W*m(in(ute)?(s)?)?(,)?\W*)?'
                      r'((?P<seconds>((\d*\.\d+)|\d+))\W*s(ec(ond)?(s)?)?)?\W*$',
-                     unicode(string))
+                     six.text_type(string))
         if not d:
             raise TypeError("'%s' is not a valid time interval" % string)
         d = d.groupdict(0)

File timedelta/widgets.py

 from django import forms
 import datetime
+import six
 
 from .helpers import nice_repr, parse
 
     def render(self, name, value, attrs=None):
         if value is None:
             value = ""
-        elif isinstance(value, (str, unicode)):
+        elif isinstance(value, six.string_types):
             pass
         else:
             if isinstance(value, int):