Skip to content

Commit

Permalink
Prevent from changing parent TabsConfig when merging
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Mar 17, 2012
1 parent 2793fd6 commit 638162b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions admin_tabs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ class MetaAdminPageConfig(type):
This metaclass make inheritance between the inner classes of the PageConfig
classes.
"""
def __new__(mcs, name, base, dict):
it = type.__new__(mcs, name, base, dict)
def __new__(mcs, name, base, dct):
it = type.__new__(mcs, name, base, dct)
# Make the FieldsetsConfig attributes overwrittable and inheritable
# TODO: reverse mro like its done in tabs
for cls in it.mro():
Expand Down Expand Up @@ -204,9 +204,10 @@ def __new__(mcs, name, base, dict):
else:
# Merge with parent's attr if it exists
if attr_name in _final_attrs:
_final_attrs[attr_name].update(attr)
else:
_final_attrs[attr_name] = attr
config = Config(**_final_attrs[attr_name]) # Copy it
config.update(attr)
attr = config
_final_attrs[attr_name] = attr
# Add selected tabs in the created class
for attr_name, attr in _final_attrs.iteritems():
setattr(it.TabsConfig, attr_name, attr)
Expand Down
1 change: 1 addition & 0 deletions admin_tabs/tests/metaadminpageconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AB(A):
class TabsConfig:
tab = Config(cols=["b", "c", "a"])

self.assertEqual(A.TabsConfig.tab["cols"], ["a", "b", "c"])
self.assertEqual(AB.TabsConfig.tab["cols"], ["b", "c", "a"])
self.assertEqual(AB.TabsConfig.tab["name"], "myname")

Expand Down

0 comments on commit 638162b

Please sign in to comment.