1. Matthew Schinckel
  2. django-timedelta-field


Flavio Curella  committed 315ae00

added py3k support.

  • Participants
  • Parent commits 7751395
  • Branches py3k

Comments (0)

Files changed (6)

File setup.py

View file
  • Ignore whitespace
+    install_requires = [
+        "six",
+    ],
     package_data = {'timedelta': ['VERSION']},
     classifiers = [
         'Programming Language :: Python',

File timedelta/__init__.py

View file
  • Ignore whitespace
 __version__ = open(os.path.join(os.path.dirname(__file__), "VERSION")).read().strip()
-    from fields import TimedeltaField
-    from helpers import (
+    from .fields import TimedeltaField
+    from .helpers import (
         divide, multiply, modulo, 
         parse, nice_repr, 
         percentage, decimal_percentage,

File timedelta/fields.py

View file
  • Ignore whitespace
 from collections import defaultdict
 import datetime
+import six
-from helpers import parse
-from forms import TimedeltaFormField
+from .helpers import parse
+from .forms import TimedeltaFormField
 # TODO: Figure out why django admin thinks fields of this type have changed every time an object is saved.
     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/forms.py

View file
  • Ignore whitespace
 import datetime
 from collections import defaultdict
-from widgets import TimedeltaWidget
-from helpers import parse
+from .widgets import TimedeltaWidget
+from .helpers import parse
 class TimedeltaFormField(forms.Field):
     default_error_messages = {

File timedelta/helpers.py

View file
  • Ignore whitespace
 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+):'
-                 unicode(string))
+                 six.text_type(string))
     if d: 
         d = d.groupdict(0)
-                     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

View file
  • Ignore whitespace
 from django import forms
 import datetime
+import six
-from helpers import nice_repr, parse
+from .helpers import nice_repr, parse
 class TimedeltaWidget(forms.TextInput):
     def __init__(self, *args, **kwargs):
     def render(self, name, value, attrs=None):
         if value is None:
             value = ""
-        elif isinstance(value, (str, unicode)):
+        elif isinstance(value, six.string_types):
             if isinstance(value, int):