Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

setup(
name='django-treemenus',
version='0.8.8-pre',
version='0.8.9-pre',
description='Tree-structured menuing application for Django.',
author='Julien Phalip',
author_email='[email protected]',
url='http://github.com/jphalip/django-treemenus/',
author='Julien Phalip, Yuriy Apollov',
author_email='[email protected], [email protected]',
url='http://github.com/jphalip/django-treemenus/, http://github.com/apollovy/django-treemenus/',
packages=find_packages(),
package_data={
'treemenus': [
Expand Down
12 changes: 7 additions & 5 deletions treemenus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from django.utils.translation import ugettext_lazy
from django.utils.translation import ugettext as _

from settings import SETTINGS


class MenuItem(models.Model):
parent = models.ForeignKey('self', verbose_name=ugettext_lazy('parent'), null=True, blank=True)
caption = models.CharField(ugettext_lazy('caption'), max_length=50)
url = models.CharField(ugettext_lazy('URL'), max_length=200, blank=True)
named_url = models.CharField(ugettext_lazy('named URL'), max_length=200, blank=True)
caption = models.CharField(ugettext_lazy('caption'), max_length=SETTINGS['MENUITEM_CAPTION_LENGTH_MAX'])
url = models.CharField(ugettext_lazy('URL'), max_length=SETTINGS['MENUITEM_URL_LENGTH_MAX'], blank=True)
named_url = models.CharField(ugettext_lazy('named URL'), max_length=SETTINGS['MENUITEM_NAMED_URL_LENGTH_MAX'], blank=True)
level = models.IntegerField(ugettext_lazy('level'), default=0, editable=False)
rank = models.IntegerField(ugettext_lazy('rank'), default=0, editable=False)
menu = models.ForeignKey('Menu', related_name='contained_items', verbose_name=ugettext_lazy('menu'), null=True, blank=True, editable=False)
Expand All @@ -31,7 +33,7 @@ def save(self, force_insert=False, **kwargs):
new_parent = self.parent
old_parent = MenuItem.objects.get(pk=self.pk).parent
if old_parent != new_parent:
#If so, we need to recalculate the new ranks for the item and its siblings (both old and new ones).
# If so, we need to recalculate the new ranks for the item and its siblings (both old and new ones).
if new_parent:
clean_ranks(new_parent.children()) # Clean ranks for new siblings
self.rank = new_parent.children().count()
Expand Down Expand Up @@ -100,7 +102,7 @@ def has_children(self):


class Menu(models.Model):
name = models.CharField(ugettext_lazy('name'), max_length=50)
name = models.CharField(ugettext_lazy('name'), max_length=SETTINGS['MENU_NAME_LENGTH_MAX'])
root_item = models.ForeignKey(MenuItem, related_name='is_root_item_of', verbose_name=ugettext_lazy('root item'), null=True, blank=True, editable=False)

def save(self, force_insert=False, **kwargs):
Expand Down
12 changes: 12 additions & 0 deletions treemenus/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.conf import settings


SETTINGS = {
'MENU_NAME_LENGTH_MAX': 50,
'MENUITEM_CAPTION_LENGTH_MAX': 50,
'MENUITEM_URL_LENGTH_MAX': 2000, # de-facto, http://stackoverflow.com/a/417184
'MENUITEM_NAMED_URL_LENGTH_MAX': 200,

}

SETTINGS.update(getattr(settings, 'TREEMENUS_SETTINGS', {}))
9 changes: 5 additions & 4 deletions treemenus/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class TreemenusTestCase(TestCase):
def setUp(self):
# Install testapp
self.old_INSTALLED_APPS = settings.INSTALLED_APPS
settings.INSTALLED_APPS += ['treemenus.tests.fake_menu_extension']
settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + \
['treemenus.tests.fake_menu_extension']
load_app('treemenus.tests.fake_menu_extension')
call_command('syncdb', verbosity=0, interactive=False)

Expand Down Expand Up @@ -152,7 +153,7 @@ def test_view_change_item(self):
self.assertRedirects(response, '/test_treemenus_admin/treemenus/menu/%s/' % menu.pk)

menu_item = menu.root_item.children()[0]
menu_item.menu = None # Corrupt it!
menu_item.menu = None # Corrupt it!

# Change the item
menu_item_data = {
Expand Down Expand Up @@ -587,7 +588,7 @@ def test_move_item_or_clean_ranks(self):
menu_item4.rank = 0
menu_item4.save()

move_item_or_clean_ranks(menu_item3, -1) # Move up
move_item_or_clean_ranks(menu_item3, -1) # Move up

# Retrieve objects from db
menu_item1 = MenuItem.objects.get(caption='menu_item1', parent=menu.root_item)
Expand All @@ -610,7 +611,7 @@ def test_move_item_or_clean_ranks(self):
menu_item4.rank = 99
menu_item4.save()

move_item_or_clean_ranks(menu_item1, 1) # Try to move down
move_item_or_clean_ranks(menu_item1, 1) # Try to move down

# Retrieve objects from db
menu_item1 = MenuItem.objects.get(caption='menu_item1', parent=menu.root_item)
Expand Down