Make sure new media has a new uuid added on
authorJessica Tallon <xray7224@googlemail.com>
Wed, 14 Aug 2013 15:16:49 +0000 (16:16 +0100)
committerJessica Tallon <jessica@megworld.co.uk>
Tue, 22 Jul 2014 22:13:14 +0000 (23:13 +0100)
mediagoblin/db/migrations.py
mediagoblin/db/models.py

index 85b1edededaf132d2ef437bf7456360f12b1371d..242d72d9b2ea114561502f7a530415a2b0013574 100644 (file)
@@ -25,12 +25,11 @@ from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.sql import and_
 from migrate.changeset.constraint import UniqueConstraint
 
-
 from mediagoblin.db.extratypes import JSONEncoded, MutationDict
 from mediagoblin.db.migration_tools import (
     RegisterMigration, inspect_table, replace_table_hack)
-from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User, 
-        Privilege)
+from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User,
+        create_uuid, Privilege)
 from mediagoblin.db.extratypes import JSONEncoded, MutationDict
 
 MIGRATIONS = {}
@@ -659,8 +658,8 @@ def create_moderation_tables(db):
     # admin, an active user or an inactive user ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     for admin_user in admin_users_ids:
         admin_user_id = admin_user['id']
-        for privilege_id in [admin_privilege_id, uploader_privilege_id, 
-                            reporter_privilege_id, commenter_privilege_id, 
+        for privilege_id in [admin_privilege_id, uploader_privilege_id,
+                            reporter_privilege_id, commenter_privilege_id,
                             active_privilege_id]:
             db.execute(user_privilege_assoc.insert().values(
                 core__privilege_id=admin_user_id,
@@ -668,7 +667,7 @@ def create_moderation_tables(db):
 
     for active_user in active_users_ids:
         active_user_id = active_user['id']
-        for privilege_id in [uploader_privilege_id, reporter_privilege_id, 
+        for privilege_id in [uploader_privilege_id, reporter_privilege_id,
                             commenter_privilege_id, active_privilege_id]:
             db.execute(user_privilege_assoc.insert().values(
                 core__privilege_id=active_user_id,
@@ -676,7 +675,7 @@ def create_moderation_tables(db):
 
     for inactive_user in inactive_users_ids:
         inactive_user_id = inactive_user['id']
-        for privilege_id in [uploader_privilege_id, reporter_privilege_id, 
+        for privilege_id in [uploader_privilege_id, reporter_privilege_id,
                              commenter_privilege_id]:
             db.execute(user_privilege_assoc.insert().values(
                 core__privilege_id=inactive_user_id,
index 02392792f98423af69fdbe55fcfab2817c01123d..e1b37aa000700ca86271a047924e20c2ff1cd1c5 100644 (file)
@@ -237,6 +237,10 @@ class NonceTimestamp(Base):
     timestamp = Column(DateTime, nullable=False, primary_key=True)
 
 
+def create_uuid():
+    """ Creates a new uuid which is suitable for use in a URL """
+    return base64.urlsafe_b64encode(uuid.uuid4().bytes).strip("=")
+
 class MediaEntry(Base, MediaEntryMixin):
     """
     TODO: Consider fetching the media_files using join