@wraps(controller)
def new_controller_func(request, *args, **kwargs):
if request.user and \
- request.user.get('status') == u'needs_email_verification':
+ request.user.status == u'needs_email_verification':
return redirect(
request, 'mediagoblin.user_pages.user_home',
user=request.user.username)
- elif not request.user or request.user.get('status') != u'active':
+ elif not request.user or request.user.status != u'active':
next_url = urljoin(
request.urlgen('mediagoblin.auth.login',
qualified=True),
request.url)
return redirect(request, 'mediagoblin.auth.login',
- next=url_quote(next_url))
+ next=next_url)
return controller(request, *args, **kwargs)
if not user:
raise NotFound()
- media = MediaEntry.query.filter_by(
- slug = request.matchdict['media'],
- state = u'processed',
- uploader = user.id).first()
+ media = None
- if not media:
- # no media via slug? Grab it via object id
+ # might not be a slug, might be an id, but whatever
+ media_slug = request.matchdict['media']
+
+ # if it starts with id: it actually isn't a slug, it's an id.
+ if media_slug.startswith(u'id:'):
try:
media = MediaEntry.query.filter_by(
- id = int(request.matchdict['media']),
- state = u'processed',
- uploader = user.id).first()
+ id=int(media_slug[3:]),
+ state=u'processed',
+ uploader=user.id).first()
except ValueError:
- # media "id" was no int
raise NotFound()
+ else:
+ # no magical id: stuff? It's a slug!
+ media = MediaEntry.query.filter_by(
+ slug=media_slug,
+ 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)
if not user:
return render_404(request)
- collection = request.db.Collection.find_one(
- {'slug': request.matchdict['collection'],
- 'creator': user.id})
-
collection_item = request.db.CollectionItem.find_one(
{'id': request.matchdict['collection_item'] })
@wraps(func)
def new_func(*args, **kwargs):
- with mgg.workbench_manager.create_workbench() as workbench:
+ with mgg.workbench_manager.create() as workbench:
return func(*args, workbench=workbench, **kwargs)
return new_func