Skip to content

Commit

Permalink
Merge pull request #43 from ambitioninc/develop
Browse files Browse the repository at this point in the history
2.2.0
  • Loading branch information
somewes committed Sep 19, 2017
2 parents 566f700 + fd46fed commit 87bb675
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
env:
global:
- DB=postgres
matrix:
- DJANGO=">=1.8,<1.9"
- DJANGO=">=1.9,<1.10"
- DJANGO=">=1.10,<1.11"
- DJANGO=">=1.11,<2.0"
install:
- pip install -q coverage flake8 psycopg2 Django$DJANGO django-nose>=1.4
before_script:
Expand Down
29 changes: 26 additions & 3 deletions localized_recurrence/fields.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
from datetime import timedelta
import re

from django.db.models import SubfieldBase
from django.db.models.fields import IntegerField
import six
from six import with_metaclass


class DurationField(with_metaclass(SubfieldBase, IntegerField)):
class CastOnAssignDescriptor(object):
"""
A property descriptor which ensures that `field.to_python()` is called on _every_ assignment to the field.
This used to be provided by the `django.db.models.subclassing.Creator` class, which in turn
was used by the deprecated-in-Django-1.10 `SubfieldBase` class, hence the reimplementation here.
https://stackoverflow.com/questions/39392343/
how-do-i-make-a-custom-model-field-call-to-python-when-the-field-is-accessed-imm
"""

def __init__(self, field):
self.field = field

def __get__(self, obj, type=None): # pragma: no cover
if obj is None:
return self
return obj.__dict__[self.field.name]

def __set__(self, obj, value): # pragma: no cover
obj.__dict__[self.field.name] = self.field.to_python(value)


class DurationField(IntegerField):
"""A field to store durations of time with accuracy to the second.
A Duration Field will automatically convert between python
Expand Down Expand Up @@ -43,6 +62,10 @@ def __init__(self, *args, **kwargs):
"""Call out to the super. Makes docs cleaner."""
return super(DurationField, self).__init__(*args, **kwargs)

def contribute_to_class(self, cls, name):
super(DurationField, self).contribute_to_class(cls, name)
setattr(cls, name, CastOnAssignDescriptor(self))

def to_python(self, value):
"""Convert a stored duration into a python datetime.timedelta object.
Expand Down
2 changes: 1 addition & 1 deletion localized_recurrence/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.0'
__version__ = '2.2.0'
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ def get_version():
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
install_requires=[
'Django>=1.8,<1.10',
'django-timezone-field<2.0',
'fleming>=0.4.4',
'Django>=1.9',
'django-timezone-field>=2.0',
'fleming>=0.4.6',
'python-dateutil',
'pytz',
],
Expand Down

0 comments on commit 87bb675

Please sign in to comment.