diff --git a/.gitignore b/.gitignore index 32825cc..5a176c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *.pyc +*.pyo +*.egg-info dist -django_helpdesk.egg-info +build +.idea \ No newline at end of file diff --git a/README.rst b/README.rst index de391e5..e0b8500 100644 --- a/README.rst +++ b/README.rst @@ -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 %} +
  • {{ item.title }}
  • + {% else %} +
  • {{ item.title }}
  • + {% 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' %} +
  • {{ item.title }}
  • + {% elif item.title == 'another-reverse-url-02' %} +
  • {{ item.title }}
  • + {% elif .... %} +
  • {{ item.title }}
  • + {% else %} +
  • {{ item.title }}
  • + {% endif %} + + Caching: -------- To avoid hitting the database every time a user requests a page, the menu items are diff --git a/menu/locale/zh_Hans/LC_MESSAGES/django.mo b/menu/locale/zh_Hans/LC_MESSAGES/django.mo index 3150fff..3c8f723 100644 Binary files a/menu/locale/zh_Hans/LC_MESSAGES/django.mo and b/menu/locale/zh_Hans/LC_MESSAGES/django.mo differ diff --git a/menu/locale/zh_Hans/LC_MESSAGES/django.po b/menu/locale/zh_Hans/LC_MESSAGES/django.po index c911a59..730e266 100644 --- a/menu/locale/zh_Hans/LC_MESSAGES/django.po +++ b/menu/locale/zh_Hans/LC_MESSAGES/django.po @@ -3,12 +3,11 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , 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 \n" "Language-Team: LANGUAGE \n" @@ -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 "菜单项" @@ -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 "菜单" diff --git a/menu/migrations/0002_booleandefaults.py b/menu/migrations/0002_booleandefaults.py index 58704b9..61a4473 100644 --- a/menu/migrations/0002_booleandefaults.py +++ b/menu/migrations/0002_booleandefaults.py @@ -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'), + ), ] diff --git a/menu/models.py b/menu/models.py index 4117ba6..bdcd1b0 100644 --- a/menu/models.py +++ b/menu/models.py @@ -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. @@ -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 + diff --git a/menu/templatetags/menubuilder.py b/menu/templatetags/menubuilder.py index 96fdb75..7e4f6b7 100644 --- a/menu/templatetags/menubuilder.py +++ b/menu/templatetags/menubuilder.py @@ -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)