NENAD CIKIC
unread,Mar 24, 2012, 10:39:24 AM3/24/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-admin-tools
Hello!
I want to add the language menu.
I have started with the following code that works:
{% get_available_languages as LANGUAGES %}
{% get_current_language as LANGUAGE_CODE %}
<form action="/favxp/i18n/setlang/" method="post"> {%
csrf_token %}
<select name="language">
{% for code, desc in LANGUAGES %}
<option value="{{ code }}"
{% ifequal code LANGUAGE_CODE %}
selected="1"
{% endifequal %}>{{ desc }}</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>
I have put that code in base.html and it changes correctly the
presentation languages.
Now I want to get rid of the above and to use the menu instead. So I
have extended the admin_tools items.py as:
class JezikList(MenuItem, AppListElementMixin):
def __init__(self, title=None, **kwargs):
super(JezikList, self).__init__(title, **kwargs)
def init_with_context(self, context):
jezici=[]
for lang in settings.LANGUAGES:
jezici.append(lang[1])
jezici.sort()
for jezik in jezici:
self.children.append(MenuItem(title=jezik,url='/favxp/i18n/
setlang/'))
and in my CustomMenu I have added the following children
items.JezikList(_('Presentation languages'))
The menu works, I mean i see all the languages sorted in the menu, but
nothing happens when i choose one of the languages. I have used the
livehttpheader to monitor what gets generated with the working code,
and it seems i have to add csrfmiddlewaretoken and the language code
as the content.
I am sure i am missing something basic:)
thanks