Media URLs with ids in them are now like /u/cwebber/m/id:4112/ rather than /u/cwebber...
authorChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 26 Feb 2013 19:38:11 +0000 (13:38 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 26 Feb 2013 19:38:11 +0000 (13:38 -0600)
This avoids some potential name collision issues.

This commit sponsored by Asokan Pichai.  Thank you!

mediagoblin/db/mixin.py
mediagoblin/decorators.py

index b69e7d51833ae502e121f614d6d404fb88d7d2ad..6789a970769453ef7f34d1f95a0aadb54903cc54 100644 (file)
@@ -150,8 +150,10 @@ class MediaEntryMixin(object):
 
     @property
     def slug_or_id(self):
-        return (self.slug or self.id)
-
+        if self.slug:
+            return self.slug
+        else:
+            return u'id:%s' % self.id
 
     def url_for_self(self, urlgen, **extra_args):
         """
index 85883c1a6d3dcc4515d9880930c21e265606a927..14b4f8fc7ba97920186dd8622f8b7b6e519401e5 100644 (file)
@@ -125,24 +125,31 @@ def get_user_media_entry(controller):
         if not user:
             raise NotFound()
 
-        media = MediaEntry.query.filter_by(
-            slug=request.matchdict['media'],
-            state=u'processed',
-            uploader=user.id).first()
-
-        if not media:
-            # no media via slug?  Grab it via object id
-            try:
-                media = MediaEntry.query.filter_by(
-                    id = int(request.matchdict['media']),
-                    state = u'processed',
-                    uploader = user.id).first()
-            except ValueError:
-                # media "id" was no int
-                raise NotFound()
+        media = None
+
+        # might not be a slug, might be an id, but whatever
+        media_slug = request.matchdict['media']
+
+        if u":" in request.matchdict['media']:
+            # okay, it's not actually a slug, it's some kind of identifier,
+            # probably id:
+            if media_slug.startswith(u'id:'):
+                try:
+                    media = MediaEntry.query.filter_by(
+                        id=int(media_slug[3:]),
+                        state=u'processed',
+                        uploader=user.id).first()
+                except ValueError:
+                    raise NotFound()
+        else:
+            # no magical id: stuff?  It's a slug!
+            media = MediaEntry.query.filter_by(
+                slug=request.matchdict['media'],
+                state=u'processed',
+                uploader=user.id).first()
 
         if not media:
-            # no media by that id? Okay, 404.
+            # Didn't find anything?  Okay, 404.
             raise NotFound()
 
         return controller(request, media=media, *args, **kwargs)