Skip to content
7 changes: 3 additions & 4 deletions baph/auth/models/oauth_/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
orm = ORM.get()
Base = orm.Base

MAX_KEY_LEN = 255
MAX_KEY_LEN = 32
MAX_SECRET_LEN = 255
KEY_LEN = 32
SECRET_LEN = 32
MAX_NONCE_LEN = 33
UNIQUE_KEY = getattr(settings, 'BAPH_UNIQUE_OAUTH_KEYS', True)


Expand Down Expand Up @@ -43,4 +42,4 @@ class OAuthNonce(Base):
timestamp = Column(DateTime, nullable=False, index=True)
token_key = Column(String(32))
consumer_key = Column(String(MAX_KEY_LEN), nullable=False)
key = Column(String(255), nullable=False)
key = Column(String(MAX_NONCE_LEN), nullable=False)
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