Skip to content
Merged
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
18 changes: 16 additions & 2 deletions baph/db/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class Email(types.TypeDecorator):
impl = types.Unicode


class UUID(types.TypeDecorator):
'''Generic UUID column type for SQLAlchemy. Includes native support for
PostgreSQL and a MySQL-specific implementation, in addition to the
Expand Down Expand Up @@ -75,31 +76,38 @@ def process_result_value(self, value, dialect=None):
def is_mutable(self):
return False


class Json(types.TypeDecorator):
impl = types.Unicode

def process_bind_param(self, value, dialect):
if value is None:
return None
#return json.dumps(value)
return json.dumps(value)

def process_result_value(self, value, dialect):
if not value:
return None
return json.loads(value)


JsonType = Json


class JsonText(JsonType):
impl = types.UnicodeText

class List(JsonText):

class List(JsonText):
@property
def python_type(self):
return list


class ListVarchar(List):
impl = types.Unicode


# http://docs.sqlalchemy.org/en/latest/orm/extensions/mutable.html

class MutableDict(Mutable, dict):
Expand Down Expand Up @@ -128,6 +136,7 @@ def __delitem__(self, key):
dict.__delitem__(self, key)
self.changed()


class MutableList(Mutable, list):
@classmethod
def coerce(cls, key, value):
Expand Down Expand Up @@ -181,6 +190,11 @@ class Dict(JsonText):
def python_type(self):
return dict


class DictVarchar(Dict):
impl = types.Unicode


class TZAwareDateTime(types.TypeDecorator):
impl = types.DateTime

Expand Down
4 changes: 3 additions & 1 deletion baph/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
Boolean: forms.BooleanField,
types.Json: fields.JsonField,
types.List: fields.ListField,
types.ListVarchar: fields.ListField,
types.Dict: fields.DictField,
types.DictVarchar: fields.DictField,
types.Email: forms.EmailField,
'collection': fields.MultiObjectField,
'object': fields.ObjectField,
}
}
ALL_FIELDS = '__all__'

orm = ORM.get()
Expand Down