diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-01-04 23:48:55 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-01-04 23:56:16 +0100 |
commit | f1cdd278e7cf195e485567ed0d0d8a90cad81e48 (patch) | |
tree | 4d83367fdc7959e46083018592bceb88e96c35ad | |
parent | 6a59a8abd49d921c2316fb4bd4cddf55a322b2fb (diff) | |
download | mediagoblin-f1cdd278e7cf195e485567ed0d0d8a90cad81e48.tar.lz mediagoblin-f1cdd278e7cf195e485567ed0d0d8a90cad81e48.tar.xz mediagoblin-f1cdd278e7cf195e485567ed0d0d8a90cad81e48.zip |
f691: Use StrictUndefined for templates and fix some issues
References to undefined variables in templates were
silently ignored/converted to None/empty strings. This
makes coding lazy stuff easy, but it makes catching typos
harder.
(It would have catched one of the SQL things earlier!)
But on the other hand it might make the current templates
error out everywhere. In fact, early testing has shown two
instances, that errored out. Those are fixed with this
commit too.
If this turns out to make things more complex and useless
than actually solving any problems, it can easily be
dropped again.
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media.html | 5 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/user.html | 3 | ||||
-rw-r--r-- | mediagoblin/tools/template.py | 3 |
3 files changed, 8 insertions, 3 deletions
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 9b331789..4b5c9337 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -60,8 +60,9 @@ {% trans date=media.created.strftime("%Y-%m-%d") -%} Added on {{ date }}. {%- endtrans %} - {% if media['uploader'] == request.user._id or - request.user['is_admin'] %} + {% if request.user and + (media.uploader == request.user._id or + request.user.is_admin) %} {% set edit_url = request.urlgen('mediagoblin.edit.edit_media', user= media.get_uploader.username, media= media._id) %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index b952e88c..78bbaf8c 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -113,7 +113,8 @@ {% else %} <div class="grid_6 alpha"> {% include "mediagoblin/utils/profile.html" %} - {% if request.user._id == user._id or request.user.is_admin %} + {% if request.user and + (request.user._id == user._id or request.user.is_admin) %} <a href="{{ request.urlgen('mediagoblin.edit.profile') }}?username={{ user.username }}"> {%- trans %}Edit profile{% endtrans -%} diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index d0400347..54a40de6 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -41,8 +41,11 @@ def get_jinja_env(template_loader, locale): if SETUP_JINJA_ENVS.has_key(locale): return SETUP_JINJA_ENVS[locale] + # jinja2.StrictUndefined will give exceptions on references + # to undefined/unknown variables in templates. template_env = jinja2.Environment( loader=template_loader, autoescape=True, + undefined=jinja2.StrictUndefined, extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape']) template_env.install_gettext_callables( |