Permalink
Browse files

Provide a Widget compound_key

make available a compound_key attribute which can be used by tw2.forms as the default value for FormField name argument
  • Loading branch information...
amol- authored and ralphbean committed Sep 6, 2012
1 parent e99f828 commit ee571a215267de2da2b663e74417b7cb2509ecf0
Showing with 16 additions and 2 deletions.
  1. +16 −2 tw2/core/widgets.py
@@ -209,6 +209,8 @@ def post_define(cls):
cls.attrs = cls.attrs.copy()
cls.attrs['id'] = cls.compound_id
cls.compound_key = cls._gen_compound_key()
if hasattr(cls, 'request') and getattr(cls, 'id', None):
import middleware
path = cls._gen_compound_id(for_url=True)
@@ -276,6 +278,17 @@ def _compound_id_elem(cls, for_url):
else:
return getattr(cls, 'id', None)
@classmethod
def _gen_compound_key(cls):
if not cls.key:
return None
parent_key = getattr(cls.parent, 'compound_key', None)
if parent_key:
return ':'.join([parent_key, cls.key])
else:
return cls.key
@classmethod
def get_link(cls):
"""
@@ -898,6 +911,7 @@ def post_define(cls):
not issubclass(cls.child, Widget):
raise pm.ParameterError("Child must be a widget")
cls.compound_key = None
cls._sub_compound = cls.child._sub_compound
cls_id = getattr(cls, 'id', None)
child_id = getattr(cls.child, 'id', None)
@@ -910,9 +924,9 @@ def post_define(cls):
cls.id = child_id
DisplayOnlyWidget.post_define.im_func(cls)
Widget.post_define.im_func(cls)
cls.child = cls.child(parent=cls)
cls.child = cls.child(parent=cls, key=cls.key)
else:
cls.child = cls.child(id=cls_id, parent=cls)
cls.child = cls.child(id=cls_id, key=cls.key, parent=cls)
@classmethod
def _gen_compound_id(cls, for_url):

0 comments on commit ee571a2

Please sign in to comment.