Skip to content

Commit

Permalink
python 2/3 string transformation with six, update requirements, code …
Browse files Browse the repository at this point in the history
…enhancement
  • Loading branch information
Quard committed Nov 15, 2016
1 parent 0cdc5a7 commit 31ea850
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion classifier/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = (0, 2)
VERSION = (0, 2, 1)
21 changes: 14 additions & 7 deletions classifier/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import six
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.dateparse import parse_date, parse_datetime
Expand Down Expand Up @@ -80,31 +81,37 @@ def to_python(self, value):
cleaner = getattr(self, 'to_python_{}'.format(self.value_type))
return cleaner(value)

def to_python_int(self, value):
@staticmethod
def to_python_int(value):
return int(value)

def to_python_float(self, value):
@staticmethod
def to_python_float(value):
return float(value)

def to_python_str(self, value):
return str(value) # PYTHON 3
@staticmethod
def to_python_str(value):
return six.text_type(value)

def to_python_bool(self, value):
@staticmethod
def to_python_bool(value):
if value.lower() in ['on', 'yes', 'true']:
return True
elif value:
raise ValueError('Can\'t convert "{}" to boolean'.format(value))

return False

def to_python_date(self, value):
@staticmethod
def to_python_date(value):
date = parse_date(value)
if value and not date:
raise ValueError('Can\'t convert "{}" to date'.format(value))

return date

def to_python_datetime(self, value):
@staticmethod
def to_python_datetime(value):
datetime = parse_datetime(value)
if value and not datetime:
raise ValueError('Can\'t convert "{}" to datetime'.format(value))
Expand Down
2 changes: 1 addition & 1 deletion requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Django==1.10
Django<=1.11
-r maintainer.txt
2 changes: 1 addition & 1 deletion requirements/maintainer.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Sphinx==1.3.6
Sphinx==1.4.8

0 comments on commit 31ea850

Please sign in to comment.