I am not sure if someone had this issue before:
I have these pages in django cms's admin.
these are the pages I created using django cms and languages come from LANGUAGES from settings.py
and I used {% language_chooser %}, it dislays all languages which are defined in LANGUAGES.
What I want is: if I am in home, in language_chooser only those languages should show up for which there is a page created. in this case, only english, german, and espaniol
how can I achieve this? any guidance is appreciated
SOLVED, BUT..
I ended up using this inside language_chooser.html
{% load i18n menu_tags %}
{% get_available_languages as languages %}
{% if languages|length > 1 %}
{% for language in languages %}
{% if language.1 in current_page.get_languages %}
<li class="lang{% ifequal current_language language.0 %} active{% endifequal %}">
<a href="{% page_language_url language.0 %}"
title="{% trans "Change to language:" %} {{ language.1 }}">{{ language.0 }}</a>
</li>
{% endif %}
{% endfor %}
{% endif %}
But this is showing up only in home page, not in other pages, any ideas? BTW, Other pages are AppHooks
I just ended up doing this:
{% if languages|length > 1 %}
{% for language in languages %}
<li class="lang{% ifequal current_language language.0 %} active{% endifequal %}">
<a href="/./{{ language.0 }}/"
title="{% trans "Change to language:" %} {{ language.1 }}">{{ language.0 }}</a>
</li>
{% endfor %}
{% endif %}
meaning.. just redirect the user to main page if they change the language.
<a href="/./{{ language.0 }}/" ..
and make sure to define in settings.py only those languages that your site has translations for..
Related
I'm relatively new to the Django world. Our client wants to add a search feature to their site so I'm integrating Haystack and Aldryn Search as described here:
https://github.com/aldryn/aldryn-search
I've also gone through here: https://django-haystack.readthedocs.io/en/v2.6.0/tutorial.html
Exception Location: env/lib/python2.7/site-packages/haystack/backends/simple_backend.py in search, line 79
Here are some helpful information snippets:
urls.py -
(r'^search/', include('haystack.urls')),
templates/search/search.html -
{% extends 'base.html' %}
{% block content %}
<div class="primary-content">
<div class="container constrained">
<form method="get" class="paragraph" action=".">
{{ form.as_table }}
<div class="text-right">
<button type="submit" class="button">
Search
</button>
</div>
{% if query %}
<h3>Results</h3>
{% for result in page.object_list %}
<div class="post-preview paragraph">
<h3>
{{ result.object.title }}
</h3>
</div>
{% empty %}
<p>No results found.</p>
{% endfor %}
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}{% endif %}« Previous{% if page.has_previous %}{% endif %}
|
{% if page.has_next %}{% endif %}Next »{% if page.has_next %}{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
</div>
</div>
{% endblock %}
settings.py -
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
}
HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter', ]
ALDRYN_SEARCH_REGISTER_APPHOOK = True
ALDRYN_SEARCH_PAGINATION = 20
ALDRYN_SEARCH_CMS_PAGE = True
Additionally, both 'haystack' and 'aldryn_search' are in INSTALLED_APPS.
When I run update_index --remove it does seem to work for the most part:
Indexing 5 locations
Indexing 2 People
Indexing 16 articles
It looks like I've done everything right according to the documentation. But I must not be. We only have one language on the site so that does make the documentation a little hard to comprehend for me because I'm not sure if I have extra things that are only needed for multi lingual.
Stack trace:
['/build/healthdirect',
'/build/env/lib/python27.zip',
'/build/env/lib/python2.7',
'/build/env/lib/python2.7/plat-darwin',
'/build/env/lib/python2.7/plat-mac',
'/build/env/lib/python2.7/plat-mac/lib-scriptpackages',
'/build/env/lib/python2.7/lib-tk',
'/build/env/lib/python2.7/lib-old',
'/build/env/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/build/env/lib/python2.7/site-packages']
I am currently working on the navbar of a project with Django-cms. I am fairly new to this framework and language, so sorry if this is a stupid question.
This has double dropdowns, which respond to user changes in the Django-cms admin interface.
Which works. Sort of.
The problem is that get_children doesn't work (no errors or something, just not detecting children, and showing the 'should be dropdown button' as a non dropdown version), but get_descendants does. But if i use that the content of the second dropdown will be shown again in the first dropdown. So get_children will be perfect, as it will only show the direct descendants, instead of all.
{% load cms_tags menu_tags sekizai_tags staticfiles%}
{% load menu_tags %}
{% for child in children %}
<!--non dropdown 1-->
{% if child.is_leaf_node %}
<li>{{child.get_menu_title }}</li>
{% endif %}
<!--dropdown 1-->
{% if not child.is_leaf_node or child.ancestor %}
<div class="dropdown">
<li>{{child.get_menu_title }}<b class="caret"></b></li>
<!-- dropdown 1 content-->
{% if child.get_descendants %}
<div class="dropdown-content">
{% for kid in child.get_descendants %}
<!--non dropdown 2-->
{% if kid.is_leaf_node %}
<li>{{kid.get_menu_title }}</li>
{% endif %}
<!--dropdown 2 -->
{% if not child.is_leaf_node or child.ancestor %}
<li>
<a class="menu-has-sub">{{kid.get_menu_title }}<i class="fa fa-angle-down"></i></a>
<!-- dropdown 2 content-->
<ul class="sub-dropdown droppeddown">
{% for baby in kid.get_descendants %}
<li>{{baby.get_menu_title }}</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
{% endfor %}
So my question is: Why can't i use children
EDIT: *Why can't i use get_children. As in the function. No child labour here.
Nvm i fixed it! The syntax in this case should be children instead of get_children. which is funny because of that edit above.
Anyway, here's an example:
This doesn't work:
{% for kid in child.get_children %}
This does work:
{% for kid in child.children%}
hopefully this will help anyone else having this little struggle.
I'm trying to have two separate menus in my django-cms app. One for the header and another with a different set of links for the footer:
[ Logo ] Link_A Link_B Link_C Link_D
... content ...
Link_E Link_F Link_G Link_H
Using baked in {% show_menu %}, will show all of the pages registered, links A - H, and doesn't allow me to separate the two menus.
How can I create two separate menus?
Depends what you want to do really, but I've got a base template which has a navigation menu at the top and a sitemap submenu at the bottom.
So starting with the navigation;
{% show_menu 1 100 100 100 "partials/navigation.html" %}
Which uses the template;
{% load cms_tags menu_tags cache cms_page %}
{% for child in children %}
<li>
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">
{{ child.get_menu_title }}
</a>
{% if child.children and child.level <= 4 %}
<ul>
{% show_menu from_level to_level extra_inactive extra_active template '' '' child %}
</ul>
{% endif %}
</li>
{% endfor %}
Then the sitemap;
{% show_sub_menu 2 1 1 "partials/sitemap.html" %}
And sitemap.html
{% load cms_tags cms_page cache %}
{% if children %}
{% for child in children %}
<ul class="site-footer__column">
<li>
<h4>
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">
{{ child.get_menu_title }}
</a>
</h4>
</li>
{% if child.children %}
{% for baby in child.children %}
<li class="footer_sub">
<a href="{{ baby.attr.redirect_url|default:baby.get_absolute_url }}">
{{ baby.get_menu_title }}
</a>
</li>
{% endfor %}
{% endif %}
</ul>
{% endfor %}
{% endif %}
Understanding the options (numbers) you can provide for a menu can enable you to display different parts of your site, but if the built in menu tags don't suit your needs, you could write a custom menu tag.
The standard menu docs are here; http://docs.django-cms.org/en/3.2.2/reference/navigation.html
And here are the docs for customising your menus; http://docs.django-cms.org/en/3.2.2/how_to/menus.html
I'm totally confused by django-cms's show_menu tag. There are four parameters but no full document on these parameters could be found. There are only several exmaples however I cannot find how to show menu under current page only.
Pages are arranged like this:
--Projects
----proj1
----proj2
--Gallery
----gal1
----gal2
In Projects template, how do I set the parameters for show_menu to show only the menu under current page?
Update
#Brandon
I tried exactly this:
{% show_sub_menu 1 "menu/cust_menu.html" %}
As exactly what the document says. However it ends up in this error:
u'menu/cust_menu.html' could not be converted to Integer
You need to use:
{% show_sub_menu 1 %}
http://django-cms.readthedocs.org/en/2.1.3/advanced/templatetags.html#show-sub-menu
There is actually an error in documentation and it seems to be also a little bug introduced in one of the last versions of django cms (planned to be solved in django-cms 3.0 version!).
https://github.com/divio/django-cms/issues/1913
I solved using this:
{% show_menu_below_id "topics_page" 0 4 100 100 "./_menus/menu_topics.html" %}
where "topics_page" is the reverse id (you configure it in advanced section in cms admin).
For recursive rendering of menu, just configure the custom id of subpages for which you want display the next menu level;
in your custom menu template, you can play with child properties and the for loop counter. Below, check a nasty example but still useful if you want to customize your menu template:
{% load menu_tags %}
{% load template_extras %}
{% for child in children %}
{# sub voices topics #}
{% if child.level == 1 %}
{% if not forloop.counter|divisibleby:2 %}
<div class="row-fluid">
{% endif %}
<div class="span6">
<div class="sub1">
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}"><span
class="icon-play"></span>{{ child.get_menu_title|capfirst }}</a>
</div>
{% if child.children %}
{% show_menu_below_id child.attr.reverse_id 0 4 100 100 template %}
{% endif %}
</div>
{% if forloop.counter|divisibleby:2 %}
</div> <!-- end row fluid -->
{% endif %}
{% elif child.level == 2 %}
{# 2 - {{ child.attr.reverse_id}} - {{ child.get_menu_title }}#}
<div class="row-fluid">
<div class="span11 offset1">
<div class="sub2">
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title|capfirst }}
</a></div>
</div>
</div>
{% if child.children %}
{% show_menu_below_id child.attr.reverse_id 0 4 100 100 template %}
{% endif %}
{% elif child.level == 3 %}
{# leaf node topics #}
{# 3 - {{ child.attr.reverse_id}} - {{ child.get_menu_title }}#}
<div class="row-fluid">
<div class="span10 offset2">
<div class="sub3"><a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">
<i class="icon-list-alt"></i> {{ child.get_menu_title|capfirst }}</a></div>
</div>
</div>
{% endif %}
{% endfor %}
I'd like to replace the standard Markdown implementation in a Django blog I'm building with Github-flavoured Markdown. I'd like to use Misaka, and I've thrown together my own custom template tags. Unfortunately, something has gone awry.
Here is my template tags file, which is in blog/templatetags/gfm.py. The __init__.py file is present in the same folder:
from django import template
from django.template.defaultfilters import stringfilter
import misaka as m
register = template.Library()
#register.filter(is_safe=True)
#stringfilter
def gfm(value):
rendered_text = m.html(value,
extensions=m.EXT_FENCED_CODE,
render_flags=m.HTML_ESCAPE)
return rendered_text
And here is one of my templates:
{% extends 'layout/base.html' %}
{% block header %}
{% endblock %}
{% block content %}
{% load gfm %}
{% if object_list %}
{% for post in object_list %}
<div class="post">
<div class="page-header">
<h1>{{ post.title }}</h1>
</div>
{{ post.text|gfm }}
<p>Posted {{ post.pub_date }}</p>
<p>
{% for category in post.categories.all %}
<a class="badge badge-info" href="/category/{{ category.slug }}/">{{ category.title }}</a>
{% endfor %}
</p>
</div>
{% endfor %}
<br />
<ul class="pager">
{% if page_obj.has_previous %}
<li class="previous">Previous Page</li>
{% endif %}
{% if page_obj.has_next %}
<li class="next">Next Page</li>
{% endif %}
</ul>
{% else %}
<div class="post">
<p>No posts matched</p>
</div>
{% endif %}
{% endblock %}
The outputted text is being returned wrapped in double quotes, which breaks the whole thing. Otherwise, the markup generated seems correct.
Where have I gone wrong here? I know it's not the data in the database as if I use pdb to get the values of value and rendered_text inside the function, they are rendered correctly. For example, here is the plain text version of one post, as printed by pdb:
u'A Python application:\r\n\r\n print "Hello world"'
And here is the version rendered in Markdown using Misaka:
u'<p>A Python application:</p>\n\n<pre><code>print "Hello world"\n</code></pre>\n'
I'm fairly experienced with Django, but I'm new to custom template tags.
Use autoescape tag.
{% autoescape off %}{{ post.text|gfm }}{% endautoescape %}
Alternatively you can use safe filter.
{{ post.text|gfm|safe }}