aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2013-02-26 13:38:11 -0600
committerChristopher Allan Webber <cwebber@dustycloud.org>2013-02-26 13:38:11 -0600
commit7de20e52345949fa9d377f06ab0241d98063d9c9 (patch)
tree1c73054310000bbbdaed52379555513f928910f3
parent397c22d1396cef285e3752d3972979bf53beb988 (diff)
downloadmediagoblin-7de20e52345949fa9d377f06ab0241d98063d9c9.tar.lz
mediagoblin-7de20e52345949fa9d377f06ab0241d98063d9c9.tar.xz
mediagoblin-7de20e52345949fa9d377f06ab0241d98063d9c9.zip
Media URLs with ids in them are now like /u/cwebber/m/id:4112/ rather than /u/cwebber/m/4112/
This avoids some potential name collision issues. This commit sponsored by Asokan Pichai. Thank you!
-rw-r--r--mediagoblin/db/mixin.py6
-rw-r--r--mediagoblin/decorators.py39
2 files changed, 27 insertions, 18 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py
index b69e7d51..6789a970 100644
--- a/mediagoblin/db/mixin.py
+++ b/mediagoblin/db/mixin.py
@@ -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):
"""
diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py
index 85883c1a..14b4f8fc 100644
--- a/mediagoblin/decorators.py
+++ b/mediagoblin/decorators.py
@@ -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)