aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2012-01-28 00:33:23 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2012-01-29 23:02:40 +0100
commit51fba99125c63a6a5e68480e7d4b1ea08f33a4db (patch)
tree2cc45e297cadab8d9c570d1ba45df1e6d9a3dd1a
parent8a9aa0758393336fb751c6f77a3d4feaa1903c06 (diff)
downloadmediagoblin-51fba99125c63a6a5e68480e7d4b1ea08f33a4db.tar.lz
mediagoblin-51fba99125c63a6a5e68480e7d4b1ea08f33a4db.tar.xz
mediagoblin-51fba99125c63a6a5e68480e7d4b1ea08f33a4db.zip
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
-rw-r--r--mediagoblin/db/sql/extratypes.py6
-rw-r--r--mediagoblin/db/sql/models.py9
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