From 3e907d5516d50fc4a75e7ccb4e687db924ec9ff6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 22 Jan 2012 17:11:43 +0100 Subject: [PATCH] Let some code support "media without slug" The upcoming SQL database will allow having media without a slug again. This might especially be useful for API support, where the uploaded image (media) does not have *any* information to generate a slug from. This code change mostly allows the sql backend to have no slug in its model and improves some parts to properly handle that. It specifically does not have any web frontend support to edit/create MediaEntries with no slug. --- mediagoblin/db/mixin.py | 21 ++++++++----------- mediagoblin/db/sql/models.py | 2 +- .../mediagoblin/user_pages/media.html | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index d587ccb4..254dbcff 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -63,6 +63,10 @@ class MediaEntryMixin(object): def main_mediafile(self): pass + @property + def slug_or_id(self): + return (self.slug or self._id) + def url_for_self(self, urlgen, **extra_args): """ Generate an appropriate url for ourselves @@ -71,18 +75,11 @@ class MediaEntryMixin(object): """ uploader = self.get_uploader - if self.get('slug'): - return urlgen( - 'mediagoblin.user_pages.media_home', - user=uploader.username, - media=self.slug, - **extra_args) - else: - return urlgen( - 'mediagoblin.user_pages.media_home', - user=uploader.username, - media=unicode(self._id), - **extra_args) + return urlgen( + 'mediagoblin.user_pages.media_home', + user=uploader.username, + media=self.slug_or_id, + **extra_args) def get_fail_exception(self): """ diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 95147d50..6232fff8 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -72,7 +72,7 @@ class MediaEntry(Base, MediaEntryMixin): id = Column(Integer, primary_key=True) uploader = Column(Integer, ForeignKey('users.id'), nullable=False) title = Column(Unicode, nullable=False) - slug = Column(Unicode, nullable=False) + slug = Column(Unicode) created = Column(DateTime, nullable=False, default=datetime.datetime.now) description = Column(UnicodeText) # ?? description_html = Column(UnicodeText) # ?? diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index cbe26cbf..9df3dfbc 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -127,7 +127,7 @@ + media = media.slug_or_id) }}#comment"> {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }} -- 2.25.1