Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Fix entries getting duplicated from apps using AppConfig.
Browse files Browse the repository at this point in the history
Fix entry always selected with blue color at template
  • Loading branch information
Javier Cordero committed Feb 12, 2014
1 parent 3f4b0d2 commit 032c77c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
32 changes: 16 additions & 16 deletions tests/tests/apps.py
Expand Up @@ -19,26 +19,26 @@ def setUp(self):
def test_get_menu(self):
generated_menu = self.test_view.get_apps_menu()
self.assertEqual(generated_menu,
{'app:testapp':
{'title': 'Test App', 'url': '', 'perm': None,
'menus': [
{'url': '/admin/testapp/testurl/', 'title': u'Test URL',
'order': '', 'perm': None, 'icon': 'bolt'}],
'first_icon': 'test', 'order': ''}})
{'app:testapp': {
'menus': [
{'url': '/admin/testapp/testurl/', 'title': u'Test URL',
'order': '', 'perm': None, 'icon': 'bolt'}],
'first_icon': 'test', 'title': 'Test App'}})

final_menu = self.test_view.get_nav_menu()
self.assertEqual(
final_menu,
[{'first_url': '/tests/modela/', 'title': 'Test App',
'url': '', 'perm': None, 'menus': [
{'url': '/tests/modela/', 'icon': None, 'order': 1,
'perm': 'tests.view_modela', 'title': u'Model as'},
{'url': '/admin/testapp/testurl/', 'title': u'Test URL',
'order': '', 'perm': None, 'icon': 'bolt'}],
'first_icon': 'test', 'order': ''},
{'menus': [{'url': '/tests/modelb/', 'icon': None, 'order': 2,
'perm': 'tests.view_modelb', 'title': u'Model bs'}],
'first_url': '/tests/modelb/', 'title': u'Tests'}])
[{'menus': [
{'url': '/tests/modela/', 'icon': None, 'order': 1,
'perm': 'tests.view_modela', 'title': u'Model as'},
{'url': '/admin/testapp/testurl/', 'title': u'Test URL',
'order': '', 'perm': None, 'icon': 'bolt'}],
'first_icon': 'test', 'first_url': '/tests/modela/',
'title': 'Test App'},
{'menus': [
{'url': '/tests/modelb/', 'icon': None, 'order': 2,
'perm': 'tests.view_modelb', 'title': u'Model bs'}],
'first_url': '/tests/modelb/', 'title': u'Tests'}])

def _create_superuser(self, username):
return User.objects.create(username=username, is_superuser=True)
Expand Down
4 changes: 1 addition & 3 deletions xadmin_extras/apps.py
@@ -1,11 +1,9 @@
# coding=utf-8

import copy

class AdminAppMixin(object):

def __init__(self):
self.custom_menu = self.init_menu()

def init_menu(self):
"""Add custom menu entries to the menu displayed for this app
Expand Down
6 changes: 2 additions & 4 deletions xadmin_extras/views.py
Expand Up @@ -33,9 +33,8 @@ def get_apps_menu(self):
app_config = model_admin.app_config
menu.update({'app:' + app_config.name: {
'title': app_config.verbose_name,
'menus': app_config.custom_menu,
'url': '', 'order': '', 'perm': None,
'first_icon': app_config.icon}})
'menus': app_config.init_menu(),
'first_icon': app_config.icon}})
return menu

@views.filter_hook
Expand Down Expand Up @@ -70,7 +69,6 @@ def get_url(menu, had_urls):
}
if model_dict['url'] in had_urls:
continue

app_key = "app:%s" % app_label
if app_key in nav_menu:
nav_menu[app_key]['menus'].append(model_dict)
Expand Down

0 comments on commit 032c77c

Please sign in to comment.