r13401 - MoreFieldsAndWidgets/CompoundField/trunk/Products/CompoundField

"Philipp Auersperg" <[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: zworkb
Date: Sun Jan  9 14:25:17 2011
New Revision: 13401

Modified:
   MoreFieldsAndWidgets/CompoundField/trunk/Products/CompoundField/EnhancedArrayWidget.py
Log:
applied CompoundField.EnhancedArrayWidget-noMoreGuessPackage.patch published in http://plone.org/products/compoundfield/issues/24

Modified: MoreFieldsAndWidgets/CompoundField/trunk/Products/CompoundField/EnhancedArrayWidget.py
==============================================================================
--- MoreFieldsAndWidgets/CompoundField/trunk/Products/CompoundField/EnhancedArrayWidget.py	(original)
+++ MoreFieldsAndWidgets/CompoundField/trunk/Products/CompoundField/EnhancedArrayWidget.py	Sun Jan  9 14:25:17 2011
@@ -73,28 +73,36 @@
 
         return value, {}
 
-    def getSubFieldWidgetHtml(self, context, field_name):
+    def getTypes(self, context, typepath=None):
         """
+        Get the types for the content type
         """
-        # The following code is adapted from getWidgets in ArchetypeTool
         atool = getToolByName(context, 'archetype_tool')
-        package = None #_guessPackage(context.__module__)
-        type = context.portal_type
+        atool = getattr(atool, "tool", atool) # Plone 4 compatibility
+        portal_type = context.portal_type
+
+        # Initialize the recursion
+        if typepath == None: typepath = context.__module__.split(".")
+
+        # Try the whole recursion again without preceding 'Products.' part
+        if typepath == ["Products"]: typepath = context.__module__.split(".")[1:]
+
+        # End recursion
+        if not typepath: raise KeyError, context.__module__
 
-        # create a false instance 
         try:
-           types = atool.listTypes(package, type)
+            # Try to find the current portal type's module in all the registered types
+            return atool.listTypes(".".join(typepath), portal_type)
         except KeyError, ex:
-            # Check if type is registered in pkg name w/out .content.XXX suffix
-            # patch see http://plone.org/products/compoundfield/issues/13
-            i = package.rfind('.content.')
-            if i > 0:
-                package = package[:i]
-                types = atool.listTypes(package, type)
-            else:
-                raise ex
+            # Strip off the last part of the path and try again until the path is empty
+            return self.getTypes(context, typepath[:-1])
 
-        t = types[0]
+    def getSubFieldWidgetHtml(self, context, field_name):
+        """
+        Get the widget html for a subfield of an ArrayField.
+        """
+        # The following code is adapted from getWidgets in ArchetypeTool
+        t = self.getTypes(context, context.__module__.split("."))[0]
         instance = t('fake_instance')
         instance._at_is_fake_instance = True
         # XXX _is_fake_instance will go away in AT 1.4

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.