web/views/autoform.py
changeset 3629 559cad62c786
parent 3589 a5432f99f2d9
parent 3595 b61f1c5e6c55
child 3655 af86ab65a282
equal deleted inserted replaced
3590:1b0dbcf4b214 3629:559cad62c786
   132         #       -> use a simple onload js function to check if there is
   132         #       -> use a simple onload js function to check if there is
   133         #          a input type=file in the form
   133         #          a input type=file in the form
   134         #       -> generate the <form> node when the content is rendered
   134         #       -> generate the <form> node when the content is rendered
   135         #          and we know the correct enctype (formrenderer's w attribute
   135         #          and we know the correct enctype (formrenderer's w attribute
   136         #          is not a StringIO)
   136         #          is not a StringIO)
   137         for rschema, targettypes, role in self.inlined_relations():
   137         for formview in self.inlined_form_views():
   138             # inlined forms don't handle multiple target types
   138             if formview.form:
   139             if len(targettypes) != 1:
   139                 if hasattr(formview.form, '_subform_needs_multipart'):
   140                 continue
   140                     needs_multipart = formview.form._subform_needs_multipart(_tested)
   141             targettype = targettypes[0]
       
   142             if targettype in _tested:
       
   143                 continue
       
   144             _tested.add(targettype)
       
   145             if self.should_inline_relation_form(rschema, targettype, role):
       
   146                 entity = self._cw.vreg['etypes'].etype_class(targettype)(self._cw)
       
   147                 subform = self._cw.vreg['forms'].select('edition', self._cw,
       
   148                                                         entity=entity)
       
   149                 if hasattr(subform, '_subform_needs_multipart'):
       
   150                     needs_multipart = subform._subform_needs_multipart(_tested)
       
   151                 else:
   141                 else:
   152                     needs_multipart = subform.form_needs_multipart
   142                     needs_multipart = formview.form.form_needs_multipart
   153                 if needs_multipart:
   143                 if needs_multipart:
   154                     return True
   144                     return True
   155         return False
   145         return False
   156 
   146 
   157     def action(self):
   147     def action(self):
   267 
   257 
   268     @cached
   258     @cached
   269     def inlined_form_views(self):
   259     def inlined_form_views(self):
   270         """compute and return list of inlined form views (hosting the inlined form object)
   260         """compute and return list of inlined form views (hosting the inlined form object)
   271         """
   261         """
   272         formviews = []
   262         allformviews = []
   273         entity = self.edited_entity
   263         entity = self.edited_entity
   274         for rschema, ttypes, role in self.inlined_relations():
   264         for rschema, ttypes, role in self.inlined_relations():
   275             # show inline forms only if there's one possible target type
   265             # show inline forms only if there's one possible target type
   276             # for rschema
   266             # for rschema
   277             if len(ttypes) != 1:
   267             if len(ttypes) != 1:
   279                              'inlined form but there is multiple target types, '
   269                              'inlined form but there is multiple target types, '
   280                              'dunno what to do', rschema)
   270                              'dunno what to do', rschema)
   281                 continue
   271                 continue
   282             ttype = ttypes[0].type
   272             ttype = ttypes[0].type
   283             if self.should_inline_relation_form(rschema, ttype, role):
   273             if self.should_inline_relation_form(rschema, ttype, role):
   284                 formviews += self.inline_edition_form_view(rschema, ttype, role)
   274                 formviews = list(self.inline_edition_form_view(rschema, ttype, role))
   285                 if role == 'subject':
   275                 if role == 'subject':
   286                     card = rschema.rproperty(entity.e_schema, ttype, 'cardinality')[0]
   276                     card = rschema.rproperty(entity.e_schema, ttype, 'cardinality')[0]
   287                 else:
   277                 else:
   288                     card = rschema.rproperty(ttype, entity.e_schema, 'cardinality')[1]
   278                     card = rschema.rproperty(ttype, entity.e_schema, 'cardinality')[1]
   289                 # there is no related entity and we need at least one: we need to
   279                 # there is no related entity and we need at least one: we need to
   296                     addnewlink = self.vreg['views'].select(
   286                     addnewlink = self.vreg['views'].select(
   297                         'inline-addnew-link', self.req,
   287                         'inline-addnew-link', self.req,
   298                         etype=ttype, rtype=rschema, role=role,
   288                         etype=ttype, rtype=rschema, role=role,
   299                         peid=self.edited_entity.eid, pform=self, card=card)
   289                         peid=self.edited_entity.eid, pform=self, card=card)
   300                     formviews.append(addnewlink)
   290                     formviews.append(addnewlink)
   301         return formviews
   291                 allformviews += formviews
       
   292         return allformviews
   302 
   293 
   303     def inlined_forms(self):
   294     def inlined_forms(self):
   304         for formview in self.inlined_form_views():
   295         for formview in self.inlined_form_views():
   305             if formview.form: # may be None for the addnew_link artefact form
   296             if formview.form: # may be None for the addnew_link artefact form
   306                 yield formview.form
   297                 yield formview.form