from bson.errors import InvalidId
from webob import exc
+from mediagoblin.util import redirect
from mediagoblin.db.util import ObjectId
Require an active login from the user.
"""
def new_controller_func(request, *args, **kwargs):
- if request.user and request.user.get('status') == u'needs_email_verification':
- return exc.HTTPFound(
- location = request.urlgen('mediagoblin.auth.verify_email_notice'))
+ if request.user and \
+ request.user.get('status') == u'needs_email_verification':
+ return redirect(request,
+ 'mediagoblin.auth.verify_email_notice')
elif not request.user or request.user.get('status') != u'active':
return exc.HTTPFound(
location="%s?next=%s" % (
return controller(request, media=media, *args, **kwargs)
return _make_safe(wrapper, controller)
+
+def get_media_entry_by_id(controller):
+ """
+ Pass in a MediaEntry based off of a url component
+ """
+ def wrapper(request, *args, **kwargs):
+ try:
+ media = request.db.MediaEntry.find_one(
+ {'_id': ObjectId(request.matchdict['media']),
+ 'state': 'processed'})
+ except InvalidId:
+ return exc.HTTPNotFound()
+
+ # Still no media? Okay, 404.
+ if not media:
+ return exc.HTTPNotFound()
+
+ return controller(request, media=media, *args, **kwargs)
+
+ return _make_safe(wrapper, controller)