Moved site_url macro into context processor so could use hasattr(g, 'lang') to fix a bug

This commit is contained in:
str4d
2012-12-19 11:43:40 +00:00
parent 487e9ae935
commit 66dca619d7
3 changed files with 12 additions and 7 deletions

View File

@@ -178,6 +178,16 @@ def restructuredtext(value):
@app.context_processor
def utility_processor():
# Shorthand for getting a site url
def get_site_url(path=None):
lang = 'en'
if hasattr(g, 'lang') and g.lang:
lang = g.lang
if path:
return url_for('site_show', lang=lang, page=path)
else:
return url_for('site_show', lang=lang)
# Provide the canonical link to the current page
def get_canonical_link():
protocol = request.url.split('//')[0]
@@ -220,6 +230,7 @@ def utility_processor():
return dict(i2pconv=convert_url_to_clearnet,
url_for_other_page=url_for_other_page,
change_theme=change_theme,
site_url=get_site_url,
canonical=get_canonical_link)

View File

@@ -1,4 +1,4 @@
{%- from "global/macros" import site_url, change_lang, ver with context -%}
{%- from "global/macros" import change_lang, ver with context -%}
<!DOCTYPE html>
<html lang="en">
<head>

View File

@@ -1,9 +1,3 @@
{%- macro site_url(path=None) -%}
{%- if path -%}{{ url_for('site_show', lang=g.lang, page=path) }}
{%- else -%}{{ url_for('site_show', lang=g.lang) }}
{%- endif -%}
{%- endmacro -%}
{%- macro change_lang(lang) -%}
{%- if request.endpoint == 'site_show' -%}{{ url_for('site_show', lang=lang, page=page) }}
{%- elif request.endpoint == 'blog_entry' -%}{{ url_for('blog_entry', lang=lang, slug=slug) }}