Skip to content

Commit

Permalink
_COLUMN_FIELD_MAP
Browse files Browse the repository at this point in the history
  • Loading branch information
timmartin19 committed Jun 30, 2015
1 parent b2843f3 commit f32efc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.0.0b2 (unreleased)
====================

- Nothing changed yet.
- Added _COLUMN_FIELD_MAP for determining python type. Transparent change.


1.0.0b1 (2015-06-29)
Expand Down
29 changes: 17 additions & 12 deletions ripozo_sqlalchemy/alchemymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@

_logger = logging.getLogger(__name__)

_COLUMN_FIELD_MAP = {
six.text_type: StringField,
six.binary_type: StringField,
int: IntegerField,
float: FloatField,
Decimal: FloatField,
datetime: DateTimeField,
date: DateTimeField,
timedelta: DateTimeField,
time: DateTimeField,
bool: BooleanField,
}


def db_access_point(func):
"""
Expand Down Expand Up @@ -108,18 +121,10 @@ def get_field_type(cls, name):
:rtype: ripozo.viewsets.fields.base.BaseField
"""
python_type = cls._get_field_python_type(cls.model, name)
if python_type in (six.text_type, six.binary_type):
return StringField(name)
elif python_type is int:
return IntegerField(name)
elif python_type in (float, Decimal,):
return FloatField(name)
elif python_type in (datetime, date, timedelta, time):
return DateTimeField(name)
elif python_type is bool:
return BooleanField(name)
else:
return BaseField(name)
if python_type in _COLUMN_FIELD_MAP:
field_class = _COLUMN_FIELD_MAP[python_type]
return field_class(name)
return BaseField(name)

@db_access_point
def create(self, session, values, *args, **kwargs):
Expand Down

0 comments on commit f32efc9

Please sign in to comment.