"""
Create all the tables
"""
- metadata = MetaData(bind=db.bind)
- user_table = inspect_table(metadata, "core__users")
-
# Create tables needed
LocalUser_V0.__table__.create(db.bind)
RemoteUser_V0.__table__.create(db.bind)
db.commit()
+ metadata = MetaData(bind=db.bind)
+ user_table = inspect_table(metadata, "core__users")
+
# Create the fields
updated_column = Column(
"updated",
wants_notifications_column = user_table.columns["wants_notifications"]
wants_notifications_column.drop()
+ db.commit()
+
+@RegisterMigration(35, MIGRATIONS)
+def federation_media_entry(db):
+ metadata = MetaData(bind=db.bind)
+ media_entry_table = inspect_table(metadata, "core__media_entries")
+
+ # Add new fields
+ public_id_column = Column(
+ "public_id",
+ Unicode,
+ unique=True,
+ nullable=True
+ )
+ public_id_column.create(
+ media_entry_table,
+ unique_name="media_public_id"
+ )
+
+ remote_column = Column(
+ "remote",
+ Boolean,
+ default=False
+ )
+ remote_column.create(media_entry_table)
+
+ updated_column = Column(
+ "updated",
+ DateTime,
+ default=datetime.datetime.utcnow,
+ )
+ updated_column.create(media_entry_table)
+
+ # Data migration
+ for entry in db.execute(media_entry_table.select()):
+ db.execute(media_entry_table.update().values(
+ updated=entry.created,
+ remote=False
+ ))
db.commit()
media=self.slug_or_id,
**extra_args)
+ def get_public_id(self, request):
+ """ Returns the public_id of the MediaEntry
+
+ If the MediaEntry has no public ID one will be produced from the
+ current request.
+ """
+ if self.public_id is None:
+ self.public_id = request.urlgen(
+ "mediagoblin.api.object",
+ object_type=self.object_type,
+ id=self.id,
+ qualified=True
+ )
+ # We need to ensure this ID is reused once we've given it out.
+ self.save()
+
+ return self.public_id
+
+
@property
def thumb_url(self):
"""Return the thumbnail URL (for usage in templates)
__tablename__ = "core__media_entries"
id = Column(Integer, primary_key=True)
+ public_id = Column(Unicode, unique=True, nullable=True)
+ remote = Column(Boolean, default=False)
+
uploader = Column(Integer, ForeignKey(User.id), nullable=False, index=True)
title = Column(Unicode, nullable=False)
slug = Column(Unicode)
- created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow,
- index=True)
description = Column(UnicodeText) # ??
media_type = Column(Unicode, nullable=False)
state = Column(Unicode, default=u'unprocessed', nullable=False)
location = Column(Integer, ForeignKey("core__locations.id"))
get_location = relationship("Location", lazy="joined")
+ created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow,
+ index=True)
+ updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+
fail_error = Column(Unicode)
fail_metadata = Column(JSONEncoded)
def serialize(self, request, show_comments=True):
""" Unserialize MediaEntry to object """
- href = request.urlgen(
- "mediagoblin.api.object",
- object_type=self.object_type,
- id=self.id,
- qualified=True
- )
author = self.get_uploader
published = UTC.localize(self.created)
- updated = UTC.localize(self.created)
+ updated = UTC.localize(self.updated)
context = {
- "id": href,
+ "id": self.get_public_id(request),
"author": author.serialize(request),
"objectType": self.object_type,
"url": self.url_for_self(request.urlgen, qualified=True),