rewrite form_needs_multipart using precomputed form views stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 07 Oct 2009 14:36:55 +0200
branchstable
changeset 3594 c5b40ab4ea43
parent 3593 987232bd79cd
child 3595 b61f1c5e6c55
rewrite form_needs_multipart using precomputed form views
web/views/autoform.py
--- a/web/views/autoform.py	Wed Oct 07 14:36:19 2009 +0200
+++ b/web/views/autoform.py	Wed Oct 07 14:36:55 2009 +0200
@@ -215,21 +215,12 @@
         #       -> generate the <form> node when the content is rendered
         #          and we know the correct enctype (formrenderer's w attribute
         #          is not a StringIO)
-        for rschema, targettypes, role in self.inlined_relations():
-            # inlined forms don't handle multiple target types
-            if len(targettypes) != 1:
-                continue
-            targettype = targettypes[0]
-            if targettype in _tested:
-                continue
-            _tested.add(targettype)
-            if self.should_inline_relation_form(rschema, targettype, role):
-                entity = self.vreg['etypes'].etype_class(targettype)(self.req)
-                subform = self.vreg['forms'].select('edition', self.req, entity=entity)
-                if hasattr(subform, '_subform_needs_multipart'):
-                    needs_multipart = subform._subform_needs_multipart(_tested)
+        for formview in self.inlined_form_views():
+            if formview.form:
+                if hasattr(formview.form, '_subform_needs_multipart'):
+                    needs_multipart = formview.form._subform_needs_multipart(_tested)
                 else:
-                    needs_multipart = subform.form_needs_multipart
+                    needs_multipart = formview.form.form_needs_multipart
                 if needs_multipart:
                     return True
         return False