hilite.me
Yeah baby alfin un servicio para postear codigo y se vea bonito… tendra api ?
<span style="color: #aa5500">"""</span>
Displays the url of the current page in the defined language. You can set a language_changer function with the set_language_changer function in the utils.py if there is no page. This is needed if you have slugs in more than one language. """ name = 'page_language_url' template = 'cms/content.html'
options = Options(
Argument(<span style="color: #aa5500">'lang'</span>),
)
<span style="color: #0000aa">def</span> <span style="color: #00aa00">get_context</span>(<span style="color: #00aaaa">self</span>, context, lang):
<span style="color: #0000aa">try</span>:
<span style="color: #aaaaaa; font-style: italic"># If there's an exception (500), default context_processors may not be called.</span>
request = context[<span style="color: #aa5500">'request'</span>]
<span style="color: #0000aa">except</span> KeyError:
<span style="color: #0000aa">return</span> {<span style="color: #aa5500">'template'</span>: <span style="color: #aa5500">'cms/content.html'</span>}
<span style="color: #0000aa">if</span> <span style="color: #00aaaa">hasattr</span>(request, <span style="color: #aa5500">"_language_changer"</span>):
<span style="color: #0000aa">try</span>:
<span style="color: #00aaaa">setattr</span>(request._language_changer, <span style="color: #aa5500">'request'</span>, request)
<span style="color: #0000aa">except</span> AttributeError:
<span style="color: #0000aa">pass</span>
url = <span style="color: #aa5500">"/%s"</span> % lang + request._language_changer(lang)
<span style="color: #0000aa">else</span>:
page = request.current_page
<span style="color: #0000aa">if</span> page == <span style="color: #aa5500">"dummy"</span>:
<span style="color: #0000aa">return</span> <span style="color: #aa5500">''</span>
<span style="color: #0000aa">try</span>:
url = page.get_absolute_url(language=lang, fallback=<span style="color: #00aaaa">False</span>)
url = <span style="color: #aa5500">"/"</span> + lang + url
<span style="color: #0000aa">except</span>:
<span style="color: #aaaaaa; font-style: italic"># no localized path/slug. </span>
url = <span style="color: #aa5500">''</span>
<span style="color: #0000aa">return</span> {<span style="color: #aa5500">'content'</span>:url}
register.tag(PageLanguageUrl)