Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

add dynamic mode for menu & translation file update #18

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.pyc
*.pyo
*.egg-info
dist
django_helpdesk.egg-info
build
.idea
25 changes: 25 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ In your template, instead of the ``{% menu %}`` tag use ``{% submenu %}``. If a
submenu for the current URI exists, it will be shown. The ``{{ submenu_items }}``
list contains your navigation items, ready to output like in the examples above.

Reverse URL:
------------
begin 0.1.11, django-menu support make reverse-url and static-url together.:::

{% if item.is_reverse_url %}
<li><a href="{% url item.url %}">{{ item.title }}</a></li>
{% else %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endif %}


before 0.1.11, if you want make reverse-url and static-url together,
you have to do it like this.:::

{% if item.title == 'reverse-url-01' %}
<li><a href="{% url item.url %}">{{ item.title }}</a></li>
{% elif item.title == 'another-reverse-url-02' %}
<li><a href="{% url item.url %}">{{ item.title }}</a></li>
{% elif .... %}
<li><a href="{% url item.url %}">{{ item.title }}</a></li>
{% else %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endif %}


Caching:
--------
To avoid hitting the database every time a user requests a page, the menu items are
Expand Down
Binary file modified menu/locale/zh_Hans/LC_MESSAGES/django.mo
Binary file not shown.
15 changes: 11 additions & 4 deletions menu/locale/zh_Hans/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-05-22 22:05+0800\n"
"POT-Creation-Date: 2016-11-29 09:33+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Wang WenPei <wangwenpei@nextoa.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -19,7 +18,7 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"

#: menu/apps.py:8 menu/apps.py:9
#: menu/apps.py:9
msgid "Menu"
msgstr "菜单项"

Expand Down Expand Up @@ -80,9 +79,17 @@ msgid "Should this item only be shown to non-logged-in users?"
msgstr "设定当前菜单只在未登录时才显示"

#: menu/models.py:89
msgid "Is reverse URL"
msgstr "反向解析URL"

#: menu/models.py:92
msgid "Should Link URL need reverse?"
msgstr "链接地址是否需要做反向解析?"

#: menu/models.py:96
msgid "menu item"
msgstr "菜单"

#: menu/models.py:90
#: menu/models.py:97
msgid "menu items"
msgstr "菜单"
7 changes: 7 additions & 0 deletions menu/migrations/0002_booleandefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ class Migration(migrations.Migration):
name='login_required',
field=models.BooleanField(default=False, help_text='Should this item only be shown to authenticated users?', verbose_name='Login required'),
),
migrations.AddField(
model_name='menuitem',
name='is_reverse_url',
field=models.BooleanField(default=False,
help_text='Should Link URL need reverse?',
verbose_name='Is reverse URL'),
),
]
13 changes: 10 additions & 3 deletions menu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class Meta:
def __unicode__(self):
return u"%s" % self.name

def __str__(self):
return self.__unicode__()

def save(self, *args, **kwargs):
"""
Re-order all items from 10 upwards, at intervals of 10.
Expand Down Expand Up @@ -87,9 +84,19 @@ class MenuItem(models.Model):
help_text=_(u'Should this item only be shown to non-logged-in users?')
)

is_reverse_url = models.BooleanField(
_(u'Is reverse URL'),
blank=True,
default=False,
help_text=_(u'Should Link URL need reverse?')
)

class Meta:
verbose_name = _(u'menu item')
verbose_name_plural = _(u'menu items')

def __unicode__(self):
return u"%s %s. %s" % (self.menu.slug, self.order, self.title)

pass

2 changes: 1 addition & 1 deletion menu/templatetags/menubuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_items(menu_name, current_path, user):
show_anonymous = i.anonymous_only and is_anonymous
show_auth = i.login_required and is_authenticated
if (not (i.login_required or i.anonymous_only)) or (i.login_required and show_auth) or (i.anonymous_only and show_anonymous):
menuitems.append({'url': i.link_url, 'title': i.title, 'current': current,})
menuitems.append({'url': i.link_url, 'title': i.title, 'current': current, 'is_reverse_url': i.is_reverse_url})

if cache_time >= 0 and not debug:
cache.set(cache_key, menuitems, cache_time)
Expand Down