aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/app.py37
-rw-r--r--mediagoblin/auth/views.py4
-rw-r--r--mediagoblin/decorators.py16
-rw-r--r--mediagoblin/templates/mediagoblin/404.html19
-rw-r--r--mediagoblin/templates/mediagoblin/root.html14
-rw-r--r--mediagoblin/user_pages/views.py15
-rw-r--r--mediagoblin/util.py20
7 files changed, 74 insertions, 51 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py
index c1ee3d77..3030929d 100644
--- a/mediagoblin/app.py
+++ b/mediagoblin/app.py
@@ -101,6 +101,23 @@ class MediaGoblinApp(object):
## Routing / controller loading stuff
route_match = self.routing.match(path_info)
+ ## Attach utilities to the request object
+ request.matchdict = route_match
+ request.urlgen = routes.URLGenerator(self.routing, environ)
+ # Do we really want to load this via middleware? Maybe?
+ request.session = request.environ['beaker.session']
+ # Attach self as request.app
+ # Also attach a few utilities from request.app for convenience?
+ request.app = self
+ request.locale = util.get_locale_from_request(request)
+
+ request.template_env = util.get_jinja_env(
+ self.template_loader, request.locale)
+ request.db = self.db
+ request.staticdirect = self.staticdirector
+
+ util.setup_user_in_request(request)
+
# No matching page?
if route_match is None:
# Try to do see if we have a match with a trailing slash
@@ -116,28 +133,12 @@ class MediaGoblinApp(object):
return request.get_response(redirect)(environ, start_response)
# Okay, no matches. 404 time!
- return exc.HTTPNotFound()(environ, start_response)
+ request.matchdict = {} # in case our template expects it
+ return util.render_404(request)(environ, start_response)
controller = util.import_component(route_match['controller'])
request.start_response = start_response
- ## Attach utilities to the request object
- request.matchdict = route_match
- request.urlgen = routes.URLGenerator(self.routing, environ)
- # Do we really want to load this via middleware? Maybe?
- request.session = request.environ['beaker.session']
- # Attach self as request.app
- # Also attach a few utilities from request.app for convenience?
- request.app = self
- request.locale = util.get_locale_from_request(request)
-
- request.template_env = util.get_jinja_env(
- self.template_loader, request.locale)
- request.db = self.db
- request.staticdirect = self.staticdirector
-
- util.setup_user_in_request(request)
-
return controller(request)(environ, start_response)
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
index 9120196f..4c4a34fd 100644
--- a/mediagoblin/auth/views.py
+++ b/mediagoblin/auth/views.py
@@ -20,7 +20,7 @@ from webob import exc
from mediagoblin import messages
from mediagoblin import mg_globals
-from mediagoblin.util import render_to_response, redirect
+from mediagoblin.util import render_to_response, redirect, render_404
from mediagoblin.util import pass_to_ugettext as _
from mediagoblin.db.util import ObjectId
from mediagoblin.auth import lib as auth_lib
@@ -144,7 +144,7 @@ def verify_email(request):
"""
# If we don't have userid and token parameters, we can't do anything; 404
if not request.GET.has_key('userid') or not request.GET.has_key('token'):
- return exc.HTTPNotFound()
+ return render_404(request)
user = request.db.User.find_one(
{'_id': ObjectId(unicode(request.GET['userid']))})
diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py
index 2e90274e..c66049ca 100644
--- a/mediagoblin/decorators.py
+++ b/mediagoblin/decorators.py
@@ -17,7 +17,7 @@
from webob import exc
-from mediagoblin.util import redirect
+from mediagoblin.util import redirect, render_404
from mediagoblin.db.util import ObjectId, InvalidId
@@ -60,9 +60,9 @@ def uses_pagination(controller):
try:
page = int(request.GET.get('page', 1))
if page < 0:
- return exc.HTTPNotFound()
+ return render_404(request)
except ValueError:
- return exc.HTTPNotFound()
+ return render_404(request)
return controller(request, page=page, *args, **kwargs)
@@ -78,7 +78,7 @@ def get_user_media_entry(controller):
{'username': request.matchdict['user']})
if not user:
- return exc.HTTPNotFound()
+ return render_404(request)
media = request.db.MediaEntry.find_one(
{'slug': request.matchdict['media'],
@@ -93,11 +93,11 @@ def get_user_media_entry(controller):
'state': 'processed',
'uploader': user['_id']})
except InvalidId:
- return exc.HTTPNotFound()
+ return render_404(request)
# Still no media? Okay, 404.
if not media:
- return exc.HTTPNotFound()
+ return render_404(request)
return controller(request, media=media, *args, **kwargs)
@@ -113,11 +113,11 @@ def get_media_entry_by_id(controller):
{'_id': ObjectId(request.matchdict['media']),
'state': 'processed'})
except InvalidId:
- return exc.HTTPNotFound()
+ return render_404(request)
# Still no media? Okay, 404.
if not media:
- return exc.HTTPNotFound()
+ return render_404(request)
return controller(request, media=media, *args, **kwargs)
diff --git a/mediagoblin/templates/mediagoblin/404.html b/mediagoblin/templates/mediagoblin/404.html
index 7a86a386..5af46a87 100644
--- a/mediagoblin/templates/mediagoblin/404.html
+++ b/mediagoblin/templates/mediagoblin/404.html
@@ -19,11 +19,16 @@
{% block mediagoblin_content %}
<h1>{% trans %}Oops!{% endtrans %}</h1>
-<div class="grid_8 alpha">
- <p>There doesn't seem to be a page at this address. Sorry!</p>
- <p>If you're sure the address is correct, maybe the page you're looking for has been moved or deleted.</p>
-</div>
-<div class="grid_8 omega">
- <img src="{{ request.staticdirect('/images/404.png') }}" />
-</div>
+
+ <div class="grid_8 alpha">
+ <p>{% trans %}There doesn't seem to be a page at this address. Sorry!{% endtrans %}</p>
+ <p>
+ {%- trans %}If you're sure the address is correct, maybe the page you're looking for has been moved or deleted.{% endtrans -%}
+ </p>
+ </div>
+
+ <div class="grid_8 omega">
+ <img src="{{ request.staticdirect('/images/404.png') }}"
+ alt="{% trans %}Image of 404 goblin stressing out{% endtrans %}" />
+ </div>
{% endblock %}
diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html
index 764609b6..08155c17 100644
--- a/mediagoblin/templates/mediagoblin/root.html
+++ b/mediagoblin/templates/mediagoblin/root.html
@@ -26,21 +26,25 @@
<div class="grid_11 alpha">
<h1>{% trans %}Hi there, media lover! MediaGoblin is...{% endtrans %}</h1>
<ul>
- <li>The perfect place for your media! No, seriously.</li>
- <li>This is just placeholder text though. In the future this will all make sense, trust me.</li>
- <li>It might talk about all the awesome features we've got. Or about how great federation is.</li>
- <li>Or that it's free software and a GNU project, so anyone can help improve and share it.</li>
- <li>No matter what, it's probably good to have <a href="example.com">a link</a> here. You never know.</li>
+ <li>{% trans %}The perfect place for your media!{% endtrans %}</li>
+ <li>{% trans %}A place for people to collaborate and show off original and derived creations!{% endtrans %}</li>
+ <li>{% trans %}Free, as in freedom. (We’re a <a href="http://gnu.org">GNU project</a> in the making, after all.){% endtrans %}</li>
+ <li>{% trans %}Aiming to make the world a better place through decentralization and (eventually, coming soon!) federation!{% endtrans %}</li>
+ <li>{% trans %}Built for extensibility. (Multiple media types coming soon to the software, including video support!){% endtrans %}</li>
+ <li>{% trans %}Powered by people like you. (<a href="http://mediagoblin.org/pages/join.html">You can help us improve this software!</a>){% endtrans %}</li>
</ul>
+
{% if allow_registration %}
<p>Excited to join us? To add your own media, make collections and save favorites...<p>
<a class="header_submit_highlight" href="{{ request.urlgen('mediagoblin.auth.register') }}">Create a free account</a> or
<a class="header_submit" href="http://wiki.mediagoblin.org/HackingHowto">Set up MediaGoblin on your own server</a>
{% endif %}
</div>
+
<div class="grid_5 omega">
<img src="{{ request.staticdirect('/images/frontpage_image.png') }}" />
</div>
+
<div class="clear"></div>
{% endif %}
<h2>Most recent media</h2>
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index d4ff1fce..3677c134 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -19,7 +19,8 @@ from webob import exc
from mediagoblin import messages
from mediagoblin.db.util import DESCENDING, ObjectId
from mediagoblin.util import (
- Pagination, render_to_response, redirect, cleaned_markdown_conversion)
+ Pagination, render_to_response, redirect, cleaned_markdown_conversion,
+ render_404)
from mediagoblin.user_pages import forms as user_forms
from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
@@ -34,7 +35,7 @@ def user_home(request, page):
user = request.db.User.find_one({
'username': request.matchdict['user']})
if not user:
- return exc.HTTPNotFound()
+ return render_404(request)
elif user['status'] != u'active':
return render_to_response(
request,
@@ -50,7 +51,7 @@ def user_home(request, page):
#if no data is available, return NotFound
if media_entries == None:
- return exc.HTTPNotFound()
+ return render_404(request)
user_gallery_url = request.urlgen(
'mediagoblin.user_pages.user_gallery',
@@ -71,7 +72,7 @@ def user_gallery(request, page):
'username': request.matchdict['user'],
'status': 'active'})
if not user:
- return exc.HTTPNotFound()
+ return render_404(request)
cursor = request.db.MediaEntry.find(
{'uploader': user['_id'],
@@ -82,7 +83,7 @@ def user_gallery(request, page):
#if no data is available, return NotFound
if media_entries == None:
- return exc.HTTPNotFound()
+ return render_404(request)
return render_to_response(
request,
@@ -154,7 +155,7 @@ def atom_feed(request):
'username': request.matchdict['user'],
'status': 'active'})
if not user:
- return exc.HTTPNotFound()
+ return render_404(request)
cursor = request.db.MediaEntry.find({
'uploader': user['_id'],
@@ -190,7 +191,7 @@ def processing_panel(request):
# Make sure the user exists and is active
if not user:
- return exc.HTTPNotFound()
+ return render_404(request)
elif user['status'] != u'active':
return render_to_response(
request,
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index cc426228..0b6428da 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -138,9 +138,11 @@ def clear_test_template_context():
TEMPLATE_TEST_CONTEXT = {}
-def render_to_response(request, template, context):
+def render_to_response(request, template, context, status=200):
"""Much like Django's shortcut.render()"""
- return Response(render_template(request, template, context))
+ return Response(
+ render_template(request, template, context),
+ status=status)
def redirect(request, *args, **kwargs):
@@ -346,8 +348,10 @@ def get_locale_from_request(request):
accept_lang_matches = request.accept_language.best_matches()
# Your routing can explicitly specify a target language
- if request.matchdict.has_key('locale'):
- target_lang = request.matchdict['locale']
+ matchdict = request.matchdict or {}
+
+ if matchdict.has_key('locale'):
+ target_lang = matchdict['locale']
elif request.session.has_key('target_lang'):
target_lang = request.session['target_lang']
# Pull the first acceptable language
@@ -660,3 +664,11 @@ def gridify_cursor(this_cursor, num_cols=5):
the number of columns in the list
"""
return gridify_list(list(this_cursor), num_cols)
+
+
+def render_404(request):
+ """
+ Render a 404.
+ """
+ return render_to_response(
+ request, 'mediagoblin/404.html', {}, status=400)