Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions example_project/manage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
import os
import sys

if __name__ == "__main__":
execute_manager(settings)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
2 changes: 1 addition & 1 deletion humandt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1'
__version__ = '0.2'
11 changes: 5 additions & 6 deletions humandt/fields.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import datetime
from django.core import validators
from django.core.exceptions import ValidationError
from django.forms.fields import DateField, TimeField, DateTimeField
from parser import parse
from .parser import parse

class HumanDateTimeField(DateTimeField):
def to_python(self, value):
if value in validators.EMPTY_VALUES:
return None
try:
return parse(value)
except Exception, e:
except Exception as e:
raise ValidationError(self.error_messages['invalid'])

class HumanTimeField(TimeField):
Expand All @@ -19,7 +18,7 @@ def to_python(self, value):
return None
try:
return parse(value).time()
except Exception, e:
except Exception as e:
raise ValidationError(self.error_messages['invalid'])

class HumanDateField(DateField):
Expand All @@ -28,5 +27,5 @@ def to_python(self, value):
return None
try:
return parse(value).date()
except Exception, e:
raise ValidationError(self.error_messages['invalid'])
except Exception as e:
raise ValidationError(self.error_messages['invalid'])
5 changes: 2 additions & 3 deletions humandt/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.test import TestCase
from parser import parse
from unittest import TestCase
from .parser import parse
from datetime import datetime

class HumanTests(TestCase):
Expand All @@ -10,4 +10,3 @@ def test_tomorrow(self):
t = parse('tomorrow 4PM')
self.assertEqual(t.day, self.now.day+1)
self.assertEqual(t.hour, 16)

33 changes: 17 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
from humandt import __version__

setup(name='django-human-datetime',
version=__version__,
description='Uses the parsedatetime package to parse human readable date/time expressions into Django fields',
long_description=open('README.rst').read(),
author='Justin Quick',
author_email='justquick@gmail.com',
url='http://github.com/justquick/django-human-datetime',
packages=['humandt'],
requires=['parsedatetime','pytz',],
classifiers=['Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Utilities'],
)
version=__version__,
description='Uses the parsedatetime package to parse human readable date/time expressions into Django fields',
long_description=open('README.rst').read(),
author='Justin Quick',
author_email='justquick@gmail.com',
url='http://github.com/justquick/django-human-datetime',
packages=['humandt'],
install_requires=['django', 'parsedatetime','pytz',],
classifiers=['Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Utilities'],
)