diff --git a/baph/auth/models/oauth_/__init__.py b/baph/auth/models/oauth_/__init__.py index b39a657..06d06b6 100644 --- a/baph/auth/models/oauth_/__init__.py +++ b/baph/auth/models/oauth_/__init__.py @@ -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) @@ -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) diff --git a/baph/db/types.py b/baph/db/types.py index e797a27..5d8288b 100644 --- a/baph/db/types.py +++ b/baph/db/types.py @@ -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 @@ -75,13 +76,13 @@ 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): @@ -89,17 +90,24 @@ def process_result_value(self, value, dialect): 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): @@ -128,6 +136,7 @@ def __delitem__(self, key): dict.__delitem__(self, key) self.changed() + class MutableList(Mutable, list): @classmethod def coerce(cls, key, value): @@ -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 diff --git a/baph/forms/forms.py b/baph/forms/forms.py index ea661f3..d5dd723 100644 --- a/baph/forms/forms.py +++ b/baph/forms/forms.py @@ -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()