From 51fba99125c63a6a5e68480e7d4b1ea08f33a4db Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 28 Jan 2012 00:33:23 +0100 Subject: [PATCH] Some small SQL model improvements - Add default for User.email_verified - Add default for MediaEntry.state - Let PathTupleWithSlashes store [] as "NULL", but not handling the reverse properly yet! - Add _id alias field to MediaEntry and MediaComment --- mediagoblin/db/sql/extratypes.py | 6 ++++-- mediagoblin/db/sql/models.py | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mediagoblin/db/sql/extratypes.py b/mediagoblin/db/sql/extratypes.py index 33c9edee..21c806ec 100644 --- a/mediagoblin/db/sql/extratypes.py +++ b/mediagoblin/db/sql/extratypes.py @@ -25,8 +25,10 @@ class PathTupleWithSlashes(TypeDecorator): def process_bind_param(self, value, dialect): if value is not None: - assert len(value), "Does not support empty lists" - value = '/'.join(value) + if len(value) == 0: + value = None + else: + value = '/'.join(value) return value def process_result_value(self, value, dialect): diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 9abd8ec7..7ec05876 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -50,7 +50,7 @@ class User(Base, UserMixin): email = Column(Unicode, nullable=False) created = Column(DateTime, nullable=False, default=datetime.datetime.now) pw_hash = Column(Unicode, nullable=False) - email_verified = Column(Boolean) + email_verified = Column(Boolean, default=False) status = Column(Unicode, default=u"needs_email_verification", nullable=False) verification_key = Column(Unicode) is_admin = Column(Boolean, default=False, nullable=False) @@ -77,7 +77,8 @@ class MediaEntry(Base, MediaEntryMixin): description = Column(UnicodeText) # ?? description_html = Column(UnicodeText) # ?? media_type = Column(Unicode, nullable=False) - state = Column(Unicode, nullable=False) # or use sqlalchemy.types.Enum? + state = Column(Unicode, default=u'unprocessed', nullable=False) + # or use sqlalchemy.types.Enum? license = Column(Unicode) fail_error = Column(Unicode) @@ -113,6 +114,8 @@ class MediaEntry(Base, MediaEntryMixin): # attachment_files # fail_error + _id = SimpleFieldAlias("id") + def get_comments(self, ascending=False): order_col = MediaComment.created if not ascending: @@ -215,6 +218,8 @@ class MediaComment(Base): get_author = relationship(User) + _id = SimpleFieldAlias("id") + def show_table_init(): from sqlalchemy import create_engine -- 2.25.1